
var tmp_arr = new Array();
var found_link = false;
var a_location;

var base_href = "";

function main(){

    var menu = $('menu');
    var atoz = $('nav');
	var newsmenu = $('nav-news');
	var submenu = $('submenu');
	var acadmenu = $('acadmenu');
	var menu_marketing = $('menu_marketing');
    
    if( document.location.href.indexOf("?") > 1){
        base_href = document.location.href.substring(0, document.location.href.indexOf("?"));
    }
    else{
        base_href = document.location.href;
    }

    if( menu != null){
        find_list_path( menu, 3);
    }
    if( atoz != null){
        find_list_path( atoz, 5);
    }
	if( newsmenu != null){
        find_list_path( newsmenu, 5);
    }
	if( menu_marketing != null){
        find_list_path( menu_marketing, 4);
    }
    show_default_menu();
    
    tmp_arr = new Array();
    found_link = false;
    
	if( submenu != null && submenu != 'undefined'){
        find_list_path( submenu, 4);
		show_default_submenu();
    }
	
	else if( acadmenu != null && acadmenu != 'undefined'){
        find_list_path( acadmenu, 4);
		show_default_acadmenu();
    }
	
}

function hide_default_menu(){
    
    for( var i=0; i<tmp_arr.length; i++){
        if( tmp_arr[i].getElementsByTagName("ul")[0] != null){
            tmp_arr[i].getElementsByTagName("ul")[0].style.visibility = '';
        }
        if( tmp_arr[i].getElementsByTagName("a")[0] != null){
            tmp_arr[i].getElementsByTagName("a")[0].style.color = '';
			tmp_arr[i].getElementsByTagName("a")[0].style.backgroundImage = '';
        }
    }
}

function show_default_menu(){
    
    for( var i=0; i<tmp_arr.length; i++){
        if( tmp_arr[i].getElementsByTagName("ul")[0] != null){
            tmp_arr[i].getElementsByTagName("ul")[0].style.visibility = 'visible';
        }
        if( tmp_arr[i].getElementsByTagName("a")[0] != null){
            tmp_arr[i].getElementsByTagName("a")[0].style.color = '#A70230';
            if(tmp_arr[i].getElementsByTagName("a")[0].className != 'no-arrow'){
			    tmp_arr[i].getElementsByTagName("a")[0].style.backgroundImage = 'url(/i/arrow-red.gif)';
			}
        }
    }
}

function show_default_menu_marketing(){
    
    for( var i=0; i<tmp_arr.length; i++){
        if( tmp_arr[i].getElementsByTagName("ul")[0] != null){
            tmp_arr[i].getElementsByTagName("ul")[0].style.visibility = 'visible';
        }
        if( tmp_arr[i].getElementsByTagName("a")[0] != null){
            tmp_arr[i].getElementsByTagName("a")[0].style.color = '#A70230';
            if(tmp_arr[i].getElementsByTagName("a")[0].className != 'no-arrow'){
			    tmp_arr[i].getElementsByTagName("a")[0].style.backgroundImage = 'url(/i/arrow-red.gif)';
			}
        }
    }
}

function show_default_submenu(){
    
    for( var i=0; i<tmp_arr.length; i++){
        if( tmp_arr[i].getElementsByTagName("ul")[0] != null){
			tmp_arr[i].getElementsByTagName("ul")[0].style.display = 'block';
        }
        if( tmp_arr[i].getElementsByTagName("a")[0] != null){
            tmp_arr[i].getElementsByTagName("a")[0].style.color = '#A70230';
            if(tmp_arr[i].getElementsByTagName("a")[0].className != 'no-arrow'){
			    tmp_arr[i].getElementsByTagName("a")[0].style.backgroundImage = 'url(/i/arrow-red.gif)';
			}
        }
    }
}

function show_default_acadmenu(){
    
    for( var i=0; i<tmp_arr.length; i++){
        if( tmp_arr[i].getElementsByTagName("ul")[0] != null){
			tmp_arr[i].getElementsByTagName("ul")[0].style.display = 'block';
        }
        if( tmp_arr[i].getElementsByTagName("a")[0] != null){
            tmp_arr[i].getElementsByTagName("a")[0].style.color = '#A70230';
            if(tmp_arr[i].getElementsByTagName("a")[0].className != 'no-arrow'){
			    tmp_arr[i].getElementsByTagName("a")[0].style.backgroundImage = 'url(http://www.zycko.com/services/i/red-arrow-menu.gif)';
			}
        }
    }
}


function find_list_path( elem, url_idx){

    a_location = base_href.split("/");
    
    for( var j=0; j<a_location.length && !found_link; j++){
    
        var new_start = false;
        
        for( var k=0; k<elem.childNodes.length && !new_start; k++ ){
            
            var i = 0;
            var tmp = get_children(elem)[k];
            
            while( i<get_children(tmp).length && !found_link && !new_start){
            
                var kids = get_children(tmp);
            
                if( kids[i].tagName == 'LI' && get_children(kids[i])[0] != null && get_children(kids[i])[0].tagName == 'A'){
                
                    a_href = get_children(kids[i])[0].href.split('/');
                    
                    if( a_location[j+url_idx] != null && a_location[j+url_idx] == a_href[j+url_idx] ){
                    
                        tmp_arr.push( kids[i]);
                        
                        if( j+url_idx == a_location.length-1 ){
                            found_link = true;
                        }
                        else{
                            if( get_children(kids[i]).length > 1 && get_children(kids[i])[1].tagName == 'UL' ){
                                // set the elem variable, and reset everything
                                elem = kids[i];
                                new_start = true
                            }
                        }
                    }
                }
                i++
            }
        }
    }
}

function get_children( elem){

    var tmp = new Array();
    
    if( elem != null ){
        for( var i=0; i<elem.childNodes.length; i++){
            if( elem.childNodes[i].tagName != null){
                tmp.push( elem.childNodes[i]);
            }
        }
    }
    return tmp;
}

function $( v ){
    return document.getElementById( v );
}

function land(ref, target)
{
lowtarget=target.toLowerCase();
if (lowtarget=="_self") {window.location=loc;}
else {if (lowtarget=="_top") {top.location=loc;}
else {if (lowtarget=="_blank") {window.open(loc);}
else {if (lowtarget=="_parent") {parent.location=loc;}
else {parent.frames[target].location=loc;};
}}}
}
function jump(menu)
{
ref=menu.choice.options[menu.choice.selectedIndex].value;
splitc=ref.lastIndexOf("*");
target="";
if (splitc!=-1)
{loc=ref.substring(0,splitc);
target=ref.substring(splitc+1,1000);}
else {loc=ref; target="_self";};
if (ref != "") {land(loc,target);}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}