function buildSubMenu(menuId, subMenuId, name, href, pnav, snav){
	var subMenuListEl = document.createElement("li");
	subMenuListEl.setAttribute("id", subMenuId);
	subMenuListEl.innerHTML = getSubMenuRef(name, href);
	var menu = document.getElementById(menuId);
	menu.appendChild(subMenuListEl);
	if(pnav == current_row && snav == current_col)
	{
		//Highlight this element
		subMenuListEl.style.background = '#AFA177';
	}
}

function highlightMainNav(menuId, pnav)
{
	if(pnav == current_row)
	{
		document.body.className = mapMenuID(menuId);
	}
}

function getSubMenuRef(name, href){
	return "<a href=\"" + href + "\">" + name + "</a>";
}

function buildMenuMaster() {
	for(var i=0; i<arrMenuId.length; i++){
		for(var j=0; j<arrSubMenuConfig[i].length; j++){
			buildSubMenu(arrMenuId[i],arrSubMenuConfig[i][j][0],arrSubMenuConfig[i][j][1], arrSubMenuConfig[i][j][2], arrSubMenuConfig[i][j][3], arrSubMenuConfig[i][j][4]);
			highlightMainNav(arrMenuId[i], arrSubMenuConfig[i][j][3]);
		}
	}
}

function buildMainMenuOnly() {
	for(var i=0; i<arrMenuId.length; i++){
		for(var j=0; j<arrSubMenuConfig[i].length; j++){
			highlightMainNav(arrMenuId[i], arrSubMenuConfig[i][j][3]);
		}
	}
}
function getPosition(menuPos){
	var pos = 0;
	for(var i=0; i<menuPos; i++){
		pos += arrWidth[i];
	}
	return pos;
}

function getBackgroundMenuPosition(menuPos, type, isPx){
	var pos = getPosition(menuPos);
	if(arrSubMenuConfig[menuPos][0][3] == current_row)
	{
		if(type == "hover"){
			return "-" + pos +  isPx + " -29" + isPx; 
		}
		else
			return  "-" + pos + isPx + " -58" + isPx;
	}
	else 
	{
		if(type == "hover"){
			return "-" + pos +  isPx + " -29" + isPx; 
		}
		else
			return  "-" + pos + isPx + " 0" + isPx;
	}
}

$(function(){

    // Main Nav Drop Downs
    
    $("ul.dropdown li").hover(function(){
    
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    
    });
    
    $("ul.dropdown li ul li").hover(function(){
    
        $(this).addClass("yellow_hover");
    
    }, function(){
    
        $(this).removeClass("yellow_hover");
    
    });
   
    // Necessary for IE 6 Main Nav Hovers to Work
    
    $("ul.dropdown #top_menu_01").hover(function(){
    
        $(this).css('background-position', getBackgroundMenuPosition(0, "hover", "px"));
        
    }, function(){
    
        $(this).css('background-position', getBackgroundMenuPosition(0, "", "px"));
    
    });
    
    $("ul.dropdown #top_menu_02").hover(function(){
    
        $(this).css('background-position', getBackgroundMenuPosition(1, "hover", "px"));
    
    }, function(){
    
        $(this).css('background-position', getBackgroundMenuPosition(1, "", "px"));
    
    });
    
    $("ul.dropdown #top_menu_03").hover(function(){
    
        $(this).css('background-position', getBackgroundMenuPosition(2, "hover", "px"));
    
    }, function(){
    
        $(this).css('background-position', getBackgroundMenuPosition(2, "", "px"));
    
    });
    
    $("ul.dropdown #top_menu_04").hover(function(){
    
        $(this).css('background-position', getBackgroundMenuPosition(3, "hover", "px"));
    
    }, function(){
    
        $(this).css('background-position', getBackgroundMenuPosition(3, "", "px"));
    
    });
    
    $("ul.dropdown #top_menu_05").hover(function(){
    
        $(this).css('background-position', getBackgroundMenuPosition(4, "hover", "px"));
    
    }, function(){
    
        $(this).css('background-position', getBackgroundMenuPosition(4, "", "px"));
    
    });
    
    $("ul.dropdown #top_menu_06").hover(function(){
    
        $(this).css('background-position', getBackgroundMenuPosition(5, "hover", "px"));
    
    }, function(){
    
        $(this).css('background-position', getBackgroundMenuPosition(5, "", "px"));
    
    });    
	
});