//zwijanie

function zwin(f){
ff='#'+f;

 $(ff).animate({
    
    "opacity": "toggle"
    
  },800);
}


function zwin2(f){

var t = document.getElementById(f);

if(t.style.opacity==0) {  t.style.opacity=1; t.style.filter="alpha(opacity=100)"; t.style.zIndex=500; }
else {  t.style.opacity=0; t.style.filter="alpha(opacity=0)"; t.style.zIndex=-10;} 
}


//easing


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



var submenus = {};
var asubmenu = null;

$(document).ready(function(){
	$(".men2").css("overflow", "hidden");
	submenus = $(".men2");
	hideMenus(true);
});

function hideMenus(noAnimation)
{
	if( noAnimation )
	{
		$(".men1 a").click(function(){
			eraseCookie("asub");
		});
		
		var asub = readCookie("asub");
		for( i = 0; i < submenus.length; i++ )
		{
			var aid = $(submenus[i]).attr('id');
			
			if( aid != asub )
				$(submenus[i]).hide(0);

			else
				asubmenu = $(submenus[i]);
				
			$("#" + aid + " a").data('asub', aid).click(function(e){
				createCookie("asub", $(this).data('asub'));
			});
		}
		
	}
	else
	{
		if( asubmenu != null )
			//asubmenu.animate( {height: "hide", paddingTop: "hide", paddingBottom: "hide", marginTop: "hide", marginBottom: "hide", opacity: "hide"}, 300, "easeInCirc");
			animObjHide(asubmenu);

			//$(asubmenu).hide('normal');
	}

}

function toggleMenu(nmenu)
{
	var nmo = $("#" + nmenu);
	
	//nmo.show('normal');
	hideMenus();
	
	if( asubmenu != null && nmenu == asubmenu.attr('id') )
	{
		asubmenu = null;
		return;
	}
		
	//nmo.animate( {height: "show", paddingTop: "show", paddingBottom: "show", marginTop: "show", marginBottom: "show", opacity: "show"}, 900, "easeOutBounce");
	
	animObjShow(nmo);

	asubmenu = nmo;
}
function animObjShow(o)
{
	
	var t = 500;
	var e = 'easeInCirc';
		
	
	o.animate( {height: "show",  opacity: "show"}, t, e);

}
function animObjHide(o)
{
	
	var t = 500;
	var e = 'easeOutElastic';
		
	
	o.animate( {height: "hide",  opacity: "hide"}, t, e);

	
}

