var menuLengths = new Array(4,5,5,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 vTop = 0;
var vRight = 1;
var vBottom = 2;
var vLeft = 3;

menuOffsets[0][0]= -67;
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]= -79;
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;
    }
}

// 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 = desco_gat(menuObj) + menuOffsets[intIndex-1][vTop];
		//menu.right = gar(menuObj) + menuOffsets[intIndex-1][vRight];
		//menu.bottom = gab(menuObj) +  menuOffsets[intIndex-1][vBottom];
		menu.left = gal(menuObj) +  menuOffsets[intIndex-1][vLeft];
    }
}

//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 desco_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;
}

//Popup Functions
function popupDisclaimer(){
	var win=window.open("/disclaimer.html","_blank","width=494,height=630,top=300,left=400")
}


function popupIR(){
	var win=window.open("https://www.deshaw.com/irweb","_blank","width=874,height=635,top=100,left=100,menubar=yes,location=yes,scrollbars=yes,status=yes,toolbar=yes,resizable=yes")
}

function popupDgray(){
	var win=window.open("discgray.html","disclaimer2","width=500,height=380,top=350,left=410")
}
function popupOncampus(){
	var win=window.open("oncampusgray.htm","Oncampusother","width=580,height=670,top=110,left=200")
}	

function popupOncampusLite(){
	var win=window.open("oncampuslite.htm","_blank","width=608,height=662,top=95,left=200,scrollbars=yes,resizable=yes")
}

function popup(URL){
	var win=window.open(URL,"_blank","width=740,height=480,top=100,left=100,location=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes,resizable=yes")
}

function popupOncampusWide(){
	var win=window.open("oncampuswidefull.htm","Oncampus","width=995,height=590,top=300,left=200")
}

function popupOncampusWideF(){
	var win=window.open("oncampuswidefull.htm","Oncampus","width=995,height=660,top=240,left=200")
}

function popupArticles(){
	var win=window.open("Articles.html","articles","width=500,height=650,top=300,left=400,scrollbars:auto")
}

//Employee Profile Flyouts

var timerId = 0;  
function stopTimer(){
	if (timerId != 0) {
		clearTimeout(timerId);
		timerId = 0;
	}
}

function startTimer(targetElement){
	stopTimer(timerId);
	timerId = setTimeout(function(){
		$(targetElement).children("#go").stop(true, true).animate({
			opacity: "show",
			left: "97"
		}, "fast")
	}, 500);
}

$(document).ready(function(){
	$(".flyout").hover(function(){
		startTimer(this);
	}, function(){
		stopTimer();
		$(this).children("#go").animate({opacity: "hide", left:"-2"}, "fast");
	});
});
// Employee Individual Profile's Q&A script
$(document).ready(function(){
						$(".question").click(function(){
							$(".answer").hide();
							$("li.question").css("font-weight","normal");
							$(this).css("font-weight","bold");
							$(".answer").filter("."+$(this).attr("id")).show();
							$('.question').removeClass('selectedq');
							$(this).addClass("selectedq");
						});
					});
					
						
$(document).ready(function(){
		$("li.question").hover(over,out);
	});


function over(){
	if (  $(this).attr('class')=='question'  )
	{
		$(this).css('font-weight','bold');
	}
	$(this).css("color","#006699");
	
}


function out(){
		if (  $(this).attr('class')=='question'  )
		{
			$(this).css('font-weight','normal');
		}
		$(this).css("color","#000000");
}
//
