$(document).ready(function() {

	/*
    $('.item').hover(function() {
		$('.desc', this).hide('fast');
	});
	$('.item').mouseleave(function() {
		$('.desc', this).show('fast');
	});
	*/
    
    //facebook
	
	function fb_slide() {
        $("#fb_toggler").hover(
            function() { $(this).stop().animate({ paddingRight: 260 }, 800); },
            function() { $(this).stop().animate({ paddingRight: 0 }, 500); }
        );
    }

	fb_slide();
    
    if($.browser.msie && parseFloat($.browser.version) <= 8){
                $(".booking_open").fancybox({
                    'titleShow'		: false,
                    'width'         : 731,
                    'scrolling'     : 'no',
                    'onComplete' : function(){
                        $("#fancybox-content").css('width','731px');
                        $("#fancybox-wrap").css('width','751px');
                        $.fancybox.resize();
                        $.fancybox.center();
                    }
                });
    }
    else {
                $(".booking_open").fancybox({
                    'titleShow'		: false,
                    'width'         : 731,
                    'scrolling'     : 'no'
                });
    }
    
    $("a.qbasket_open").fancybox({
        'type'  :'inline'
    });
    
    $("a.gallery").fancybox({
        'cyclic' : true
    });
    
    
    /* -----  EqualHeight for blocks ----- */
	
	function equalHeight(group) {
		var tallest = 0;
		group.each(function() {
			var thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}
	equalHeight($(".equal"));
	
	
//	$('ul.carusel').roundabout({
//         shape: 'tearDrop'
//    });

    // This initialises carousels on the container elements specified.
	$("#carousel1").CloudCarousel(		
		{
            xPos: 600,
            yPos: 20,
            reflHeight: 50,
            minScale: 0.35,
            reflGap: 0,
            autoRotateDelay: 2000,
            bringToFront: true,
            mouseWheel: true,
			autoRotate: 'left'
		}
	);
    

    $(".uniform, .fil_select label input").uniform();

    $("a.fil").click(function() {
        if($(this).hasClass("active")) {
            $(this).parent(".filters").css('zIndex',990);
            $(this).removeClass("active");
            $(this).next(".fil_select").stop(true,true).fadeOut("fast");
        }
        else {
            $(".fil_select").hide();
            $("a.fil").removeClass("active");
            $(".filters").css('zIndex',990);
            
            $(this).parent(".filters").css('zIndex',999);
            $(this).addClass("active");
            $(this).next(".fil_select").stop(true,true).fadeIn("fast");
        }
    });
    
    $("a.fil_close").click(function() {
        $(this).parent(".fil_select").stop(true,true).fadeOut("fast");
        $("a.fil").removeClass("active");
        $(".filters").css('zIndex',990);
    });
    
    //$(".filters").mouseleave(function() {
    //    $(this).css('zIndex',9990);
    //    $(this).children("a.fil").removeClass("active");
    //    $(this).children(".fil_select").stop(true,true).fadeOut("fast");
    //});
    
    
    $("#hig_all, #mid_all, #low_all, .sel_ch").click(function() {
        if( $(this).hasClass('zaznaczone') ) {
            $(this).parent().find("input[type=checkbox]").removeAttr('checked');
            $(this).children('.selected').hide();
            $(this).removeClass('zaznaczone').children('.unselected').show();
        }
        else {
            $(this).parent().find("input[type=checkbox]").attr('checked', 'checked');
            $(this).addClass('zaznaczone').children('.unselected').hide();
            $(this).children('.selected').show();
        }
        
        if( $('#hig_all').hasClass('zaznaczone') && $('#mid_all').hasClass('zaznaczone') && $('#low_all').hasClass('zaznaczone') ) {
            if( !$('#sel_all').hasClass('zaznaczone') )
                $('#sel_all').click();
        }
        else {
            if( !$('#hig_all').hasClass('zaznaczone') || !$('#mid_all').hasClass('zaznaczone') || !$('#low_all').hasClass('zaznaczone') ) {
                if( $('#sel_all').hasClass('zaznaczone') ) {
                    $('#sel_all').children('.selected').hide();
                    $('#sel_all').removeClass('zaznaczone').children('.unselected').show();
                }
            }
        }
        
        $.uniform.update();
        $(".fil_select").click();
        return false;
    });
    
    $("#sel_all").click(function() {
        if( $(this).hasClass('zaznaczone') ) {
            if( $('#hig_all').hasClass('zaznaczone') )
                $('#hig_all').click();
            if( $('#mid_all').hasClass('zaznaczone') )
                $('#mid_all').click();
            if( $('#low_all').hasClass('zaznaczone') )
                $('#low_all').click();
            
            $(this).children('.selected').hide();
            $(this).removeClass('zaznaczone').children('.unselected').show();
        }
        else {
            if( !$('#hig_all').hasClass('zaznaczone') )
                $('#hig_all').click();
            if( !$('#mid_all').hasClass('zaznaczone') )
                $('#mid_all').click();
            if( !$('#low_all').hasClass('zaznaczone') )
                $('#low_all').click();
            
            $(this).addClass('zaznaczone').children('.unselected').hide();
            $(this).children('.selected').show();
        }
    });
    
    $(".fil_select").click(function() {
        var boxes = $(this).find("input[type=checkbox]");
        var fil_count = 0;
        boxes.each(function() {
            if( $(this).is(":checked") ){
                fil_count += 1;
                return;
            }
        });

        if(fil_count <= 0)
            $(this).parent(".filters").find(".fil_count").text('wybierz');
        else
            $(this).parent(".filters").find(".fil_count").text('wybranych: ' + fil_count);
            
    });
    
    
    $(".employee").click(function() {
        $(this).next(".subsection").slideToggle();
    });
    
	
	// popup sprawdzanie depozytu 
	$("#sprawdz_depozyt_form").bind('submit', function() {

		$.fancybox.showActivity();
		$.ajax({
			type	: "POST",
			cache	: false,
			url		: "index.php?mod=depozyt&act=sprawdz",
			data	: $(this).serializeArray(),
			success	: function(response) {
				$.fancybox(response);
			}
		});
		return false;
	});
});

