/******* VARIABLES *********/

var ActiveLayers = "";
var MenuLevel = 0;
var is;

/******* Browser detection *********/
function Is (){
    var agt=navigator.userAgent.toLowerCase();
    this.major		= parseInt(navigator.appVersion);
    this.minor		= parseFloat(navigator.appVersion);
    this.nav		= ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    this.nav4		= (this.nav && (this.major == 4));
    this.nav6up		= (this.nav && (this.major >= 5));
    this.ie			= ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    this.ie4		= (this.ie && (this.major == 4) && (agt.indexOf("msie 5")==-1) );
    this.ie4up		= (this.ie && (this.major >= 4));
    this.mac		= (agt.indexOf("mac")!=-1);
}
is = new Is(); 
/******* End Browser detection ******/		


/******* MENU FUNCTIONS *********/	
function ShowLayerBottom(MenuID, origin){
	var X, Y;

	X = findPosX(origin);
	Y = findPosY(origin) + 21;
	
	ShowLayer(MenuID, origin, X, Y);
	
	ActiveLayers += (ActiveLayers == "" ? MenuID : "," + MenuID);
	MenuLevel++;
}

function ShowLayerRight(MenuID, origin){
	var X, Y;		
	X = findPosX(origin) + 171;
	Y = findPosY(origin) ;
	
	ShowLayer(MenuID, origin, X, Y);
	
	ActiveLayers += (ActiveLayers == "" ? MenuID : "," + MenuID);
	MenuLevel++;
}

function ShowLayer(MenuID, origin, X, Y)
{
	if (is.nav4){
		document.layers[MenuID].left = X + 'px';
		document.layers[MenuID].top = Y + 'px';
		document.layers[MenuID].visibility = "show";
	}else if(is.ie4up){
		document.all[MenuID].style.pixelLeft = X;
		document.all[MenuID].style.pixelTop = Y;
		document.getElementById(MenuID).style.visibility = "visible";
	}else if(is.nav6up){
		document.getElementById(MenuID).style.left = X + 'px';
		document.getElementById(MenuID).style.top = Y + 'px';
		document.getElementById(MenuID).style.visibility = "visible";
	}
}

function HideLayer(LayerName){
	if (is.nav4){
		document.layers[LayerName].visibility = "hide";
	}else if(is.ie4up){
		document.getElementById(LayerName).style.visibility = "hidden";
	}else if(is.nav6up){
		document.getElementById(LayerName).style.visibility = "hidden";
	}		
}

//Hides the layers with the level specified and any levels highers.
function HideLevel(level){	
	var ids = ActiveLayers.split(",");
	while(MenuLevel >= level)
	{
		if(ids[MenuLevel-1] != "" && ids[MenuLevel-1] != null)
		{
			HideLayer(ids[MenuLevel-1]);
			MenuLevel--;
			ActiveLayers = ActiveLayers.substring(0, ActiveLayers.lastIndexOf(','));
		}
	}
}

//Hides all layers
function HideMenu(){	
	if(ActiveLayers != "")
	{
		var ids = ActiveLayers.split(",");
		for (id in ids)
		{
			HideLayer(ids[id]);		
		}
		ActiveLayers = "";
		MenuLevel = 0;
	}
}

function Popup(strURL, intWidth, intHeight)	
{
	var intLeft = (screen.width - intWidth) / 2;
	var intTop = (screen.height - intHeight - 35) / 2;
	NewChild = window.open(strURL,'_blank','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=' + intWidth + ',height=' + intHeight + ',top=' + intTop + ',left=' + intLeft)
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

//Hide's the Menus when you click anywhere
document.onmouseup = HideMenu;
/******* /END MENU FUNCTIONS *********/	