function ddMenu(menuId)
{
	this.cId = menuId;
	this.speed = 1;
	this.tweening = false;
	
	this.hideRequested = false;
	this.showRequested = false;
	
	this.shown = false;
	this.mouseOverSubMenu = false;
}

function handlerObj(_parent)
{
	this.parent = _parent;
}


ddMenu.prototype.show = function()    // Define Method
{    
	clearTimeout(this.t);
	if(!this.shown)
	{
		if(!this.tweening)
		{
			var subcatDiv = document.getElementById("subcatContainer_"+this.cId);
			var	subcatContents = document.getElementById("subcatContents_"+this.cId);
			var position = getPosition(document.getElementById("cat_"+this.cId));
			
			this.tweening = true;
			this.hideRequested = false;
			this.showRequested = false;
			
			subcatDiv.style.display = "inline";
			subcatDiv.style.visibility = "visible";
			

			subcatDiv.style.left = position.x + "px";
			subcatDiv.style.top = (position.y+15) + "px";
			subcatDiv.style.height = subcatContents.offsetHeight+"px";
			subcatDiv.style.visibility = "visible";	
			
			ddTween = new Tween(subcatContents.style,'top',Tween.strongEaseOut,0-parseInt(subcatContents.offsetHeight),0,this.speed,'px');
			ddTween.fixTime;
			
			
			handler = new handlerObj(this);
			handler.onMotionFinished = function(){
				this.parent.tweening = false;
				this.parent.shown = true;
				this.parent.hideOtherSubs();
				if(this.parent.hideRequested)
					this.parent.queHide();
			};
			ddTween.addListener(handler);
			ddTween.start();
		}
		else
		{
			this.hideRequested = false;
			this.showRequested = true;
		}
	}
}

ddMenu.prototype.hide = function()    // Define Method
{    
	if(!this.mouseOverSubMenu)
	{
		if(!this.hideTweening&&!this.showTweening&&this.shown)
		{
			var subcatDiv = document.getElementById("subcatContainer_"+this.cId);
			var	subcatContents = document.getElementById("subcatContents_"+this.cId);
			
			this.tweening = true;
			this.hideRequested = false;
			this.showRequested = false;
			this.shown = false;
			
			ddTween = new Tween(subcatContents.style,'top',Tween.strongEaseOut,0,0-parseInt(subcatContents.offsetHeight),this.speed/2,'px');
			ddTween.fixTime;
			
			handler = new handlerObj(this);
			handler.onMotionFinished = function(){
				this.parent.tweening = false;
				if(this.parent.showRequested)
					this.parent.show();
				else
				{
					var subcatDiv2 = document.getElementById("subcatContainer_"+parent.cId);
					subcatDiv2.style.display = "inline";
					subcatDiv2.style.visibility = "hidden";
				}
			};
			ddTween.addListener(handler);
			ddTween.start();
		}
		else
		{
			this.hideRequested = true;
			this.showRequested = false;
		}
	}
} 

ddMenu.prototype.lock = function()    // Define Method
{ 
	this.hideOtherSubs();
	this.mouseOverSubMenu = true;
}

ddMenu.prototype.unlock = function()    // Define Method
{ 
	this.mouseOverSubMenu = false;
	this.queHide();
}

ddMenu.prototype.hideOtherSubs = function()    // Define Method
{ 
	for (var i = 0; i < subMenuIds.length; i++)
	{
		if(subMenuIds[i]!=this.cId)
			{eval("thisMenu"+subMenuIds[i]+".hide()");}
	} 
}

ddMenu.prototype.queHide = function()    // Define Method
{    
	clearTimeout(this.t);
	cId = this.cId;
	this.t = setTimeout( function(){eval('thisMenu'+cId+'.hide()')},300);
} 

function isdefined(variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}


function showSubCat(cId)
{
	if(isdefined("thisMenu"+cId))
	{
		eval("thisMenu"+cId+".show()");
	}
	
}


function hideSubCat(cId)
{
	if(isdefined("thisMenu"+cId))
	{
		eval("thisMenu"+cId+".queHide()");
	}
}

function getPosition(obj){
	var position = {x:0,y:0};
    while(obj){
	position.x+= obj.offsetLeft;
	position.y+= obj.offsetTop;
	obj= obj.offsetParent;
    }
    return position;
}




//main body subcats script
var subT2;
var queuedHide='';
function showSub2(sCatId)
{
	if(queuedHide==sCatId)
		clearTimeout(subT2);
	else
		hideSub2();
	if (document.getElementById('sub2_'+sCatId))
		document.getElementById('sub2_'+sCatId).style.display='block';
}

function QueHideSub2(sCatId)
{
	queuedHide = sCatId;
	subT2 = setTimeout( function(){ hideSub2() },300);
}

function hideSub2()
{
	if(selectedSubCat2!=queuedHide)
		if (document.getElementById('sub2_'+queuedHide))
			document.getElementById('sub2_'+queuedHide).style.display='none';
}