// WebTicker by Mioplanet
// www.mioplanet.com
// changed to work as rtl by hagai @ wsd

TICKER_SPEED = 1;
TICKER_STYLE = "font-family:Arial; font-size:12px; color:#00A8FF; font-weight: bold; ";
TICKER_PAUSED = false;
TICKER_OBJ = undefined;
TICKER_UA = "";

function ticker_start() {
	TICKER_OBJ = document.getElementById("TICKER");
	
	if ( undefined == TICKER_OBJ ) {
		return false;
	}
	
	TICKER_WIDTH = parseInt(TICKER_OBJ.style.width);
	tickerContent = TICKER_OBJ.innerHTML;
	var tickerSupported = false;
	var FFimg = "<img src=/images/ticker_space.gif width="+TICKER_WIDTH+" height=0>";
	var IEimg = "<img src=ticker_space.gif width="+TICKER_WIDTH+" height=0>";

	// Firefox
	if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) {
		TICKER_OBJ.innerHTML = "<TABLE  cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'>"+FFimg+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'>&nbsp;</SPAN>"+FFimg+"</TD></TR></TABLE>";
		tickerSupported = true;
		TICKER_UA = "FF";
	}
	// IE
	if (navigator.userAgent.indexOf("MSIE")!=-1 || navigator.userAgent.indexOf("Opera")!=-1) {
		TICKER_OBJ.innerHTML = "<DIV nowrap='nowrap' style='width:100%; overflow: visible'>"+IEimg+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'></SPAN>"+IEimg+"</DIV>";
		TICKER_UA = "IE";
		tickerSupported = true;
	}
	if(!tickerSupported) {
		TICKER_OBJ.outerHTML = "";
	} else {
		TICKER_OBJ.scrollLeft = 0;
		document.getElementById("TICKER_BODY").innerHTML = tickerContent;
		TICKER_OBJ.style.display="none";
		TICKER_tick();
	}
	
	return true;
}

function TICKER_tick() {
	if ( undefined == TICKER_OBJ ) {
		return false;
	}
	
	var delta = (TICKER_OBJ.scrollWidth - TICKER_OBJ.offsetWidth);
	var TICKER_START = 0;
	var TICKER_DONE = 0;
	
	switch (TICKER_UA) {
		case "IE":
			TICKER_START = delta;
			TICKER_DONE = document.getElementById("TICKER_BODY").offsetWidth + TICKER_OBJ.offsetWidth;
			break;
		case "FF":
			TICKER_START = 0;
			TICKER_DONE = -delta;
			break;
	}
	
	if ( "none" == TICKER_OBJ.style.display ) {
		TICKER_OBJ.style.display="block";
		TICKER_OBJ.scrollLeft = TICKER_START;
	}
	
	if(!TICKER_PAUSED) {
		TICKER_OBJ.scrollLeft += TICKER_SPEED * -1;
	}

	if(TICKER_OBJ.scrollLeft <= TICKER_DONE) {
		TICKER_OBJ.scrollLeft = TICKER_START;
	}

	window.setTimeout("TICKER_tick()", 30);
	
	return true;
}
