// ACTIVE LINK version 0.3(2009/01/28)
// Automatic functions for webpages
// Copyright: (c) 2007-2009, Kazuya Numajiri
//---------------------------------------

// user custom
activeColor = "#FFFFFF";
activeImg = "_ov";
ROOT="http://analysis.nacinc.jp/";

//------------------------------------
// addEvent
if (window.addEventListener) {
    window.addEventListener("load", activeLink, false);
} else if (window.attachEvent) {
    window.attachEvent("onload", activeLink);
} else  {
    window.onload = activeLink;
}
//------------------------------------
function activeLink() {
var path=window.location.href;
now_dir=path.substring(0,path.lastIndexOf('/',path.length)+1);
if(path.indexOf('/index.',0)>0) { path=path.substring(0,path.lastIndexOf('/index.html',path.length)+1);}
//check a tag
var a=document.getElementsByTagName('a');
    for(var i=0;a.length>i;i++) {
        if(a[i].className == "active") {
            var k=a[i].href;
            if(k.indexOf('/index',0)>0) { top_dir=k.substring(0,k.lastIndexOf('/index.html',path.length)+1);}
            else { top_dir=k;}
            if(path==k || path.indexOf(top_dir,0)>=0) {
                var style = a[i].currentStyle || document.defaultView.getComputedStyle(a[i], '');
                var imgURL=style.backgroundImage;
                imgExt=imgURL.substring(imgURL.lastIndexOf(".",imgURL.length),imgURL.length);
                var Newimg=imgURL.replace(imgExt,activeImg+imgExt);
                a[i].style.backgroundImage = Newimg;
                a[i].style.color = activeColor;
            }
        }
    }//for
//check img tag
var b=document.getElementsByTagName('img');
    for(var i=0;b.length>i;i++) {
        if(b[i].className == "active") {
            var k=b[i].parentNode.href;
            if(k.indexOf('/index.',0)>0) { top_dir=k.substring(0,k.lastIndexOf('/index.html',path.length)+1);}
            if(k.indexOf('/index.',0)>0) { k=k.substring(0,k.lastIndexOf('/index.html',path.length)+1);}
            else { top_dir=k;}
            if(top_dir==ROOT) top_dir=top_dir+'products/';
            if(path==k || (path.indexOf(top_dir,0)>=0 && now_dir!=top_dir)) {
                var imgSrc=b[i].src;
                imgExt=imgSrc.substring(imgSrc.lastIndexOf(".",imgSrc.length),imgSrc.length);
                var Newimg=imgSrc.replace(imgExt,activeImg+imgExt);
                b[i].src = Newimg;
            }
        }
    }
}