var firstTimer = null;
var secTimer = null;
var see1 = 0;
var see2 = 0;

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

$(document).ready(function(){
	 
	 var uwaga = getCookie("uwaga");
	 if(uwaga !=null && uwaga !=""){
		alert("Strona w trakcie aktualizacji. Przepraszamy za utrudnienia.");
		setCookie("uwaga","supsupuwaga",1);
	 }
     
	 $(".sup").accordion({autoHeight: false,collapsible: true,active: false});
	 $("#kategoria").accordion({autoHeight: false,collapsible: true});

	 
	 $("#aux").accordion({autoHeight: false,collapsible: true,active: false});
	
/*
	$('div.sliderGallery').each(function () {
    var ul = $('ul', this);
	var num_elem = 0;
	var elem_width = 160;

	$("ul li",this).each(function(){ num_elem ++ ; });
	
	ul.css('width', num_elem * elem_width+"px");
    var productWidth = num_elem * elem_width - $(this).outerWidth();
	
	
	var valval = (productWidth/100 );
	
    var slider = $('.slider', this).slider({ 
      handle: '.handle',
      minValue: 0, 
      maxValue: num_elem, 
	  value: 0,
	  
      slide: function (ev, ui) {
	    console.log(ui.value*valval);
        ul.css('left', '-' + ui.value*valval + 'px');
      }, 
      stop: function (ev, ui) {
	    console.log(ui.value*valval);
        ul.animate({ 'left' : '-' + ui.value*valval + 'px' }, 500, 'linear');
      }
    });
  });   */
 
	$("#menu.secsec > ul > li:not('.m')").hover(function(){
	
		$(this).addClass("set");
		},function(){ $(this).removeClass("set"); } ); 
	
	$("#menu > ul > li.m").hover(function(){

		clearTimeout(firstTimer);
		clearTimeout(secTimer);
		$("#menu > ul li.m").removeClass('prod');
		$('.sub2').hide();
		$('.sub').hide();
		
		if($(this).children('.sub2').length != 0){
			
			$("#menu > ul > li.m").removeClass('prod');
			$(this).addClass('prod');
			$(this).children('.sub2').show();
			firstTimer = setTimeout('hide2()',1500);
			see2 = 1;
		}else if($(this).children('.sub') .length != 0){
			
			$("#menu > ul > li.m").removeClass('prod');
			$(this).addClass('prod');
			$(this).children('.sub').show();
			//secTimer = setTimeout('hide()',1000);
			see1 = 1;
		}
		
	
	},function(){
	
	
	});
	
	$("div.item").hover(function(){
		$(this).children("div.dymek").show();
	},function() {  
		$(this).children("div.dymek").hide();
	});
	
	$("#menu > ul > li.m div.sub2").hover(function(){
	    
		clearTimeout(firstTimer);
		
		
	},function(){
		firstTimer = setTimeout('hide2()',500);
		see2 = 0;
		
	});
	
	$("#menu > ul > li.m div.sub").hover(function(){
		
		clearTimeout(secTimer);
		
	},function(){
		secTimer = setTimeout('hide()',500);
		see1 = 0;		
	});
	
});
function hide2(){    
	$("#menu > ul > li.m").removeClass('prod');
	$(".sub2").hide();
	see2 = 0;	
}

function hide(){
    
	$("#menu > ul > li.m").removeClass('prod');
	$(".sub").hide();
	see1 = 0;
	
}


