var otwarty = 0;
var timeOutLeft = null;

var timeOutBig = null;

var smallTime = null;
$(document).ready(function(){ 
	
	$(".b1").mouseover(function(){ clearTimeout(timeOutBig); openKatalog("1"); timeOutBig = setTimeout("hideBig();",1000); });
	$(".b2").mouseover(function(){ clearTimeout(timeOutBig); openKatalog("2"); timeOutBig = setTimeout("hideBig();",1000); });
	$(".b3").mouseover(function(){ clearTimeout(timeOutBig); openKatalog("3"); timeOutBig = setTimeout("hideBig();",1000); });

	
	// Lewe boksy
	$("ul.left_box > li.left_pos").hover(function(){
		$(".hover > a > .raquo").hide();
		$("ul.left_box > li.left_pos").removeClass('hover');
		clearTimeout(timeOutLeft);
		$(this).addClass('hover');
		$(".hover > a > .raquo").show();
		$("ul.left_box > li.left_pos > .middle_box").hide();

				//jak boks pusty to content w lewo przesuń
				if(otwarty == 1 || otwarty == 2){
					$(this).children(".middle_box").show();
				}else{
					$("#menu_content").css('right','220px');
				}	
				
		//jeśli lewy boks posiada także treść to wyświetla ją 		
		
			$("#menu_content").hide();
			$("#menu_content").innerHTML = "";
			$("#menu_content").html($(this).children(".big_tresc").html());
			if($("#menu_content h3").text() != "") $("#menu_content").show();
	},function(){
		//wychodzimy i zaczyna zegar cykać
		clearTimeout(timeOutLeft);
		timeOutLeft = setTimeout("allowClose("+1+");",3000);
	});
	
	// środkowy boks 
	$("ul.left_box > li.left_pos > .middle_box").hover(function(){
		
		clearTimeout(timeOutLeft);
	},function() { 
		clearTimeout(timeOutLeft);
		timeOutLeft = setTimeout("allowClose("+2+");",1500);
	});
	
	//do rozwijania 
	$("ul.left_box > li.left_pos > div.middle_box > ul > li").hover(function(){
		
		$("ul.left_box > li.left_pos > div.middle_box > ul > li > .raquo").hide();
		$("div.node").hide();
		$(this).children(".node").show();
		$(this).children("span").addClass('hovered');
		$(".hovered > .raquo").show();
	},function(){
		$(".hovered > .raquo").hide();
		$(this).children("span").removeClass('hovered');
		
	});
	
	
	// pola w środkowym boksie 
	$("ul.left_box > li.left_pos > div.middle_box > ul > li > div.node").hover(function(){
			$(".hover > a > .raquo").hide();
			$("ul.left_box > li.left_pos > div.middle_box > ul > li > div.node").removeClass('hover');
			$(this).addClass("hover");
			$(".hover > a > .raquo").show();
			$("#menu_content").hide();
			$("#menu_content").innerHTML = "";
			var tresc = $(this).children(".tresc").html();
			$("#menu_content").html(tresc);
			if($("#menu_content h3").text() != "" ) {  $("#menu_content").show(); } 
	},function(){
			//$(this).removeClass("hover");
			//$("ul.left_box > li.left_pos > div.middle_box > ul > li > div.node > a > .raquo").hide();
	});
	
	
	//duży boks
	$("#menu_content").hover(function(){
		clearTimeout(timeOutLeft);
	},function(){
		clearTimeout(timeOutLeft);
		timeOutLeft = setTimeout("allowClose("+3+");",1500);
	});
	
	
	$("#menu_big").hover(function(){
		clearTimeout(timeOutBig);
	},function(){
		clearTimeout(timeOutBig);
		timeOutBig = setTimeout("hideBig();",1000);
	}); 
	
	/*
	$("#menu_side > ul.see > li").hover(function(){
		$(this).children('p').show();
		$(this).children('p').css('marginLeft','10px');
	},function(){
		$(this).children('p').hide();
		$(this).children('a').first().show();
	});
	
	$("#menu_side > ul.see > li > p").hover(function(){
		$(this).show();
	},function(){
		$(this).hide();
	}
	);
		
	*/
});

function hideSmall(id)
{
	clearTimeout(smallTime);
	$(id).next().hide();
		
}


function allowClose(ss){
	clearTimeout(timeOutLeft);
	$("ul.left_box > li.left_pos > .middle_box").hide();
	$("#menu_content").html("").hide();
	$("#menu_content").css('right','10px');
	timeOutLeft = null;
	//console.log(ss);
}

function closeContent(ss){
	clearTimeout(timeOutLeft);
	$("#menu_content").html("").hide();
	$("#menu_content").css('right','10px');
	timeOutLeft = null;
	//console.log(ss);
}

function hideBig(){
	$("ul.left_box > li.left_pos > .middle_box").hide();
	$("#menu_content").html("").hide();
	$("#menu_content").css('right','10px');
	$("#menu_big").hide();
}

function openKatalog(type){
	$("ul.left_box > li.left_pos > .middle_box").hide();
	$("#menu_content").html("").hide();
	$("#menu_content").css('right','10px');
	switch(type){
		case '1': { otwarty = 1;$("#katalog_0").show(); $("#katalog_2").hide(); $("#katalog_1").hide();$("#menu_big").show();  break; }
		case '2': { otwarty = 2;$("#katalog_1").show(); $("#katalog_2").hide(); $("#katalog_0").hide();$("#menu_big").show(); break; }
		case '3': { otwarty = 3;$("#katalog_2").show(); $("#katalog_1").hide(); $("#katalog_0").hide();$("#menu_big").show(); break; }
	}
}








function sss(link){
	window.location.replace(link);
}
