// hilite_current_page_link //

// config stuff
nav_container = "nav";
hilite_class = "hilite";
root_path = "intermedia.vancouverartinthesixties.com";

// declare some variables we'll be using later
arr_first_a_tags = new Array();
el_current_section_a_tag = "";

$(document).ready(function() {                 
    // if #submenu exists, and it has a ul in it, run set_up_menu
    if (document.getElementById(nav_container)) {   
        if (document.getElementById(nav_container).getElementsByTagName("ul")[0]) {
            set_up_menu();
        }
    }
});

//////////////////////////////////////////

function strstr(needle, haystack) {
    if (haystack.indexOf(needle) != -1) {
        return true;
    } else {
        return false;
    }
}

//////////////////////////////////////////

function get_templatename(templatename) {
    // do we have the full path?
    //alert("1: " + templatename)

    if (strstr( root_path, templatename )) {
        //if we do, remove it.
        templatename = templatename.substring(templatename.lastIndexOf((root_path+'\/')) + root_path.length, templatename.length);
        //alert("2: " + templatename)
    }
   
    templatename = templatename.substring(0, (templatename.indexOf('\/', 1)+1) );
    //alert("3: " + templatename)
   
    return templatename
}

//////////////////////////////////////////

function set_up_menu() {
	
    // figure out where we are:
    this_templatename = get_templatename(String(document.location));
	
	if (this_templatename == "") {
		this_templatename = "/home/";
	}
    
    // make an array of only first li tags - arr_first_a_tags
    first_list = document.getElementById(nav_container).getElementsByTagName("ul")[0]
    arr_first_list_li_tags = document.getElementById(nav_container).getElementsByTagName("ul")[0].getElementsByTagName("li");
    for (i=0; i<arr_first_list_li_tags.length; i++){
        if (first_list == arr_first_list_li_tags[i].parentNode){
            arr_first_a_tags.push(arr_first_list_li_tags[i].getElementsByTagName("a")[0]);
        }
    }
   
    // determine if we are in a section that belongs to one of those a tags.
    //   if so, remember that tag - el_current_section_a_tag
    for (i=0; i<arr_first_a_tags.length; i++){
        arr_links_to_check = arr_first_a_tags[i].parentNode.getElementsByTagName("a");
        for (a=0; a<arr_links_to_check.length; a++){
			//alert(get_templatename(arr_links_to_check[a].href));
            if (strstr(this_templatename, get_templatename(arr_links_to_check[a].href))) {
                el_current_section_a_tag = arr_first_a_tags[i];
            }
        }
    }
   
    // hilite the link if it is current

    el_current_section_a_tag.setAttribute("class", hilite_class);
    el_current_section_a_tag.className = hilite_class;
}
