// JavaScript Document
function ajouteEvent(objet, typeEvent, nomFunction, typePropagation){
	if(objet.addEventListener) {
		objet.addEventListener(typeEvent, nomFunction, typePropagation);
	}else if(objet.attachEvent){
		objet.attachEvent('on' + typeEvent, nomFunction);
	}
}

function trim(myString){
		return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
} 

ajouteEvent(window, "load", function(){isload();},false);


function isload(){
	var annoncedef=document.getElementById('AnnonceDefilante');
	annoncedef.innerHTML=trim(annoncedef.innerHTML)+trim(annoncedef.innerHTML);
	setInterval(function(){		
		if(!pause) DefileBloc('AnnonceDefilante', 10);
	},4000);
}


/**/
var pause=false;
function Poz(bool, obj){
	pause=!pause;
	if(pause)obj.value="PLAY";
	else obj.value="STOP";
}
/**/



blocDefilant=new Array();
var blocDefilantTps;

function DefileBloc(idbloc, vitesse){
	
	nbannonceslargeur=3;
	nbannoncesdefile=1;
	if(typeof(blocDefilant[idbloc])=="undefined"){
		blocDefilant[idbloc]=new Array();
		blocDefilant[idbloc]["but"]=0;
		blocDefilant[idbloc]["vitesse"]=0;
	}
	largeurparent=document.getElementById(idbloc).clientWidth;
	scrollvalue=document.getElementById(idbloc).scrollLeft;
	largeurbloc=document.getElementById(idbloc).scrollWidth;
	if(blocDefilant[idbloc]["vitesse"]!=vitesse){
		clearInterval(blocDefilantTps);
		blocDefilant[idbloc]["but"]=blocDefilant[idbloc]["but"]+((largeurparent/nbannonceslargeur*nbannoncesdefile)*vitesse/Math.abs(vitesse));
	
		blocDefilant[idbloc]["vitesse"]=vitesse;
		
				
		if(blocDefilant[idbloc]["but"]<0){
			blocDefilant[idbloc]["but"]=0;
		}
		if(blocDefilant[idbloc]["but"]>largeurbloc/2){
			blocDefilant[idbloc]["but"]=((largeurparent/nbannonceslargeur*nbannoncesdefile)*vitesse/Math.abs(vitesse));
			document.getElementById(idbloc).scrollLeft=0;
			scrollvalue=0;
		}

		blocDefilantTps=setInterval(function(){DefileBloc(idbloc, blocDefilant[idbloc]["vitesse"]);}, 20);
	}
	
	if(blocDefilant[idbloc]["but"]==scrollvalue){
		blocDefilant[idbloc]["vitesse"]=0;
		clearInterval(blocDefilantTps);
	}
	
	if((blocDefilant[idbloc]["vitesse"]>0 && scrollvalue+blocDefilant[idbloc]["vitesse"]>blocDefilant[idbloc]["but"]) || (blocDefilant[idbloc]["vitesse"]<0 && scrollvalue+blocDefilant[idbloc]["vitesse"]<blocDefilant[idbloc]["but"])){
		document.getElementById(idbloc).scrollLeft=blocDefilant[idbloc]["but"];
	}else{
		document.getElementById(idbloc).scrollLeft=scrollvalue+blocDefilant[idbloc]["vitesse"];
	}
}
