// JavaScript Document
// Site : Quilvest Family
// Objectif : Gestion du menu du site
// Commentaires : gère les rollovers sur les ongletes de manières non intrusive.


// this fonction apply the CSS style and the event
function initMenu()
{
    // a test to avoid some browser like IE4, Opera 6, and IE Mac
    if ( browser.isDOM1 
    && !( browser.isMac && browser.isIE ) 
    && !( browser.isOpera && browser.versionMajor < 7 )
    && !( browser.isIE && browser.versionMajor < 5 ) )
    {
        // get some element
        var menu = document.getElementById('menu'); // the root element
        var imgs = menu.getElementsByTagName('img'); // all the img in root element
        
        // i am searching for ul element in li element
        for ( var i=0; i<imgs.length; i++ )
        {
			addAnEvent(imgs.item(i),'mouseover',rollover);
			addAnEvent(imgs.item(i),'mouseout',rollout);
        }
    }
}

//library de fonctions
//--------------------

function addAnEvent( target, eventName, functionName )
{
    // apply the method to IE
    if ( browser.isIE )
    {
        //attachEvent dont work properly with this
        eval('target.on'+eventName+'=functionName');
    }
    // apply the method to DOM compliant browsers
    else
    {
        target.addEventListener( eventName , functionName , true ); // true is important for Opera7
    }
}

function chgPointer()
{
	this.style.cursor = 'pointer';	
}

function rollover()
{
	this.style.cursor = 'pointer'; // change le pointer qd le rollover ne se fait pas sur un lien
	originalimgpath = this.src;
	var imgpath = this.src;
	var imgname = imgpath.split('/')[imgpath.split('/').length-1].split('.')[0];
	var ext = imgpath.split('/')[imgpath.split('/').length-1].split('.')[1];
	var newimgname = imgname+'-on.'+ext;
	var expr = eval("/."+ext+"/");
	if(imgpath.indexOf("-on")==-1)
	{
		newimgpath = imgpath.replace(expr,"-on."+ext);
		this.src = newimgpath;
	}else{
		newimgpath = imgpath;
	}
}

function rollout()
{
	imgpath = this.src;
	if(originalimgpath.indexOf("-on")==-1)
	{
		var imgname = imgpath.split('/')[imgpath.split('/').length-1].split('.')[0];
		var ext = imgpath.split('/')[imgpath.split('/').length-1].split('.')[1];
		var newimgname = imgname+'.'+ext;
		var expr = eval("/-on."+ext+"/");
		var newimgpath = imgpath.replace(expr,"."+ext);
		this.src = newimgpath;
		//alert(newimgpath);
	}
}

// initialise le script :
function init()
{
	initMenu();
}
window.onload = init;
