$(document).ready(function () {

   /*facebook bok*/
var th_var=0;
th_offset=$("#cart_main").offset();//$("#cart_main").css('left');
$("#cart_button").click(function(){
    
        if(th_var==0){
            $("#cart_main_empty").animate({
                    right: '0'
            }, 500,function(){
                    th_var=1;
                               
            });
            $("#cart_main_notempty").animate({
                    right: '0'
            }, 500,function(){
                    th_var=1;
                               
            });
            $("#fb_main").css('z-index',997);
            $("#yt_main").css('z-index',997);
            
            
        }else{
            $("#cart_main_empty").animate({
                    right: '-208px'            /*'+th_left+'*/
            }, 500,function(){
                    th_var=0;
                         $("#fb_main").css('z-index',999);
            $("#yt_main").css('z-index',999);
            });
            $("#cart_main_notempty").animate({
                    right: '-677px'            /*'+th_left+'*/
            }, 500,function(){
                    th_var=0;
                         $("#fb_main").css('z-index',999);
            $("#yt_main").css('z-index',999);
            });
       
        }

});


   /*cart bok*/
var th_var=0;
th_offset=$("#fb_main").offset();//$("#fb_main").css('left');
$("#fb_button").click(function(){
        if(th_var==0){
            $("#fb_main").animate({
                    right: '0'
            }, 500,function(){
                    th_var=1;
            });
             $("#cart_main").css('z-index',997);
            $("#yt_main").css('z-index',997);
        }else{
            $("#fb_main").animate({
                    right: '-208px'            /*'+th_left+'*/
            }, 500,function(){
                    th_var=0;
                        $("#cart_main").css('z-index',998);
            $("#yt_main").css('z-index',999);
            });
         
        }

});

   /*yt bok*/
var th_var=0;
th_offset=$("#yt_main").offset();//$("#yt_main").css('left');
$("#yt_button").click(function(){
        if(th_var==0){
            $("#yt_main").animate({
                    right: '0'
            }, 500,function(){
                    th_var=1;
            });
        }else{
            $("#yt_main").animate({
                    right: '-208px'            /*'+th_left+'*/
            }, 500,function(){
                    th_var=0;
            });
        }

});

/*caruzelka*/
var cart_items = $('#prods_cart li').size();
var current_cart_item = 2;

if (cart_items > 2) {
    $('#strzalka_prawo').removeClass('inactive');  
    $('#strzalka_prawo').addClass('active');  
         
}

$.each($('#prods_cart li'), function(i, l) {
/* ie */
 if ((i+1) <= 2)    $(this).css('display','block');
 });

$('#strzalka_prawo').click(function ()
            {
                
                  if (current_cart_item < cart_items) {
                       
                         current_cart_item += 1;
                       $.each($('#prods_cart li'), function(i, l) {
                                var turn_off =current_cart_item -2;
                                
                                if ((i+1) <= turn_off)    $(this).css('display','none');
                                if ((i+1) == current_cart_item)    $(this).css('display','block');
                                if ((i+1) == (current_cart_item+1))    $(this).css('display','block');
                                
                                if ((i+1) > current_cart_item)    $(this).css('display','none');
                                
                                
                                  if (current_cart_item == cart_items) {
                                    $('#strzalka_prawo').addClass('inactive');  
                                    $('#strzalka_prawo').removeClass('active');  

                                }
                                    if (current_cart_item == 2) {
                                    $('#strzalka_lewo').addClass('inactive');  
                                    $('#strzalka_lewo').removeClass('active');  

                                }
                                else {
                                     $('#strzalka_lewo').addClass('active');  
                                    $('#strzalka_lewo').removeClass('inactive');  

                                }

                            });
                          
                 }
                
    
});



$('#strzalka_lewo').click(function ()
            {
                
                  if (current_cart_item > 2) {
                       
                         current_cart_item -= 1;
                      
                      
                       $.each($('#prods_cart li'), function(i, l) {
                                var turn_off =current_cart_item -2;
                                if ((i+1) < turn_off)    $(this).css('display','none');
                                if ((i+1) == current_cart_item-1)    $(this).css('display','block');
                                if ((i+1) == (current_cart_item))    $(this).css('display','block');
                                
                                if ((i+1) > current_cart_item)    $(this).css('display','none');
                                
                                
                                  if (current_cart_item == 2) {
                                    $('#strzalka_lewo').addClass('inactive');  
                                    $('#strzalka_lewo').removeClass('active');  

                                }
                                else {
                                     $('#strzalka_lewo').addClass('inactive');  
                                    $('#strzalka_lewo').removeClass('active');  

                                }
                                     if (current_cart_item < cart_items) {
                                    $('#strzalka_prawo').addClass('active');  
                                    $('#strzalka_prawo').removeClass('inactive');  

                                }

                            });
                          
                 }
                
    
});
/*$('#cart_notempty').append('<div id="cart_title">Koszyk</div>');*/
$("#bottom-menu .nwsl .input-removee").hover(
  function () {
    $('.hov1').css('display','block');
  }, 
  function () {
     $('.hov1').css('display','none');
  }
);

$("#bottom-menu .nwsl .input-addd").hover(
  function () {
    $('.hov2').css('display','block');
  }, 
  function () {
     $('.hov2').css('display','none');
  }
);
$("#info-boxes li:last-child").addClass("remove");
$("#bottom-menu ul li:last-child").addClass("remove");
$("#categories li:first-child").addClass("remove");
$("#prods-also li:first-child").addClass("remove");


    $("#extras li a").click(function() {
    
        var curList = $("#extras li a.current").attr("rel");
        var curListHeight = $("#extras-rotate").height();
        
        $("#extras-rotate").height(curListHeight);
    
        $("#extras li a").removeClass("current");
        $(this).addClass("current");
        
        var listID = $(this).attr("rel");
        
        if (listID != curList) {
            $("#"+curList).fadeOut(200, function() {
    
                $("#"+listID).fadeIn();
                
                var newHeight = $("#"+listID).height();
                
                $("#extras-rotate").animate({
                    height: newHeight
                });
            
            });
        }        
        
        return false;
    });	
	
    $("#det-data-nav li a").click(function() {
    
        var curList = $("#det-data-nav li a.current").attr("rel");
        var curListHeight = $("#det-data-rotate").height();
        
        $("#det-data-rotate").height(curListHeight);
    
        $("#det-data-nav li a").removeClass("current");
        $(this).addClass("current");
        
        var listID = $(this).attr("rel");
        
        if (listID != curList) {
            $("#"+curList).fadeOut(200, function() {
    
                $("#"+listID).fadeIn();
                
                var newHeight = $("#"+listID).height();
                
                $("#det-data-rotate").animate({
                    height: newHeight
                });
            
            });
        }        
        
        return false;
    });		
	
	$("#myController-upper").jFlow({
		slides: "#slides-upper",
		controller: ".jFlowControl-upper", // must be class, use . sign
		slideWrapper : "#jFlowSlide-upper", // must be id, use # sign
		selectedWrapper: "jFlowSelected-upper",  // just pure text, no sign
		auto: true,		//auto change slide, default true
		width: "733px",
		height: "337px",
		duration: 800,
		prev: ".jFlowPrev-upper", // must be class, use . sign
		next: ".jFlowNext-upper" // must be class, use . sign
	});
	
});
