// global variables
var marqueecontent=(isSet(marqueecontent))?marqueecontent:'Variable "marqueecontent" du bandeau non déclarée | ';
var copyspeed=(isSet(copyspeed))?copyspeed:5; // <-- speed of ticker
var tickerWidth = (isSet(tickerWidth))?tickerWidth:557; // <-- ticker width
var tickerHeight = (isSet(tickerHeight))?tickerHeight:17; // <-- ticker height

var actualWidth='';
var jsMarquee1;
var jsMarquee2;
var div1Interval = 0;
var div2Interval = 0;
var timeToStartSecond= new Array(8)
var div1Status = 0;
var div2Status = 0;

document.write('<span id="temp" style="visibility:hidden;position:absolute;left:-5000px;">'+marqueecontent+'</span>'); // used to determine initial content width
document.write('<span id="temp2" style="visibility:hidden;position:absolute;left:-5000px;"></span>'); // used later to calculate the new width of the content

function populate(){
	actualWidth=document.getElementById("temp").offsetWidth;
	actualWidthTemp=document.getElementById("temp").offsetWidth;

	// first DIV
	jsMarquee1=document.getElementById('marquee1');
	jsMarquee1.style.left=parseInt(tickerWidth)+"px";	
	
	// second DIV
	jsMarquee2=document.getElementById('marquee2');
	jsMarquee2.style.left=parseInt(tickerWidth)+"px";	
	
	if(actualWidth <= (tickerWidth*2)){

		var tempContent;
		tempContent = "<nobr>";
		
		// make sure that the div is larger than the ticker area
		// if not, duplicate the content
		while (actualWidth < (tickerWidth*2)){
			tempContent = tempContent + marqueecontent;
			actualWidth = actualWidth + actualWidthTemp;
		}
		tempContent = tempContent + "</nobr>"
		
		// load the content into the divs
		jsMarquee1.innerHTML=tempContent;
		jsMarquee2.innerHTML=tempContent;


		// get the new actual width of the content
		document.getElementById("temp2").innerHTML=tempContent;
		actualWidth = document.getElementById("temp2").offsetWidth;

	}else{
		// load the content into the divs
		jsMarquee1.innerHTML="<nobr>"+marqueecontent+"</nobr>";
		jsMarquee2.innerHTML="<nobr>"+marqueecontent+"</nobr>";	
	}

	
		timeToStartSecond=(tickerWidth-actualWidth);
		startMarquee();
	
}
if (marqueecontent != '') {
window.onload=populate
}


function scrollMarquee(){
	if ((parseInt(jsMarquee1.style.left)>(actualWidth*(-1)))){
		jsMarquee1.style.left=parseInt(jsMarquee1.style.left)-copyspeed+"px";

		// call function to begin the second DIV
		if(parseInt(jsMarquee1.style.left) < timeToStartSecond && div1Status == 0){
			div1Status = 1;
			div2Status = 0;
			beginSecondMarquee();
		}
	}else{
		//resets the div to it's original location
		document.getElementById("marquee1").style.left = parseInt(tickerWidth)+"px";	
		//clear the interval and stop animation
		div1Interval = window.clearInterval(div1Interval);		
	}
}

function scrollSecondMarquee(){
	if (parseInt(jsMarquee2.style.left)>(actualWidth*(-1))){
		jsMarquee2.style.left=parseInt(jsMarquee2.style.left)-copyspeed+"px";

		// call function to restart the first DIV
		if(parseInt(jsMarquee2.style.left) < timeToStartSecond && div2Status == 0){
			div1Status = 0;
			div2Status = 1;
			startMarquee();
		}
	}else{
		//resets the div to it's original location
		document.getElementById("marquee2").style.left = parseInt(tickerWidth)+"px";	
		//clear the interval and stop animation
		div2Interval = window.clearInterval(div2Interval);
	}
}

/* begins the second marquee */
function beginSecondMarquee(){
	div2Interval = window.setInterval("scrollSecondMarquee()",20);
}

/* begins the first marquee */
function startMarquee(){
	div1Interval = window.setInterval("scrollMarquee()",20);
}

/**
 * Test l'existence d'une variable
 * @param variable La variable a tester.
 * @return true si la variable existe.
 */
function isSet(variable)
{
	return( typeof(variable) != 'undefined' );
}
