/*   These functions allow mouse overs without setting handlers in the HTML

******* top nav ********
It gets a nodeList of imgs, which are children of the container you specify.
It sets up mouse and keyboard events, assigned to the roll function.
It checks for a valid node.
It strips the file extension and then looks for _over in the remaining string
and uses that to determine which file path to use for the img src.
It checks the A element id against the current URL and if it matches
the id substring in the URL, it sets the image On, and disables events for that element.
*/
function doTopNav(navroot) {
    var imgs=document.getElementById(navroot).getElementsByTagName('img');
    var flag = false;
    for(var i=0 ;i < imgs.length; i++) {
        // sets On state for top nav
        if(!flag && matchToID(imgs[i].parentNode) ){
            roll(imgs[i].parentNode);
            flag = true;
            continue;
        }
        
        imgs[i].parentNode.onmouseover=function(){roll(this);};
        imgs[i].parentNode.onmouseout=function(){roll(this);};
        imgs[i].parentNode.onfocus=function(){roll(this);};
        imgs[i].parentNode.onblur=function(){roll(this);};
    }
}
// the swapper
function roll(o) {
    var node, src, filetype, newsrc, currentNode, pointer;
    // make sure its an img tag node
    for (var i=0; i < o.childNodes.length; i++) {
        currentNode=o.childNodes[i];
        if(currentNode.nodeType==1 && /img/i.test(currentNode.nodeName)) {
            node=i;
            break;
        }
    }
    // get src and switch the file path
    src = o.childNodes[node].src;
    filetype = src.substring(src.lastIndexOf('.'), src.length);
    if(/_over/.test(src)) { newsrc = src.replace('_over','');  }
    else{ newsrc = src.replace(filetype, '_over'+filetype); }
    o.childNodes[node].src=newsrc;
}
// searches location for substring that matches A id
function matchToID(node){
    var mtags = document.getElementsByTagName('meta');
    for(var i=0; i < mtags.length; i++){
        if(mtags[i].getAttribute("name") == "site-section"){
            if( mtags[i].getAttribute("content").indexOf( node.getAttribute("id") ) != -1 ){ 
                return true;
             }
            return false;
        }   
    }
}