/* ---nav_hover.js------------------------------------------------------------ */
/*  This object pulls all of the <img> out of the specified container to create
    rollover effects. It is used for pages which load a new nav_hover each
    page - meaning my_nav.set(); must be called on each page load in order to
    highlight the current page.
    If the 'suffix' property is not set, img file names must end in _on, then the
    file extension. For example: home.jpg and home_on.jpg are valid file names.

    Arguments:
        nav_container:  this arg specifies the id of the element containing the
                        nav images

    Examples:
        var my_nav = new nav_hover('menu_container'); //Makes a new 'nav_hover'
                                                        object using the element
                                                        whose id is 'menu_container'
        my_nav.suffix = '_th'; //Changes the '_on' default suffix for file names
                                to '_th'. Therefore, home.jpg and home_th.jpg are
                                valid file names.*/

function nav_hover(nav_container){
    this.nav_container = document.getElementById(nav_container);
    this.nav_images = this.nav_container.getElementsByTagName('img');
    this.set_src = '';
    this.suffix = '_on';
    for(var i=0;i<this.nav_images.length;i++){
        var cur = this.nav_images[i];
        cur.nav_hover = this;
        cur.onmouseover = function(){
            if(this.nav_hover.set_src!=this.src)
                this.nav_hover.turn_on(this);
        }
        cur.onmouseout = function(){
            if(this.nav_hover.set_src!=this.src)
                this.nav_hover.turn_off(this);
        }
    }
}
nav_hover.prototype.turn_on = function(image){
    var ext = image.src.match(/.[a-zA-Z0-9]{2,4}$/);
    var new_src = image.src.replace(/.[a-zA-Z0-9]{2,4}$/,this.suffix+ext);
    image.src = new_src;
}

nav_hover.prototype.turn_off = function(image){
    var ext = image.src.match(/.[a-zA-Z0-9]{2,4}$/);
    var re = new RegExp(this.suffix+".[a-zA-Z0-9]{2,4}$");
    //var new_src = image.src.replace(/_on.[a-zA-Z0-9]{2,4}$/,ext);
    var new_src = image.src.replace(re,ext);
    image.src = new_src;
}
nav_hover.prototype.set = function(index){
    this.turn_on(this.nav_images[index]);
    this.set_src = this.nav_images[index].src;
}