var gMenu =
{
	m_h			: 0,
	m_catHeight	: 150,
	m_animate	: false,
	m_expanding	: $(".children0 .expanded"),
	m_delayTip	: null,
	M_init		: function()
	{

		//$("#menudd .children1").css('display',"none");
		var $categories = $(".children0>li>div");
			
		$categories.children("ul").css({opacity:0});
		$categories.not(".expanded").children("ul").css('display',"none");
		$categories.filter(".expanded").children("ul").css('display',"block"); //css('height',this.m_catHeight);


		// categories expanding
		
		$categories.children("a")
		.mouseover(
			function()
			{	
				var parentDiv =$(this).parent();

				if(!parentDiv.is(".expanded"))
				{
					
					
					if( $(this).siblings("ul").is("ul"))
					{
						if( gMenu.m_expanding && (gMenu.m_expanding!=parentDiv ))				// this line to unfold only when we're rolling over an expandable item
							gMenu.M_foldMenu();


						gMenu.m_expanding = parentDiv;
						
						// expand this item
						parentDiv.addClass("expanded").children("ul").mySlide("down");
						gMenu.m_delayTip= self.setTimeout( "gMenu.sM_showTip()",500);
					}						
					
				}
			}
		);


	}
	,M_foldMenu:function(fn)
	{	if( gMenu.m_expanding)
		{
			if( gMenu.m_delayTip) { self.clearTimeout(gMenu.m_delayTip); gMenu.m_delayTip=null;}
			gMenu.m_expanding = null;
			$(".children0 .expanded").removeClass("expanded").children("ul").stop().mySlide("up",fn);
		}else if(fn)fn();
	}
	, sM_showTip: function()
	{
		//var o=gMenu.m_expanding.offset();
		//$('#tipVenir').animateTip({show:true}).animateTip({ex:o.left+100, ey:o.top+10});
	}
	, M_start :function()
	{

	}
}

jQuery.fn.mySlide = function(dir,fn)
{
	return this.each( function(i,e)
	{
		if (dir=="up")
		{	
			RQDebug("fold up");	
			$(this).stop().animate({height:0,opacity:0},{queue:false, duration:500},"linear",function(){$(this).css({zIndex:0}).hide();if(fn)fn();});

		}
		else if( dir=="down")
		{	
			//RQDebug("fold down");
			$(this).stop().css({clear:"both",height:"auto",display:"block",overflow:"visible",zIndex:200} ).animate({opacity:1},{queue:false, duration:500},"linear",fn);
		}

	});
}




//=== Drop Down menu
function showDropDown(aObj)
{	var id ="d"+$(aObj).attr('id');
	if( sMenuCurrentDropDown && (id!=sMenuCurrentDropDown))
		hideDropDown();
	sMenuCurrentDropDown = id;
		
	$("#"+id).slideDown();
}
function hideDropDown(fn)
{	if(sMenuCurrentDropDown)
		$("#"+sMenuCurrentDropDown).slideUp("normal",fn);
	else if(fn)fn();
	sMenuCurrentDropDown = null;
	sMenuDropDownVisible = false;
	menuItemsRolledOut();
}
var sMenuCurrentDropDown=null;
var sMenuOutDelay=null;
var sMenuOverDelay=null;
var sMenuDropDownCanHide=false;
function menuItemsRolledOut()
{

	gMenu.M_foldMenu();
}
function menuItemOver()
{		
	menuItemsRolledOut();
	menuItemKeepUp();
	showDropDown(this);
}
function menuItemKeepUp()
{
	sMenuDropDownCanHide = false;
	if( sMenuOutDelay)
	{
		self.clearTimeout(sMenuOutDelay);
		sMenuOutDelay = null;
	}
	if( sMenuOverDelay)
		self.clearTimeout(sMenuOverDelay);
	sMenuOverDelay = self.setTimeout("menuCanHide();",10);

}
function menuCanHide()
{
	sMenuOverDelay = null;
	sMenuDropDownCanHide = true;
}
function menuItemOut()
{
	if(sMenuDropDownCanHide)
	{	if( sMenuOutDelay) self.clearTimeout(sMenuOutDelay);
		sMenuOutDelay = self.setTimeout("hideDropDown();",500);
	}
}

