var submenus = new Array();
var mouseOn = false;

function activateMenuHolder(menuHolderID,show)
{
	var element = document.getElementById(menuHolderID);
	if(element == null) return;
	
	submenus.push(menuHolderID);
	
	if(show)
	{
		 element.style.display = "block";
		 mouseOn = true;
	}
	else
	{
		mouseOn = false;
		//hideAll();
		// element.style.display = "none";
	}
}

var toggleView = true;

function toggleMenuHolder(menuHolderID)
{
	var element = document.getElementById(menuHolderID);
	if(element == null) return;
	
	if(toggleView)
	{
		 element.style.display = "block";
		 toggleView = false;
	}
	else
	{
		element.style.display = "none";
		toggleView = true;
	}
}
setInterval(hideAll,1000);

function hideAll()
{
	if(!mouseOn)
	{
		for(var i=0;i<submenus.length;i++)
		{
			var id = submenus[i];
			var e = document.getElementById(id);
			if(e != "undefined" && e != null)
			{
				 e.style.display = "none";
				 submenus.pop(id);
			}
		}
	}
}


var bubblingEnabled = false;
var cancelLocation = false;
function windowLocation(location,caller_a)
{
	if(cancelLocation) return;
	
	//We had bubbling and this is the end of it.
	//Reset.
	if(caller_a == null && bubblingEnabled)
	{
		cancelLocation = false;
		bubblingEnabled = false;
		return;
	}
	//This is the main item, no bubbling, just go to location.
	else if(caller_a == null)
	{
		window.location = location;
	}
	//This is a sub-page, we have bubbling
	//enable it and allow only this caller to go to location.
	//Since cancelLocation will be set to true here, no other
	//caller, who is not the main section will go beyond the first
	//if statement of this function.
	else if (caller_a != null)
	{
		bubblingEnabled = true;
		cancelLocation = true;
	}
	
	window.location = location;
}


/* 
var interval;

var startTop = 0;
var endTop = 400;
var tmpTop = 0;
var working = false;
var mouseOn = false;
var currentActive;

function activateMenuHolder(menuHolderID,show)
{
	if(show)
	{
		if(currentActive != menuHolderID)
		{
			hideAll();
		}
	
		currentActive = menuHolderID;
		mouseOn = true;
		document.getElementById(menuHolderID).style.display = "block";
		if(!working) showItem(document.getElementById(menuHolderID));

	}		
	else
	{
		mouseOn = false;
		//if(working) return;
		//document.getElementById(menuHolderID).style.display = "none";
	}
}

var bubblingOff = false;
function windowLocation(location,caller_a)
{
	if(bubblingOff)
	{
		bubblingOff = false;
		return;
	}
	
	//We have a request from a sub menu.
	if(caller_a != null)
	{
		bubblingOff = true;
	}
	
	window.location = location;
}

function showItem(element)
{
	working = true;
	element.style.display = "block";
	//element.style.height = startTop + "px";
	//tmpTop = startTop;
	//interval = setInterval(function(){move(element);},40);
}

/* 
function move(element)
{
	element.style.height = tmpTop + "px";
	tmpTop += 2;
	
	if(tmpTop >= endTop)
	{
		clearInterval(interval);
	}
}

var submenus = new Array();

submenus.push("menuHolder_2");

setInterval(hideAll,1000);

function hideAll()
{
	if(!mouseOn)
	{
		for(var i=0;i<submenus.length;i++)
		{
			var id = submenus[i];
			var e = document.getElementById(id);
			
			if(e != "undefined" && e != null) e.style.display = "none";
		}
		
		working = false;
	}
} */
