/**
 * @author Justyna Pawlata
 * rozwijane menu 
 */

 
$(document).ready(function(){
	
	var cook = $.cookie('show');
	var link = $.cookie('link');

	if (cook == null || cook == 0){
		$('#menu ul li ul').hide();
	}
	else{
		$("#" + cook).children("ul").show();
		}
	

	if ( link == "menu2" || link =="logo"){
		$('#' + cook + " ul").slideUp("slow");
		link = null;
		$.cookie('link', link, { expires: 7 });		
		// nowe ciasteczko anihilowane 
		cook = null;
		$.cookie('show', cook, {expires: 7 });
		// koniec ciasteczkowego potwora
	}
	
	$('#menu ul li span').click(
		function(){
		var disp = $(this).parent("li").children("ul").css("display");
		if( disp == "none" ){
			if(cook == null || cook == 0){
				$(this).parent("li").children("ul").slideDown("slow");
				cook = $(this).parent("li").attr('id'); 
				$.cookie('show', cook, { expires: 7 });
			}
			else{
				$("#" + cook).children('ul').slideUp("slow");			
				$(this).parent("li").children('ul').slideDown("slow");
				cook = $(this).parent("li").attr('id'); 
				$.cookie('show', cook, { expires: 7 });
				}
			}
		else if(!disp){
			if(cook == null || cook == 0){
				$(this).parent("li").children("ul").slideDown("slow");
				cook = $(this).parent("li").attr('id'); 
				$.cookie('show', cook, { expires: 7 });
			}
			else{
				$("#" + cook).children('ul').slideUp("slow");			
				$(this).parent("li").children('ul').slideDown("slow");
				cook = $(this).parent("li").attr('id'); 
				$.cookie('show', cook, { expires: 7 });
				}
			}
		else{
			$(this).parent("li").children("ul").slideUp("slow");
			cook = $(this).parent("li").attr('id'); 
			$.cookie('show', cook, { expires: 7 });
			}
		});
		
	$("#menu2 li").click(
		function(){
			link = $(this).parent("ul").attr('id');
			$.cookie('link', link, { expires: 7 });		
		});
	$("#logo a").click(
		function(){
			link = $(this).parent("div").attr('id');
			$.cookie('link', link, { expires: 7 });	
			});
});
