/* 
copyright:	2005-2006 greg canavera. www.totemic.net
there's nothing really new here, but please credit me for use if you do use it.
/* --------------------------------- */
/* rev 1.0							 */
/* --------------------------------- */
/* nav_on.js	 					 */
/* --------------------------------- */


// find nav matches _navids in array in the dom. creates new instances of Selectednav for each element

function findnav() {

    var _navids = Array("nav_1", "nav_2");

    for (i=0; i < _navids.length; i++) {
        if (document.getElementById(_navids[i]) != null) {			
            var _id = document.getElementById(_navids[i]);	
            new Selectednav(_id);
        }
        else { break; }
    }
}


// controller class. sets array and calls prototypes

function Selectednav(_id) {
    this._navitems = new Array();
    this.getNavItems(_id);
    this.setStyle();
}

// get Nav LI elements. add to navitems array

Selectednav.prototype.getNavItems = function(_id) {
    _topelements = _id.firstChild.firstChild;
    _lielements  = _topelements.getElementsByTagName("li").length;

    for (this.i=0; this.i < _lielements; this.i++) {
        this._navitems[this.i] = _topelements.childNodes[this.i].firstChild.getAttribute('id');
    }
}


// pull nav ids out of array.  check against URL for match. Apply new class to elements

Selectednav.prototype.setStyle = function() {
    _url = document.URL;

    for (this.i=0; this.i< this._navitems.length ; this.i++)	{

        if ( _url.match(this._navitems[this.i]) ) {
            document.getElementById(this._navitems[this.i]).className = "main_nav_on";
        }
    }
}

