(function(){
	var liste_tickers = []
	
	$.fn.ticker = function(params){
		var ticker
		params = params || {}
		ticker = $(this).LKdata('ticker_obj')
		if (ticker != undefined){
			return ticker
		}
		
		params.obj = $(this)
		$(this).LKdata('ticker_obj', new ticker_obj(params))
		return $(this)
	}
	
	var ticker_obj = function(params){
		this.obj = params.obj
		this.no = 0
		this.html = this.obj.html()
		this.dir_gauche = params.gauche || true
		this.vitesse = params.vitesse || 1.5
		this.style = "font-family:Arial; font-size:12px; color:#444444"
		this.paused = false
		this.start()
	}
	
	var tick = ticker_obj.prototype
	
	tick.start = function(){
		var this_ = this
		if (this.started){
			this.tick()
		}
		this.started = true
		var tickerSupported = false
		this.width = this.obj.width()
		
		var img = "<img src=\"./images/ticker_space.gif\" width="+ this.width +" height=0>";
		// Firefox
		if (true || $.browser.mozilla || $.browser.webkit) {
			this.obj.html("<TABLE  cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'>"+img+"<SPAN style='"+this.style+"' class='TICKER_BODY' width='100%'>&nbsp;</SPAN>"+img+"</TD></TR></TABLE>")
			tickerSupported = true;
		}
		// IE
		 else if ($.browser.msie || $.browser.opera) {
			this.obj.html("<DIV nowrap='nowrap' style='width:100%'>"+img+"<SPAN style='"+this.style+"' class='TICKER_BODY' width='100%'></SPAN>"+img+"</DIV>")
			tickerSupported = true;
			//this.scrolled_obj = this.obj.children('div:eq(0)')
		}
		if(!tickerSupported) this.obj.remove()
		else {
			this.scrolled_obj = this.obj.find('span.TICKER_BODY').css({position:'relative', left:0})
			this.obj[0].scrollLeft = (this.dir_gauche ? this.obj[0].scrollWidth - this.obj[0].offsetWidth : 0)
			$('span.TICKER_BODY', this.obj).html(this.html)
			this.obj.css('display','block');
			setTimeout(function(){
				this_.paused = false
				this_.tick();
			}, 500)
			
		}		
	}
	tick.tick = function(){
		var this_ = this, a
		if (this.timeout){
			clearTimeout(this.timeout)
			this.timeout = null
		}
		if (this.paused){
			return
		}
		var obj = this.scrolled_obj
				
		obj.css('left', this.vitesse * (this.dir_gauche ? -1 : 1) + parseInt(obj.css('left')))
		
		var pos = parseInt(obj.css('left'))
		
		if(this.dir_gauche && pos < -this.width - obj.width()){
			obj.css('left',0)
		}
		if(!this.dir_gauche && this.obj[0].scrollLeft >= this.obj[0].scrollWidth - this.obj[0].offsetWidth) 
			obj.scrollLeft = 0;
		
		this.timeout = setTimeout(function(){this_.tick()}, 30);

	}
	tick.pause = function(){
		this.paused = true
	}
	tick.stop = tick.pause
	tick.resume = function(){
		this.paused = false
		this.tick()
	}
	
	
})()



