var menuLengths = new Array(4,3,4,0,0,0,0);
var menuTimers = new Array(menuLengths.length);

// row index indicates menu
// column index indicates positioning coordinates
// top, right, bottom, left
var menuOffsets = new Array(4,4);
menuOffsets[0] = new Array(4);
menuOffsets[1] = new Array(4);
menuOffsets[2] = new Array(4);
menuOffsets[3] = new Array(4);
var top = 0;
var right = 1;
var bottom = 2;
var left = 3;

menuOffsets[0][0]= -47;
menuOffsets[0][1]= 0;
menuOffsets[0][2]= 0;
menuOffsets[0][3]= 8;

menuOffsets[1][0]= 42;
menuOffsets[1][1]= 0;
menuOffsets[1][2]= 0;
menuOffsets[1][3]= -66;

menuOffsets[2][0]= 0;
menuOffsets[2][1]= 0;
menuOffsets[2][2]= 0;
menuOffsets[2][3]= 0;

menuOffsets[3][0]= -59;
menuOffsets[3][1]= 0;
menuOffsets[3][2]= 0;
menuOffsets[3][3]= 19;

// Returns the style of the object associated with the given id
function getStyleObj(id) {
    if (document.getElementById || // DOM-compliant browsers (MSIE5, NSN6, O5)
        document.all) {            // or MSIE 4
        var obj = getObj(id);
        // Return the style only if the object is not null or not undefined
        if (obj)
            return obj.style;
        else
            return "";
    } else return getObj(id); // NSN4
}

// Returns the object corresponding to the id
function getObj(id) {
    if (document.getElementById) { // DOM-compliant browsers (MSIE5, NSN6, O5)
        return document.getElementById(id);
    } else if (document.all) { // MSIE4
        return document.all[id];
    } else if (document.layers) { // NSN4
        return document.layers[id];
    } else { // Trap DHTML-impaired browsers 
        //alert("Your browser does not support DHTML!");
        return false;
    }
}

//Popup Functions
function popupDisclaimer(){
	var win=window.open("/disclaimer.html","_blank","width=500,height=629,top=300,left=400")
}


// Function to show the flyout menus of a menu on mouseover
function showMenu(index) {

    if (menuTimers[index-1]) clearTimeout(menuTimers[index-1]);
    
    //Closing all other menus except for the current one
    for (i=1;i<=menuLengths.length;i++)
        if (i!=index) closeMenu(i);
        
    var menu = getStyleObj("menu"+index);
    if (menu) menu.visibility = "visible";
    
    //Obtaining the sytle object to change the background Color
    var menuRoot = getStyleObj("menuDiv" + index);
    var intIndex;
    try{
    	intIndex = parseInt(index);
    }catch(ne){
    	intIndex = index;
    }
    //menuRoot.backgroundColor = menubar[intIndex-1].overColor;
    var menuObj = getObj("menuDiv" + index);
    menuObj.className = menubar[intIndex - 1].styleClass + "_over";
    menuRoot.color = "white";
    menuRoot.cursor = "pointer";
    /**/
    
    if(intIndex < 5){
		menu.top = gat(menuObj) + menuOffsets[intIndex-1][top];
		//menu.right = gar(menuObj) + menuOffsets[intIndex-1][right];
		//menu.bottom = gab(menuObj) +  menuOffsets[intIndex-1][bottom];
		menu.left = gal(menuObj) +  menuOffsets[intIndex-1][left];
    }
}

//Function to hide the display of the flyout menus on mouseout
function hideMenu(index) {
	
	//
	// Setting timeout to 1/2 second. this is to ensure that 
	// the flyout menus are visible atleast for that period
	//
	if (menuTimers[index-1]) clearTimeout(menuTimers[index-1]);
    menuTimers[index-1] = setTimeout("closeMenu('"+index+"');", 0);
    var menuObj = getObj("menuDiv" + index);
    
    //Obtaining the sytle object to change the background Color
    var menuStyle = getStyleObj("menuDiv" + index);
    var intIndex;
    try{
    	intIndex = parseInt(index);
    }catch(ne){
    	intIndex = index;
    }
    if(menuObj && menuObj.innerHTML != currentMenu){
    	menuObj.className = menubar[intIndex - 1].styleClass;
    	menuStyle.color = "black";
    }
}

// Hides the flyout menu for the given index
function closeMenu(index) {
	var menu = getStyleObj("menu"+index);
    if (menu) menu.visibility = "hidden";
}

function overMenuItem() {
    showMenu(this.menuid);
}

function outMenuItem() {
    hideMenu(this.menuid);
}

function clickMenuItem() {
	if (this.url) { // There is a URL associated with this item
        window.location = this.url;
    }
}

function clickMenuItemIE(id) {
	var obj = getObj(id);
	if (obj && obj.url) { // There is a URL associated with this item
        window.location = obj.url;
    }
}

window.onload=setupMenus; // Assign to onLoad event handler

// Generates the header and left section 
function setupMenus() {
    buildMenuBar(currentMenu); // Assumes desco_menu.js is loaded
    if (document.layers) { // This section is for Netscape 4 only
        for (menuid=1;menuid<=menuLengths.length;menuid++) { // For each menu
            var menu = getObj("menu"+menuid);
            menu.menuid = menuid;
            var eTypes = Event.MOUSEOVER | Event.MOUSEOUT | Event.CLICK;
            menu.captureEvents(eTypes);
            menu.onmouseover = overMenuItem;
            menu.onmouseout = outMenuItem;
        }
    } else { // This section is for all other browsers
       for (menuid=1;menuid<=menuLengths.length;menuid++) { // For each menu
       		var menu = getObj("menu"+menuid);
            if (menu) {
                menu.menuid = menuid;
                menu.onmouseover = overMenuItem;
                menu.onmouseout = outMenuItem;
            }
        }
    }
}


/****************************************************/

/*
 * Returns absolute top of given control.
 */
function gat(ctrl)
{
	var eT = 0;
	for(var p=ctrl; p&&p.tagName!='BODY'; p=p.offsetParent)
	{
		eT += p.offsetTop;
	}
	return eT;
}

/*
 * Returns absolute left of given control.
 */
function gal(ctrl)
{
	var eT = 0;
	for(var p=ctrl; p&&p.tagName!='BODY'; p=p.offsetParent)
	{
		eT += p.offsetLeft;
	}
	return eT;
}
