var contents = null;									// Message array to be given through startticker

var tLeft=320;                        // Position gauche du texte
var tHeight=60;                       // height (in pixels)
var fHeight=16;                       // height (in pixels)
var fontfamily = 'arial,sans-serif';  // font
var withBG=false;                     // background
var tcolour='#ffffcc';                // background colour:
var tSpeed=3;                         // scroll speed (1 = slow, 5 = fast)

var tWidth=0;
var tTop=44 - fHeight;
var choixTxt=0;
var cps=tSpeed;
var aw, mq;
var lefttime=null;
var stopped=false;

function startticker(messages){
	contents = new Array();
	today = new Date();
	for(i = 0; i < messages.length; i++) {
		after = new Date(messages[i][0]);
		before = new Date(messages[i][2]);
		if ((isNaN(after) || (today >= after)) && (isNaN(before) || (today <= before))) 
			contents[contents.length] = messages[i][1];
	}

	tWidth=document.body.clientWidth - tLeft;
	if ( tWidth<100 ) tWidth=100;
	if (document.getElementById) {
		document.getElementById('TICKER').innerHTML = '<div onmouseover="cps=0" onmouseout="cps=tSpeed" style="left:'+tLeft+'px;position:relative;width:'+tWidth+'px;height:'+tHeight+'px;overflow:hidden'+(withBG?';background-color:'+tcolour+'':'')+'"><div id="mq" style="position:absolute;left:0px;top:'+tTop+'px;font-family:'+fontfamily+';font-size:'+fHeight+'px;white-space:nowrap;"></div></div>';
		mq = document.getElementById("mq");
		mq.style.left=(tWidth-100)+"px";
		mq.innerHTML='<span id="tx">'+contents[choixTxt=0]+'</span>';
		aw = document.getElementById("tx").offsetWidth;
		lefttime=setTimeout("scrollticker()",50);
	}
}

function stopticker(){
	stopped=true;
	try {
		clearTimeout(lefttime);
	}
	catch (e) { }
}

function scrollticker(){
	if (parseInt(mq.style.left)>(-10 - aw)){
		mq.style.left =  parseInt(mq.style.left)-cps+"px" ;
	} else {
		mq.style.left =  tWidth+10+"px" ;
		choixTxt =  (choixTxt + 1) % contents.length;
		mq.innerHTML='<span id="tx">' + contents[choixTxt] + '</span>';
		aw = document.getElementById("tx").offsetWidth;
	}
	if ( stopped==false ) lefttime=setTimeout("scrollticker()",50);
}


