var scrollerIncAmount = 3;
var scrollerIncDelay = 100;
var scrollers = Array();

function initscroller(scrollerID) {
	var iMaxReps = 10;
	scrollers[scrollerID] = Array()

	scr = document.getElementById(scrollerID+'_content');
	try {
		if (scr) {
			if (scr.style.left == '') {scr.style.left = '0px';}
			scrollers[scrollerID]['left'] = scr.style.left.replace('px', '');
			scrollers[scrollerID]['width'] = (scr.offsetWidth);
			scrollers[scrollerID]['containerwidth'] = (document.getElementById(scrollerID+'_container').offsetWidth);

			oContent = document.getElementById(scrollerID+'_content')
			s = oContent.style.position;
			oContent.style.position = 'absolute';
			scrollers[scrollerID]['contentwidth'] = (oContent.offsetWidth);
			oContent.style.position = s;

			scrollers[scrollerID]['tick'] = true;

			ctsIn = scr.innerHTML;
			ctsOut = ctsIn;
			if (ctsIn.length>0) {
				iReps =  Math.ceil(scrollers[scrollerID]['containerwidth'] / scrollers[scrollerID]['width']);
				if (iReps > iMaxReps) {iReps = iMaxReps;}
				ctsOut += ctsIn;
				for (i=1; i<iReps; i++) {ctsOut += ctsIn;}
				scr.innerHTML = ctsOut;

				scrollerTicker(scrollerID);
			}
		}
	}catch (e) {
		//alert("Debug: Javascript Error - initScroller('"+scrollerID+"')\n\r" + e.name + ":\n\r" + e.message);
	}
}
function scrollerTicker(scrollerID) {
	var l = scrollers[scrollerID]['left'];           // Left: setting in CSS, except this has no 'px' appendage
	var w = scrollers[scrollerID]['width'];          //
	var c = scrollers[scrollerID]['containerwidth']; // Measured width of content text.
	var t = scrollers[scrollerID]['contentwidth']; // Measured width of content text.

	try {
	  scr = document.getElementById(scrollerID+'_content');
	  if (scr) {
	  	if (scrollers[scrollerID]['tick']) { // is Scroller Enabled
		  	if ((l-scrollerIncAmount) < -t) {
		  		scr.style.left = '0px';
	  			scrollers[scrollerID]['left'] = 0;

	  		}else{
	  			scr.style.left = (l - scrollerIncAmount) + 'px';
	  			scrollers[scrollerID]['left'] = (l - scrollerIncAmount)
	  		}
			}
	  	setTimeout('scrollerTicker(\''+scrollerID+'\');', scrollerIncDelay);
	  }
  } catch (e) {
		//alert("Debug: Javascript Error - scrollerTicker('"+scrollerID+"')\n\r" + e.name + ":\n\r" + e.message);
  }
}

function scrollerStop(scrollerID)  {
	try {
		scrollers[scrollerID]['tick'] = false;
		scrollerButtonMode(scrollerID, false)
	} catch (e) {
		//alert("Debug: Javascript Error - scrollerStop('"+scrollerID+"')\n\r" + e.name + ":\n\r" + e.message);
  }
}
function scrollerStart(scrollerID) {
	try {
		scrollers[scrollerID]['tick'] = true;
		scrollerButtonMode(scrollerID, true)
	} catch (e) {
		//alert("Debug: Javascript Error - scrollerStart('"+scrollerID+"')\n\r" + e.name + ":\n\r" + e.message);
  }
}

function scrollerButtonMode(scrollerID, bButtonMode) { // True = Say "Pause", False = Say "Resume"
	try {
		btn = document.getElementById(scrollerID+'button_toggle');
		if (btn) {
			if (bButtonMode) {btn.value = "Pause"}else{btn.value = "Resume";}
		}
	} catch (e) {
		//alert("Debug: Javascript Error - scrollerButtonMode('"+scrollerID+"', "+bButtonMode+")\n\r" + e.name + ":\n\r" + e.message);
	}
}

function scrollerToggle(scrollerID) {
	var bMode = true;
	try {
		bMode = scrollers[scrollerID]['tick'];
		scrollers[scrollerID]['tick'] = !bMode;
		scrollerButtonMode(scrollerID, !bMode);

		btn = document.getElementById(scrollerID+'_button_toggle');
	} catch (e) {
		//alert("Debug: Javascript Error - scrollerToggle('"+scrollerID+"')\n\r" + e.name + ":\n\r" + e.message);
  }
}