/*smartnav2.js
 * (c) Boston University 2004 * Networked Information Services
 *  rjaeckel
 * JavaScript based SmartNav
 * allows for image or CSS based navigation
 *
 * needs trigger function eval_location(parameters)
 * to execute the appropriate code
 * Example :
 * function eval_location(){
 *    setNav('location',mkeys,'navbar1','menu','gif','ind','gif');
 *    if (typeof(mkeys) != 'undefined'&& mkeys.length>1) {
 *****CSS based example:
 *     evaluate location or title, array of keyword/image singletons
 *     or pairs, CSS style name
 *     setCSSNav('location',mkeys,'','activelink');
 ****** image based example:
 *     evaluate location or title, array of keywords/image singletons
 *     or pairs, navbar name, image prefix, image type, indicator prefix,
 *     indicator type
 *     setNav('title',mkeys,'','navbar1','l2','gif','ind','gif');
 *     }
 *    return true;
 * }
 */
//
// FUNCTION setCSSNav
// generic CSS SmartNav with options
// When kMode is title then spaces in the title are replaced with
//underscores
//
// arguments:
// kMode    -> validate against location or title. "location" triggers
//location, anything else is title
// kArray    -> array of keywords with keyword mapping through pipes
//"keyword|targetid"
// prefix    -> id prefix if specified
// navStyle    -> style attribute to be set, allows for individualized
//CSS style names
//
function setCSSNav(kMode, kArray, prefix, navStyle)
{
    // ascertain the document property
    if (kMode == 'location') {
        var here=new String(document.location);
    } else {
        var here=new String(document.title.toLowerCase());
        var pattern = /\s/g;
        here = here.replace(pattern,"_");
    }


    // get browser info
    var bVersion = parseInt(navigator.appVersion);
    var bName = navigator.appName;

    // work through the keywords and test against the here string
    for (i=0;i<kArray.length;i++){
      
        // split function -> if pipe present
        var trigger = new Array();
        trigger = nameTarget(kArray[i]);

        if (here.indexOf(trigger[0])>-1){

            // add prefix if needed
            if (prefix != '') {
                var keyword = prefix+trigger[1];
            } else {
                var keyword = trigger[1];
            }

            // set CSS property
            if ((bName.indexOf('Netscape')>-1&& bVersion
                >4)||(bName.indexOf('Explorer')>-1 && bVersion >=4)){
                var myObj = document.getElementById(keyword);
                myObj.className=navStyle;
                return;
            }
        }
    }
}

// FUNCTION nameTarget
// split pairs into match part and destination part
//
function nameTarget(keyword) {
  
    if (keyword.indexOf('|')>-1) {
        var keyArray = keyword.split('|');
    } else {
        var keyArray = Array(keyword,keyword);
    }
return keyArray;
}
//
// FUNCTION setNav
// generic SmartNav with options
//
// arguments:
// kMode    -> validate against location or title
// kArray    -> array of keywords
// nBar        -> navbar name
// prefix    -> images/object prefix
// iType    -> image type gif or jpg or png
// xInd        -> extra indicator image prefix
// xiType    -> extra indicator image type
//
function setNav(kMode,kArray,nBar,prefix,iType,xInd,xiType)
{
		
    // ascertain the document property
    if (kMode == 'location') {
        var here=new String(document.location); 
    } else {
        var here=new String(document.title.toLowerCase());
    }

    // work through the keywords and test against the here string
    for (i=0;i<kArray.length;i++){
      
        // split function -> if pipe present
        var trigger = new Array();
        trigger = nameTarget(kArray[i]);

        if (here.indexOf(trigger[0])>-1){

            // get curent image source property
            var imgName = new String(prefix+trigger[1]);
	
		    path=new String(document.images[imgName].src);
            // get the path to the graphics folder
            path = path.substring(0,path.lastIndexOf("/")+1);

            // execute standard MM behavior
           MM_nbGroup('down',nBar,imgName,path+prefix+(prefix.length>0?'-':'')+trigger[1]+'-d.'+iType,1);

            // check for additional indicator
            if (xInd.length > 0) {
                document.images[xInd+trigger[1]].src = path+xInd+'-'+trigger[1]+'-d.'+xiType;
            }
			return true;
        }
    }
}

