/*
 * Copyright Crickett Software Limited, 2003-2005. All rights reserved.
 *
 * The "Software", below, refers to the software below (in either 
 * source code, or binary form and accompanying documentation). 
 * Each licensee is addressed as "you" or "Licensee." 
 *
 * The copyright holder shown above hereby grants the Licensee a 
 * royalty-free non-exclusive license to use the software. 
 *
 * You may modify and make a copy or copies of the Software for use 
 * within your organization, if you meet the following conditions: 
 *   a. Copies in source code must include the copyright notice and 
 *      this Software License Agreement. 
 *   b. Copies in binary form must include the copyright notice and 
 *      this Software License Agreement in the documentation and/or
 *      other materials provided with the copy. 
 *
 * You may not distribute copies outside your organization.
 *
 * You may nor modify a copy or copies of the Software or any portion
 * of it, thus forming a work based on the Software, and distribute 
 * such copies outside your organization.
 *
 * This software is provided "as is" without express or implied 
 * warranty, and with no claim as to its suitability for any purpose.
 */

//names of dropdowns stored here
menuLayers=new Array();
menuLayers[0]="drop1";
menuLayers[1]="drop2";
menuLayers[2]="drop3";
menuLayers[3]="drop4";
menuLayers[4]="drop5";
menuLayers[5]="drop6";
menuLayers[6]="drop7";

menuHeads=new Array();
menuHeads[0]="head1";
menuHeads[1]="head2";
menuHeads[2]="head3";
menuHeads[3]="head4";
menuHeads[4]="head5";
menuHeads[5]="head6";
menuHeads[6]="head7";

menu_to_keep = -1;

//alert(navigator.userAgent.toLowerCase());

agt = navigator.userAgent.toLowerCase();

if (agt.indexOf('firefox')!=-1)
{
	document.onmousemove = getMousePositionNetscape7;
}
else if (agt.indexOf('netscape')==-1)
{
	document.onmousemove = getMousePosition;
}
else
{
	document.onmousemove = getMousePositionNetscape7;
}

function showMenu(thelayer)
{
	menu_to_keep = thelayer; 
	hideAllLayers(); 
	showMenuLayer(thelayer);
}

function getRealPosLeft(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;
}

function getRealPosTop(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 showMenuLayer(thelayer)
{
	head = document.getElementById(menuHeads[thelayer]);
	elm = document.getElementById(menuLayers[thelayer]);
    elm.style.visibility = "visible";
	elm.style.left = getRealPosLeft(head);
	elm.style.top = getRealPosTop(head) + 20;
}

function hideMenu()
{
	menu_to_keep = -1; 
	setTimeout('hideAllLayers()', 200);
}

function hideAllLayers()
{
	for(i = 0; i < menuLayers.length; i++)
	{  
		checkMousePosition(i);

		if(menu_to_keep != i)
		{ 
			elm = document.getElementById(menuLayers[i]);
			elm.style.visibility = "hidden";
		}
	}
}

function getMousePosition()
{
	mouseX = event.clientX; 
	mouseY = event.clientY;
}

function getMousePositionNetscape7(event)
{
	mouseX = event.clientX; 
	mouseY = event.clientY;
}

function checkMousePosition(i)
{       
	elm = document.getElementById(menuLayers[i]);

	x_min = elm.style.pixelLeft;
	x_max = x_min + elm.style.pixelWidth;
	y_min = elm.style.pixelTop;
	y_max = y_min + elm.style.pixelHeight;
	
	if ((mouseX >= x_min) && 
		(mouseX <= x_max) && 
		(mouseY >= y_min) && 
		(mouseY <= y_max)
	   )
	{
		setTimeout('hideAllLayers()', 200);
	}
}

function bgcolor(id,color)
{
	document.getElementById(id).style.backgroundColor = color;
}

function rollover(id,color)
{
	document.getElementById(id).style.color = color;
}