/*
	Auteur : Allani Karim
	Créé le : 1 juillet 2010
	www.kinformatique.ch
	Ce script a besoin de jQuery pour fonctionner
	Il permets de transformer tous les span contenu dans un div de classe "defiler" en un objet qui défile le long du div de droite à gauche.
*/


function kiTexteDeffilant(prmTexte, largeurDiv)
{  
	this.texte = prmTexte;
	this.largeur = this.texte.width();
	this.position = largeurDiv - this.largeur;
	
	this.getPosition = function()  
	{  
		return(this.position);
	}
	
	this.getLargeur = function()  
	{
		this.largeur = this.texte.width();
		return(this.largeur);
	}
	
	this.setPosition = function(newPosition)
	{
		this.position = newPosition;
	}
	
	this.raffrechir = function()  
	{ 
		this.texte.animate({"left": this.position}, 1);
	}
	
}  

function kiBlocDeffilant(prmBloc)
{  
	this.bloc = prmBloc;
	this.position = this.bloc.offset().left;
	this.largeur = this.bloc.width();
	this.texte = new kiTexteDeffilant(this.bloc.find("span"), this.largeur);
	this.avancer = 1;
	
	this.pause = function(pause)
	{
		if (pause)
			{this.avancer = 0;}
		else
			{this.avancer = 1;}
	}
	
	this.defiler = function()
	{
		this.position = this.bloc.offset().left;
		this.largeur = this.bloc.width();
		
		
		if (this.texte.getPosition() > this.largeur)
			{this.texte.setPosition(this.largeur);}
		
		this.texte.setPosition((this.texte.getPosition() - this.avancer));
		
		if ((this.texte.getPosition()+this.texte.getLargeur()) <= 0)
			{this.texte.setPosition(this.largeur);}
		
		this.texte.raffrechir();
			
	}
}

$(function(){
	listeDiv = new Array();
	$('.defiler').each(function(i)
	{
		listeDiv[i] = new kiBlocDeffilant($(this));
		setInterval('listeDiv['+ i +'].defiler();', 25);
		
		$(this).find("span").mouseover(function(){
		  listeDiv[i].pause(true);
		});

		$(this).find("span").mouseout(function(){
		  listeDiv[i].pause(false);
		});
	});

});