var activePageMenu = null;
var activeSectionMenu = null;
function activatePageMenu(submenuId)
{
	if(activePageMenu != null) deactivatePageMenu();

	var element = document.getElementById(submenuId);
	if(element == null){ return; } //If submenu has no sub-submenu
	
	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		element.style.display = "block";
	}
	else
	{
		element.style.setProperty("display","block","");
	}
	
	onPage = true;
	activePageMenu = element;
}

function activateSectionMenu(submenuId)
{
	//debug("activate section: " + submenuId);	
	if(activeSectionMenu != null) deactivateSectionMenu();
	
	var element = document.getElementById(submenuId);
	if(element == null){ return; } //If menu has no submenu
	
	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		element.style.display = "block";
	}
	else
	{
		element.style.setProperty("display","block","");
	}
	
	onSection = true;
	activeSectionMenu = element;
}

function deactivatePageMenu()
{
	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		if(activePageMenu != null){activePageMenu.style.display = "none";}
	}
	else
	{
		if(activePageMenu != null){activePageMenu.style.setProperty("display","none","");}
	}
}

function deactivateSectionMenu()
{

	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		if(activeSectionMenu != null) activeSectionMenu.style.display = "none";
	}
	else
	{
		if(activeSectionMenu != null) activeSectionMenu.style.setProperty("display","none","");
	}
}

//Makes all columns the same height.
function fixHomeHeights()
{
	var highest = 0;
	
	var middle_home = document.getElementById("middle_home");
	var left_column = document.getElementById("left_column");

	var nums = new Array()
	nums[0] = middle_home.scrollHeight;
	nums[1] = left_column.scrollHeight;
	
	for(var i=0;i<2;i++)
	{
		if(nums[i] > highest) highest = nums[i];
	}
	
	var left_column_height = highest + 60;
	
	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		middle_home.style.height = highest  + "px";
		left_column.style.height = left_column_height  + "px";		
	}
	else
	{
		middle_home.style.setProperty("height",highest+"px","");
		left_column.style.setProperty("height",left_column_height + "px","");
	}
}

//Makes all columns the same height.
function fixMainHeights()
{
	var highest = 0;
	
	var middle = document.getElementById("middle");
	var left_column = document.getElementById("left_column");

	var nums = new Array()
	nums[0] = middle.scrollHeight;
	nums[1] = left_column.scrollHeight;
	
	for(var i=0;i<2;i++)
	{
		if(nums[i] > highest) highest = nums[i];
	}
	
	var left_column_height = highest + 187;
	
	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		middle.style.height = highest  + "px";
		left_column.style.height = left_column_height  + "px";		
	}
	else
	{
		middle.style.setProperty("height",highest+"px","");
		left_column.style.setProperty("height",left_column_height + "px","");
	}
}

/*	Detects the browser */
function detectBrowser()
{
	var browser=navigator.appName;
	return browser;
}

function changeBG(elementID,color,activate)
{
	//The anchor
	var element = document.getElementById(elementID);
	
	if(activate) changeLinkColor(element,"white");
	else changeLinkColor(element,"black");
	
	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		element.style.backgroundColor = color;
	}
	else
	{
		element.style.setProperty("background-color",color,"");
	}
}

function changeLinkColor(element,linkColor)
{
	
	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		element.style.color = linkColor;
	}
	else
	{
		element.style.setProperty("color",linkColor,"");
	}
}

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

function resizeImages(c, imageID)
{
	// size image
	// set constant--this is the max width and height 
	var constant = c;
	var imgW = 0;
	var imgH = 0;
	// get width and height of image
	imgW = document.getElementById('asset' + imageID);
	imgW = imgW.scrollWidth;
	imgH = document.getElementById('asset' + imageID);
	imgH = imgH.scrollHeight;
	
	if (imgH  > imgW)
	{
		document.getElementById('asset' + imageID).height = constant;
		var new_width = Math.ceil((constant*imgW)/imgH);
		document.getElementById('asset' + imageID).width = new_width;
	}
	else if(imgW > imgH)
	{
		document.getElementById('asset' + imageID).width = constant;
		var new_height = Math.ceil((constant*imgH)/imgW);
		document.getElementById('asset' + imageID).height = new_height;
	}
	//If they are the same, they both become the constant
	else 
	{
		document.getElementById('asset' + imageID).height = constant;
		document.getElementById('asset' + imageID).width = constant;
	}
}
