$(document).ready(function() {   
    // add hoverIntent bindings for header nav    
    $(".navElement").hoverIntent( function(){ navElementSelected(this); } , function(){} );
    
    var agent= navigator.userAgent.toLowerCase();
    var ver = parseInt(navigator.appVersion);
    var ie = agent.indexOf("msie")>=0;
    var ie6=ie && agent.indexOf("msie 6")>=0;

    // this is a fix for the nav on ie6.  without this, the nav with dissappear when mousing over the selections, because there is a gap between the list elements in the nav (only ie6)
    if (ie6) {
        var config = {    
             sensitivity: 15, // number = sensitivity threshold (must be 1 or higher)    
             interval: 200, // number = milliseconds for onMouseOver polling interval    
             over: function(){}, // function = onMouseOver callback (REQUIRED)    
             timeout: 500, // number = milliseconds delay before onMouseOut    
             out: function(){ navElementUnselectAll(); } // function = onMouseOut callback (REQUIRED)    
        };
        $("#navBar").hoverIntent( config );
    } 
    else {
        $("#navBar").hoverIntent( function(){}, function(){ navElementUnselectAll(); } ); 
    }

});

// ******************** Search form code ****************
function submitform() {
    document.searchForm.submit();
}

// ******************** Nav bar code ********************
function navElementSelected(thisElement) {
    var splitString = $(thisElement).attr("id").split("_");
    var menuNum = splitString[1];   

    navElementUnselectAll();
    
    navigatorDetected = navigator.userAgent.toLowerCase();

	if (checkIt('firefox', navigatorDetected)) {
        // find the position of the nav element (for FF)
        var pos = $(thisElement).offset();
    } else {
        // find the position of the nav element (for IE and others)
        var pos = $(thisElement).position();        
    }

    // place the menu content in the right spot
    $("#navContent_"+menuNum).css("left", pos.left+1);
    $("#navContent_"+menuNum).css("top", pos.top + 20);
    $("#navContent_"+menuNum).css("visibility", "visible");

    $(thisElement).css("background-color", "#EEEEEE");
    $(thisElement).css("color", "black");
}

function navElementUnselectAll() {
    $(".navElement").css("background-color", "");
    $(".navElement").css("color", "#444444");
    $(".navContent").css("visibility", "hidden");
}

function getElementSuffixNum(thisElement) {
    var splitString = $(thisElement).attr("id").split("_");
    return splitString[1];   
}
function getElementSubSuffixNum(thisElement) {
    var splitString = $(thisElement).attr("id").split("_");
    return splitString[2];   
}

function checkIt(string, navigatorDetected) {
	var place = navigatorDetected.indexOf(string) + 1;
    return place;
}
