
	
	// Edit these Variables
	var tickerPause = 2500;
	var tickerSpeed = 20;
				
	// Don't edit these ones!
	var menuTop = 0;
	var isPaused = false;
	var isInit = false
	
	function doTicker() {
		// Set up our objects
		var navRootContainer = document.getElementById("newsTickerContainer");
		var navRoot = document.getElementById("newsTicker");
		var finalNode = document.getElementById("finalNode");
		
		if (!isInit)
		{
			prepareTicker(navRoot,navRootContainer);
		}

		// If the menu is at the end, move it back to the top of the page
		// The 70 value is the height of the finalnode element
		if (findPosY(navRootContainer) == (findPosY(finalNode) + 55)) {
			menuTop = 1;
		}

		// If the ticker isn't paused, scroll it
		if (!isPaused == true) {
			navRoot.style.top = menuTop + 'px';
			menuTop--;
		}
				
		// Check to see if theres a node / item at the top of the newsTicker
		// If there is, pause it!
		if (checkNodeAtTop(navRoot,navRootContainer) == true) {
			pauseTicker(tickerPause);
		}
			
		// Set up to repeat!
		setTimeout(doTicker,tickerSpeed);
	}

	function prepareTicker(navRoot,navRootContainer) {
		// Copy all list items after 'finalnode' to keep the newsticker looking smooth
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];

			if (node.nodeName=="LI") {
				if (node.id == "finalNode") {
					isInit = true;
					return;
				}
				var newli = navRoot.appendChild(document.createElement("li"));
				newli.innerHTML = node.innerHTML;
			}
		}
		return;
	}

	function pauseTicker(lengthoftime) {
		isPaused = true;

		// If we don't pass in a length, just pause it indefinately
		if (lengthoftime != 0) {
			setTimeout(unpauseTicker,lengthoftime);
		}
	}

	function unpauseTicker() {
		isPaused = false;
	}

	function checkNodeAtTop(navRoot,navRootContainer) {
		// Cycle through each node in the newsticker unordered list. If its at the top
		// of the newsTicker, return that information to the script
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];

			if (node.nodeName=="LI") {
				//alert("node: " + findPosY(node) + "\nnavRoot: " + findPosY(navRootContainer));
				if (findPosY(node) == findPosY(navRootContainer)) {
					if (isPaused == false) {
						return true;
					}
				}
			}
		}
		return false;
	}

	// Script taken from a site which I've forgotten the source of.
	// returns the position of the object you pass in
	// Found it! http://www.quirksmode.org/js/findpos.html
	function findPosY(obj) {
		var curtop = 0;

		if (obj.offsetParent) {
			while (obj.offsetParent) {
				curtop += obj.offsetTop;
				obj = obj.offsetParent;
			}
		} else if (obj.y) {
			curtop += obj.y;
		}
		
		return curtop;
	}
