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, txtArray, linkArray, numArray, firstPass;
var randNum=Math.floor(Math.random()*100000);
newsXML = "/blog-feed.aspx";// + randNum;


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("feed").style.visibility="hidden";
  	}
}

function checkReadyState(obj)
{
  if(obj.readyState == 4)
  {
    if(obj.status == 200)
    {
      return true;
    }
    else
    {
      //alert("Problem retrieving XML data");
		document.getElementById("feed").style.visibility="hidden";
    }
  }
}

function onResponse() 
{
	if(checkReadyState(xmlHttp))
  	{
  		var response = xmlHttp.responseXML.documentElement;
  		xmlStart=response.getElementsByTagName("entry");//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")[4].attributes.getNamedItem("href").value;
		//alert(gLink);	
		showNews();
	}
}

function resetNumArray()
{
	for (k=0;k<itemMax;k++)
	{
		numArray.splice(k,0,k);
	}
}

function showNews()
{
	linkTxt = gTxt[0].firstChild.data;
  	linkRef = gLink;	
	newsTicker();
	window.setTimeout("onResponse()",8500);
}

function newsTicker()
{
	i+=1;
	document.getElementById('theTicker').innerHTML=linkTxt.substring(0,i);
  	document.getElementById('theTicker').href=linkRef;
	if(i<linkTxt.length)
	{
		window.setTimeout("newsTicker()",70);
	}
	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;
