
//traverse le tree de la page et trouve les pitons, pour leur ajouter le comportement */
function initHover(){
	
	var dvs=document.getElementsByTagName('DIV');
	var dv;
	for(var n in dvs){//loop ds les divs
		dv=dvs[n];
		
		if(dv.className=='bouton'){//si le div est un piton, lui met les evenements
			dv.onmouseenter=hoverPiton;
			dv.onmouseout=hoverPiton;
		}
		
	}
	
}
function hoverPiton(){
	
	if(this.className=='bouton'){
		this.className='bouton_hov';
	} else {
		this.className='bouton';
	}
}

/** Hover d'image generique *************************************************************************

	Prend une image et lui assigne un rollover. Les noms des fichiers images doivent être xxxxxoff.ext pour le off et xxxxxov.ext pour le hover.
	L'image est enregistree avec ce comportement quand elle a  onload="initImHov(this)" dans son tag.


*/

function hoverImg(){
	if(this.src==this.origSrc){
		//_debug('hover'+this.origSrc,true);
		this.src=preHover.getSrc(this.hovIndex);
	}else{
		//_debug('out'+this.origSrc,true);
		this.src=this.origSrc;
	}
}

//la reg qui trouve le state de l'image dans le nom
regHov=new RegExp(/off\./i);

//le array des images preloadées

cPreloads = function(){
	this.imgs=new Array();
}
cPreloads.prototype.imInArray = function ( checkSrc ) {
	
	var len = this.imgs.length;
	for ( var x = 0 ; x < len ; x++ ) {
		//_debug(x+ ' ' + this[x].src);
		if ( this.imgs[x].src == checkSrc ) return x;
	}
	return false;
}
cPreloads.prototype.getLen = function () {
	return this.imgs.length;
}
cPreloads.prototype.getSrc = function (indx) {
	return this.imgs[indx].src;
}
cPreloads.prototype.addIm = function (im, indx) {
	return this.imgs[indx]=im;
}

preHover=new cPreloads();

/* cette fonction doit etre au onload des images qui hover **********************************************************************************/
function initImHov(im){

	//eneleve le onload
	im.onload=null;

	//trouve le nom de l'image
	var imSrc=im.src;
	var hovSrc=imSrc.replace(regHov, 'ov.');

	var imIndex=preHover.imInArray(hovSrc);//l'index de l'image dans le array des load si elle existe
	
	if(imIndex===false){//si l'image n'existe pas ds le array, la met
		//_debug(hovSrc + ' ajoutée');
		
		var imHov=new Image;
		imHov.src=hovSrc;//cree l'image
		
		var imIndex=preHover.getLen();
		preHover.addIm(imHov,imIndex);
	}
	
	im.hovIndex=imIndex;//index de l'image hover
	im.origSrc=imSrc;//src originale
	
	//sette le rollover
	im.onmouseover=hoverImg;
	im.onmouseout=hoverImg;
}

