//---------------------------NEWS
function newsslider(prev) {
    var current_excerpt = $('#news li.selected').length ? $('#news li.selected') : $('#news li:first');
    if (prev) {
        var next_excerpt = (current_excerpt.prev().length) ? current_excerpt.prev() : $('#news li:last');
    } else {
        var next_excerpt = (current_excerpt.next().length) ? current_excerpt.next() : $('#news li:first');
    }
    $('#news li').removeClass('selected');
    next_excerpt.addClass('selected');
    $('#newsWraper').scrollTo(next_excerpt, 1000);
}
//---------------------------NEWS


$(document).ready(function() {
    
    
    $('form').submit(function(){
        if(!$('input[name=cFormPrzetwDanych]').is(':checked')){
            $('div.demo').dialog({
                buttons: {
                    "Tak": function() {
                        $(this).dialog("Tak");
                        $('input[name=cFormPrzetwDanych]').attr("checked", true);
                        $('input#rezerwacjaWyslij').click();
                    }
                }
            },{
                buttons: {
                    "Nie": function() {
                        $(this).dialog("close");
                        $('input#rezerwacjaWyslij').click();
                    }
                }
            })
            return false;
        }
        return true;
    })
    
    


    //        //alert(action);
    //        if (action != 'true') {
    //            return false;
    //        }
    //        return true;
    //    })


    //    $('input#rezerwacjaWyslij').click(function(){
    //        if(!$('input[name=cFormPrzetwDanych]').is(':checked')){
    //            if (confirm("Czy wyrażasz zgoda na przetważanie danych przes Hotel junior 2 ?")) {
    //                return true;
    //            }
    //            else {
    //                return false;
    //            }
    //        }
    //    });

    $().piroBox_ext({
        piro_speed : 800,
        bg_alpha : 0.4,
        piro_scroll : true
    });

    $('.alpha1').addClass('alpha1JQ').removeClass('alpha1');
    $('.alpha2').addClass('alpha2JQ').removeClass('alpha2');
    $('.alpha3').addClass('alpha3JQ').removeClass('alpha3');
    $('.alpha4').addClass('alpha4JQ').removeClass('alpha4');

    $(".alpha1JQ").find('.alpha').addClass('hide');
    $(".alpha1JQ").mouseenter(function(){
        $(this).find('.alpha').removeClass('hide');
        $(this).find('.alpha').fadeOut(0);
        $(this).find('.alpha').fadeIn(200);
    });
    $(".alpha1JQ").mouseleave(function(){
        $(this).find('.alpha').removeClass('hide');
        $(this).find('.alpha').fadeOut(50);
    });

    $(".alpha2JQ").find('.alpha').addClass('hide');
    $(".alpha2JQ").mouseenter(function(){
        $(this).find('.alpha').removeClass('hide');
        $(this).find('.alpha').fadeOut(0);
        $(this).find('.alpha').fadeIn(200);
    });
    $(".alpha2JQ").mouseleave(function(){
        $(this).find('.alpha').removeClass('hide');
        $(this).find('.alpha').fadeOut(50);
    });

    $(".alpha3JQ").find('.alpha').addClass('hide');
    $(".alpha3JQ").mouseenter(function(){
        $(this).find('.alpha').removeClass('hide');
        $(this).find('.alpha').fadeOut(0);
        $(this).find('.alpha').fadeIn(200);
    });
    $(".alpha3JQ").mouseleave(function(){
        $(this).find('.alpha').removeClass('hide');
        $(this).find('.alpha').fadeOut(50);
    });

    $(".alpha4JQ").find('.alpha').addClass('hide');
    $(".alpha4JQ").mouseenter(function(){
        $(this).find('.alpha').removeClass('hide');
        $(this).find('.alpha').fadeOut(0);
        $(this).find('.alpha').fadeIn(200);
    });
    $(".alpha4JQ").mouseleave(function(){
        $(this).find('.alpha').removeClass('hide');
        $(this).find('.alpha').fadeOut(50);
    });

    $(".nav li.field").prepend("<span></span>"); //Throws an empty span tag right before the a tag

    $(".nav li.field").each(function() { //For each list item...
        var linkText = $(this).find("a").html(); //Find the text inside of the <a> tag
        $(this).find("span").show().html(linkText); //Add the text in the <span> tag
    });

    $("div.menuTop > .nav li.field").hover(function() {	//On hover...
        $(this).find("span").stop().animate({
            marginTop: "-46" //Find the <span> tag and move it up 40 pixels
        }, 250);
    } , function() { //On hover out...
        $(this).find("span").stop().animate({
            marginTop: "0"  //Move the <span> back to its original state (0px)
        }, 250);
    });

    $("div.menuBottom > .nav li.field").hover(function() {	//On hover...
        $(this).find("span").stop().animate({
            marginTop: "-15" //Find the <span> tag and move it up 40 pixels
        }, 250);
    } , function() { //On hover out...
        $(this).find("span").stop().animate({
            marginTop: "0"  //Move the <span> back to its original state (0px)
        }, 250);
    });
    $("div.menuOferta > .nav li.field").hover(function() {	//On hover...
        $(this).find("span").stop().animate({
            marginTop: "-18" //Find the <span> tag and move it up 40 pixels
        }, 250);
    } , function() { //On hover out...
        $(this).find("span").stop().animate({
            marginTop: "0"  //Move the <span> back to its original state (0px)
        }, 250);
    });
    $("div.menuRestauracja > .nav li.field").hover(function() {	//On hover...
        $(this).find("span").stop().animate({
            marginTop: "-18" //Find the <span> tag and move it up 40 pixels
        }, 250);
    } , function() { //On hover out...
        $(this).find("span").stop().animate({
            marginTop: "0"  //Move the <span> back to its original state (0px)
        }, 250);
    });

    $(function()
    {
        $('.date-pick').datePicker();
    });

    $('#slider').nivoSlider({
        effect:'random', //Specify sets like: 'fold,fade,sliceDown'
        slices:10,
        animSpeed:900, //Slide transition speed
        pauseTime:8000,
        startSlide:0, //Set starting Slide (0 index)
        directionNav:false, //Next & Prev
        directionNavHide:false, //Only show on hover
        controlNav:false, //1,2,3...
        controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:false, //Use left & right arrows
        pauseOnHover:false, //Stop animation while hovering
        manualAdvance:false, //Force manual transitions
        captionOpacity:0.8, //Universal caption opacity
        beforeChange: function(){},
        afterChange: function(){},
        slideshowEnd: function(){}, //Triggers after all slides have been shown
        lastSlide: function(){}, //Triggers when last slide is shown
        afterLoad: function(){} //Triggers when slider has loaded
    });

    //---------------------------NEWS
    var speed = 6000;
    $('#newsWraper, #news li').height($('#newsSlider').height());
    var run = setInterval('newsslider(0)', speed);
    $('#news li:first').addClass('selected');
    $('#newsBt-pause').click(function () {
        clearInterval(run);
        return false;
    });
    $('#newsBt-play').click(function () {
        clearInterval(run);
        run = setInterval('newsslider(0)', speed);
        return false;
    });
    $('#newsBt-next').click(function () {
        clearInterval(run);
        run = setInterval('newsslider(0)', speed);
        newsslider(0);
        return false;
    });
    $('#newsBt-prev').click(function () {
        clearInterval(run);
        run = setInterval('newsslider(0)', speed);
        newsslider(1);
        return false;
    });
    $('#newsSlider').hover(
        function() {
            clearInterval(run);
        },
        function() {
            run = setInterval('newsslider(0)', speed);
        });
//---------------------------NEWS
    
});
