/* 	Script to create a scrolling text news box. Takes teh news you give it and scrolls
those items across the screen for your users to see
Based on newsticker by www.fczbkk.sl/js/newsticker/ 
*/
// run inittck when the window loads.....
//addEvent(window, "load", inittck);
var news;
function inittck() {
	if (document.getElementById) {
		tck = document.getElementById("all");
		if (tck.getElementsByTagName("div").length > 0) {
			actual = 0; // I guess actual index of news array :)
			step = 1;  // steps to take [in px I guess] when moving
			speed = 20;  // scrolling speed - greater number=slower, smaller number=faster
			delay = 1;   // delay for news to wait 'till moving forward and let the next come into view
			
			news = new Array();
			// build an array of news - eg every seperate div provided in the div with id = "all". 
			for (i = 0; i < tck.getElementsByTagName("div").length; i++) {
				news[i] = tck.getElementsByTagName("div")[i];
				news[i].style.left = tck.offsetWidth;
			}
			// start the news rolling ....
			rollNews();
			// add listeners for when mouse goes over tck to stop and when it leaves 
			// tck to start again
			addEvent(tck, "mouseover", stopNews);
			addEvent(tck, "mouseout", rollNews);
		}
	}
}
function rollNews() {
	// move left edge to left a bit
	news[actual].style.left = parseInt(news[actual].style.left) - step + "px";
	if (parseInt(news[actual].style.left) == tck.offsetWidth % step) {
		// if that movement hasnt taken us off the edge of the div then wait
		// a bit and move it again.
		tick = setTimeout("rollNews()",delay);
	}
	else {
		// if it has taken us over the edge then move to the next item in news array
		if (parseInt(news[actual].style.left) <= 0-news[actual].offsetWidth) {
			actual++;
			// if at end of array then knock it back to start
			if (actual == news.length) {actual = 0;}
			news[actual].style.left = tck.offsetWidth;
		}
		// wait a bit and try again.
		tick = setTimeout("rollNews()",speed);
	}
}
function stopNews() {
	clearTimeout(tick);
}
function addEvent(obj, evType, fn){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
  } else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
	return false;
  }
}
