var isIe4=false, isDom=false, isMac=false, isWin=false, isNs=false, isNs4=false, isFlash=-1, isLoaded=false, isIe=false, isIe50=false;
var gNewsTitle = "", i=0, itemCount=0, newsXML="",xmlHttp;
var rNum=Math.floor(Math.random()*100000);
newsXML="/news.xml?"+rNum;

function showMe(divID)
{
	if (isLoaded) document.getElementById(divID).style.visibility='visible';
}
function hideMe(divID)
{
	if (isLoaded) document.getElementById(divID).style.visibility='hidden';
}
function writeMe(divID,divText)
{
	if (isLoaded)
	{
		document.getElementById(divID).innerHTML=divText;
	}
	if (isNs4)
	{
		document.layers[divID].document.open()
		document.layers[divID].document.write(divtext)
		document.layers[divID].document.close()
	}
}
function positionMe(divID,l,t)
{
	if (isLoaded)
	{
		document.getElementById(divID).style.display="block";
		document.getElementById(divID).style.position="absolute";
		document.getElementById(divID).style.top=t+"px";
		document.getElementById(divID).style.left=l+"px";
	}
}

function init()
{
	if (isDom)
	{
		isLoaded=true;
		loadXMLDoc(newsXML);
		numArray=new Array();
		firstPass=true;
	}
}

function loadXMLDoc(url) 
{
	xmlHttp=null;
	// code for Mozilla, Safari...
	if (window.XMLHttpRequest)
	{
  		xmlHttp=new XMLHttpRequest();
  	}
	// code for IE....
	else if (window.ActiveXObject)
  	{
  		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
  	}
	if (xmlHttp!=null)
  	{
  		xmlHttp.onreadystatechange=onResponse;
  		xmlHttp.open("GET",url,true);
  		xmlHttp.send(null);
  	}
	else
  	{
  		//alert("Your browser does not support XMLHTTP.")
  		document.getElementById("newsTicker").style.visibility="hidden";
  	}
}

function checkReadyState(obj)
{
  if(obj.readyState == 4)
  {
    if(obj.status == 200)
    {
      return true;
    }
    else
    {
      //alert("Problem retrieving XML data");
		document.getElementById("newsTicker").style.visibility="hidden";
    }
  }
}

function onResponse() 
{
	if(checkReadyState(xmlHttp))
  	{
  		var response = xmlHttp.responseXML.documentElement;
  		xmlStart=response.getElementsByTagName("item");
  		itemMax=xmlStart.length;
  		
		if(firstPass)
		{
			resetNumArray();
			firstPass=false;
		}
		if(numArray.length>0)
		{
			rNum=Math.floor(Math.random()*(numArray.length));
			itemCount=(numArray[rNum]);
			numArray.splice(rNum,1);
		}
		else
		{
			resetNumArray();
		}		
		gTxt=xmlStart[itemCount].getElementsByTagName("title");
  		gLink=xmlStart[itemCount].getElementsByTagName("link");		
		showNews();
	}
}

function resetNumArray()
{
	for (k=0;k<itemMax;k++)
	{
		numArray.splice(k,0,k);
	}
}

function showNews()
{
	linkTxt = gTxt[0].firstChild.data;
  	linkRef = gLink[0].firstChild.data;	
	newsTicker();
	window.setTimeout("onResponse()",9000);
}

function newsTicker()
{
	i+=1;
	document.getElementById('theTicker').innerHTML=linkTxt.substring(0,i);
  	document.getElementById('theTicker').href=linkRef;
	if(i<linkTxt.length)
	{
		window.setTimeout("newsTicker()",40);
	}
	else
	{
		i=0;
	}
}

isMac=(navigator.platform=="MacPPC")? true:false;
isWin=(navigator.appVersion.indexOf("Win")!=-1)? true:false;
isIe=(navigator.appName=="Microsoft Internet Explorer")? true:false;
isIe4=(document.all)? true:false;
isDom=(document.getElementById)? true:false;
if ((parseInt(navigator.appVersion)==4) && (navigator.appName=="Netscape"))
{
	isNs4 = true;
	isImg = true;
}
window.onload=init;