window.addEvent('domready', function(){
	var navs = $$('.activenav');
    navs.each(function(item,index){
            var src = item.getProperty('src');
            ext = getExtension(src);
            index = item.src.indexOf(ext);
            firstpart = item.src.substring(0,index);
            item.rollonImg = new Asset.image(firstpart + "_h" + ext);
            item.rolloffImg = new Asset.image(src);
            item.addEvent('mouseover', function(){
                    item.setProperty('src',item.rollonImg.src);
            })
            item.addEvent('mouseout', function(){
                    item.setProperty('src',item.rolloffImg.src);
            })
    });
    
    var bgs = $$('.activebg');
    bgs.each(function(item,index){
            var src = getBGImage(item);
            ext = getExtension(src);
            index = src.indexOf(ext);
            firstpart = src.substring(0,index);
            item.rollonImg = new Asset.image(firstpart + "_h" + ext);
            item.rolloffImg = new Asset.image(src);
            item.addEvent('mouseover', function(){
                    backgroundRollover(item);
            })
            item.addEvent('mouseout', function(){
                    backgroundRollout(item);
            })
    });
});

function getExtension(file){
        return file.substring(file.length - 4);
}


function rollover(which){
        index = which.src.indexOf(".gif");

        if (index > -1){
                firstpart = which.src.substring(0,index);
                which.src = firstpart + "_h.gif";
                }
        else{
                index = which.src.indexOf(".png");
                if (index > -1){
                        firstpart = which.src.substring(0,index);
                        which.src = firstpart + "_h.png";
                        }
                }
        }

function backgroundRollover(which){
	path = getBGImage(which);
	ext = getExtensionFromPath(path);
	cleanPath = getPathWithoutExtension(path);
	newval = "url(" + cleanPath + "_h." + ext + ")";
	which.style.backgroundImage = newval;
}

function getBGImage(which){
	fulltext = which.style.backgroundImage;
	path = fulltext.substring(4, fulltext.length -1);
	return path;
}

function getExtensionFromPath(path){
	return path.substring(path.length - 3);
}

function getPathWithoutExtension(path){
	return path.substring(0,path.length - 4);
}

function getPathWithoutH(path){
	return path.substring(0,path.length - 2);
}

function rollout(which){
        index = which.src.indexOf("_h.gif");
        if (index > -1){
                firstpart = which.src.substring(0,index);
                which.src = firstpart + ".gif";
                }
        else{

        index = which.src.indexOf("_h.png");
        if (index > -1){
                firstpart = which.src.substring(0,index);
                which.src = firstpart + ".png";
                
                
                }
                }
        }

function backgroundRollout(which){
	path = getBGImage(which);
	ext = getExtensionFromPath(path);
	cleanPath = getPathWithoutExtension(path);
	newval = "url(" + getPathWithoutH(cleanPath) + "." + ext + ")";
	which.style.backgroundImage = newval;
}
