//javascript ticker for games radar
//nick nettleton, www.nicknettleton.co.uk
//copyright 2001 nick nettleton, all rights reserved. 
//modification, distribution or use of this code prohibited.

//sniffer
w3c=(document.getElementById)?1:0
ie=(document.all&&!w3c)?1:0 //meaning ie4
ns=(document.layers&&!w3c)?1:0 //meaning ns4

agt=navigator.userAgent.toLowerCase()
win=(agt.indexOf('win')!=-1)?1:0
mac=(agt.indexOf('mac')!=-1)?1:0
iemac=(mac && agt.indexOf('msie'))?1:0

//information control
	ticker = {items:new Array(),addItem:addTickerItem}
	function addTickerItem(text,link){ticker.items[ticker.items.length]= {text:text,link:link}}


//dynamics
	with (ticker) {
		thisItem=0;
		thisCharacter=0;
		timer=0;
		mouseIsOver=0;
		cursor=0
		}

	function tickerOver(){ ticker.mouseIsOver=1 }
	function tickerOut(){ ticker.mouseIsOver=0 }

	function StopTicker() {
		with (ticker) {
			clearTimeout(timer);
			timer = 0;
		}
	}

	function getTickerHTML(text, link, style) {
		return "<span class=\"smallSize\"><span class=\"tickerText\">LATEST: <a href=\"" + link + "\" onmousedown=\"StopTicker(); top.location.href=link; return false;\" onmouseup=\"StopTicker(); top.location.href=link; return false;\" onmouseout=\"tickerOut(); return true;\" onmouseover=\"tickerOver(); return true;\"> <span class=\"" + style + "\">" + text + "</span></a></span></span>";
	}


	function getCursor(){
		//toggle & return
		cursor -- ; cursor *= -1
		return cursor ? "_" : ""
		}

	function writeTicker(text,link,style){
		html = getTickerHTML(text,link,style)
		obj = getObject(tickerContainerId)
		writeToObject(obj,html)
		}

	function goTicker(){
		with(ticker){

			//get content and write it
			text=items[thisItem].text.substring(0,thisCharacter) + getCursor()
			link=items[thisItem].link
			style = mouseIsOver ? "tickerTextOver" : "tickerText"
			writeTicker(text,link,style)

			//step and loop
//if(ie&&mac) thisCharacter=items[thisItem].text.length
  			thisCharacter++
			if (thisCharacter>items[thisItem].text.length + tickerHold && !mouseIsOver){
				thisItem++;
				thisCharacter=0
				}
			if (thisItem>=items.length) thisItem=0
			timer = setTimeout('goTicker()',tickerSpeed)

		}}
		
//create container

	function createTicker(){
		code=''
		if(iframeVersion){ //for ie on a mac, and can apply to anything else with speed issues
			code+=''
				+ '<iframe src=\"/inc/elements-ticker-iframe.asp\" width=\"'+tickerWidth+'\" height=\"'+tickerHeight+'\" scrolling=\"no\" frameborder=0 marginwidth=0 marginheight=0>'
				+ '</iframe>'
			}

		else if(!ns){ //not ns
			tickerContainerId="tickerDiv"
			code+=''
				+ '<div id=\"'+tickerContainerId+'\" '
				+ 'style=\"position:relative; cursor:hand; cursor:pointer; left:0px; width:'+tickerWidth+'px; height:'+tickerHeight+'\px; top:0px; clip:rect(0px '+tickerWidth+'px '+tickerHeight+'px 0px); overflow:hidden; " '
				+ 'onMouseOver=\"tickerOver(); return true;\" onMouseOut=\"tickerOut(); return true;\" onClick=\"StopTicker(); top.location.href=ticker.items[thisItem].link; return false;\">'
				+ '</div>'
			}

		else if(ns){ //ns - write a marker then create a layer over it onload
			code+=''
				+ '<a href=\"#\" onClick=\"top.location=ticker.items[thisitem].link\" onMouseover=\"tickerOver()\" onMouseout=\"tickerOut()\">'
				+ '<img name=\"tickerMarker\" src=\"'+shimLocation+'\" width=\"'+tickerWidth+'\" height=\"'+tickerHeight+'\" border=\"0\">'
				+ '</a>'
			}

		document.write(code)
		
		}

	function createTickerNS(){ //this is called onload for NS, in addition to above function
		marker=document.images['tickerMarker']
		tickerDiv=new Layer(tickerWidth)
		tickerDiv.x=marker.x;tickerDiv.y=marker.y;
		tickerDiv.visibility="show";
		tickerDiv.clip.height = tickerHeight;
		tickerContainerId = document.layers[document.layers.length-1].id
		}

//set it all in motion

	function initTicker(){
		if(ns) createTickerNS()
		if(!iframeVersion) {goTicker()} //and off...
		}

//cross-browser
	iframeVersion=(iemac&&location.href==top.location.href)?1:0

	function getObject(id){
		if (ie) return document.all(id)
		else if (ns) return document.layers[id]
		else return document.getElementById(id)
		}

	function writeToObject(obj,html){
		if(ns) { obj.document.write(html); obj.document.close() } //may need eval()
		else obj.innerHTML=html
		}