var ticker =
{
	_letterSpeed: 50,
	_timeoutSpeed: 3000,
	//_cibles: $A(),
	
	init: function(letterSpeed, timeoutSpeed, cibles)
	{
		this._letterSpeed = letterSpeed;
		this._timeoutSpeed = timeoutSpeed;
		this._cibles = cibles;
		
		this._cibles.each(function(cible)
		{
			if(navigator.appName == "Netscape")
			{
				$('tickercontent' + cible.id).innerHTML = '<layer onclick="ticker.linkRedirect('+cible.id+');" onmouseover="ticker.onOverMouse(this);" onmouseout="ticker.onOutMouse(this);" id="ticker'+cible.id+'" style="cursor:hand;text-decoration:none;"></layer><br>';
				//document.write('<layer onclick="ticker.linkRedirect();" onmouseover="ticker.onOverMouse(this);" onmouseout="ticker.onOutMouse(this);" id="ticker'+cible.id+'" style="cursor:hand;text-decoration:none;"></layer><br>');
			}
			if(navigator.appVersion.indexOf("MSIE") != -1)
			{
				$('tickercontent' + cible.id).innerHTML = '<span onclick="ticker.linkRedirect('+ cible.id +');" onmouseover="ticker.onOverMouse(this);" onmouseout="ticker.onOutMouse(this);" id="ticker'+cible.id+'" style="cursor:hand;text-decoration:none;"></span><br>';	
				//document.write('<span onclick="ticker.linkRedirect();" onmouseover="ticker.onOverMouse(this);" onmouseout="ticker.onOutMouse(this);" id="ticker'+cible.id+'" style="cursor:hand;text-decoration:none;"></span><br>');
			}
			
			cible._started = false;
			cible.upticker = function()
			{
				if(!this._started)
					return;
				if(this.currentMessage > this.messages.length - 1)
				{
					this.currentMessage = 0;
					//setTimeout(this.upticker.bind(this), this._letterSpeed);
				}
				
				var m = this.messages[this.currentMessage];
				$('tickerUrl' + this.id).value = '/news/' + m.lien;
				$('title' + this.id).innerHTML = m.titre;
				if(m.currentPos > m.message.length)
				{
					m.currentPos = 0;
					this.currentMessage++;
					setTimeout(this.upticker.bind(this), ticker._timeoutSpeed);
				}
				else
				{
					mymessage = m.message.substring(0, m.currentPos++);
					setTimeout(this.upticker.bind(this), ticker._letterSpeed);
					$('ticker' + this.id).innerHTML = mymessage;
				}
			}
		});
	},
	
	start: function()
	{
		this._cibles.each(function(cible){cible._started = true; cible.upticker();});
	},
	
	stop: function()
	{
		this._cibles.each(function(cible){cible._started = false;});
	},
	
	
	onOverMouse: function(obj)
	{
		obj.style.textDecoration = "underline";
	},
	
	onOutMouse: function (obj)
	{
		obj.style.textDecoration = "none";
	},

	linkRedirect: function(cibleid)
	{
		window.location.href = $('tickerUrl'+cibleid).value;	
	}
};



/*
// page
var cibles = $A();

// boucle cible
var c = {id: "1", messages: $A(), currentMessage: 0};
// boucle messages
var m = {titre: "", message: "", lien: "", currentPos: 0};
c.messages.push(m);
// fin boucle messages
cibles.push(c);
// fin boucle cibles

ticker.init(50, 3000, cibles);
ticker.start();*/