var timoutID = "";
var spotCount = 0;
var hex = 255;

function GetXmlHttpObject(){
var xmlHttp=null;
	// Firefox, Opera 8.0+, Safari  
try{xmlHttp=new XMLHttpRequest();}
 	catch (e){ 
  // Internet Explorer
try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
  catch (e){
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
}
return xmlHttp;
}

// Pings the backend object and calls the display function.
function pingSpotlight(){
	xmlHttp=GetXmlHttpObject();
	var url="/_includes/init/pingSpotlight.cfm";
	url=url+"?sid="+Math.random();	
	xmlHttp.onreadystatechange=displaySpotlight;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	//timoutID = setTimeout(pingSpotlight, 2000);
}


function displaySpotlight() { 
	if (xmlHttp.readyState==4){
			var xmlDoc=xmlHttp.responseXML.documentElement;
			divSet = document.getElementById('spotlightNews');
			totalSpot = xmlDoc.getElementsByTagName("spotlight_count")[0].childNodes[0].nodeValue;
			if(divSet.innerHTML.length != 0){
				hex = 0;
				fadeOut(spotCount);
			}else{
				divSet.innerHTML = '';
				//divSet.innerHTML = divSet.innerHTML + xmlDoc.getElementsByTagName("release_dt")[spotCount].childNodes[0].nodeValue + '<br />';
				//divSet.innerHTML = divSet.innerHTML + '<a href="' + 'news/index.cfm?mode=detail_' + xmlDoc.getElementsByTagName("content_type")[spotCount].childNodes[0].nodeValue + '&' + xmlDoc.getElementsByTagName("content_type")[spotCount].childNodes[0].nodeValue + '=' + xmlDoc.getElementsByTagName("spotlight_uuid")[spotCount].childNodes[0].nodeValue + '"><strong>' + xmlDoc.getElementsByTagName("headline")[spotCount].childNodes[0].nodeValue  + '</strong>' + '</a><br />' + xmlDoc.getElementsByTagName("summary")[spotCount].childNodes[0].nodeValue + '<br />';
		divSet.innerHTML = divSet.innerHTML + '<a href="' + 'news/index.cfm?mode=detail_' + xmlDoc.getElementsByTagName("content_type")[spotCount].childNodes[0].nodeValue + '&' + xmlDoc.getElementsByTagName("content_type")[spotCount].childNodes[0].nodeValue + '=' + xmlDoc.getElementsByTagName("spotlight_uuid")[spotCount].childNodes[0].nodeValue + '"><strong>' + xmlDoc.getElementsByTagName("headline")[spotCount].childNodes[0].nodeValue  + '</strong></a>' + '<br />';

		if (xmlDoc.getElementsByTagName("summary")[spotCount].childNodes[0]) {
		    divSet.innerHTML = divSet.innerHTML + xmlDoc.getElementsByTagName("summary")[spotCount].childNodes[0].nodeValue + '<br />';
		}


				thisLink = document.getElementById('moreLink');
				thisLink.href = 'news/index.cfm?mode=detail_' + xmlDoc.getElementsByTagName("content_type")[spotCount].childNodes[0].nodeValue + '&' + xmlDoc.getElementsByTagName("content_type")[spotCount].childNodes[0].nodeValue + '=' + xmlDoc.getElementsByTagName("spotlight_uuid")[spotCount].childNodes[0].nodeValue;
				fadeIn();
			}
			if(spotCount != (totalSpot) - 1){
				spotCount = spotCount + 1;
				
			}else{
				spotCount = 0;
			}
			timoutID = setTimeout(displaySpotlight, 7000);
	}
}

function fadeIn(){
	if(hex>0) {
   	hex-=11;
    divSet.style.color="rgb("+hex+","+hex+","+hex+")";
		setTimeout("fadeIn()",20); 
  }else{
    hex=255;
	}
}

function fadeOut(nextSpot){
	if(hex<255){
    hex+=11;
		divSet.style.color="rgb("+hex+","+hex+","+hex+")";
		setTimeout("fadeOut("+nextSpot+")",20); 
  }else{
		xmlDoc=xmlHttp.responseXML.documentElement;
		divSet.innerHTML = '';
		//divSet.innerHTML = divSet.innerHTML + xmlDoc.getElementsByTagName("release_dt")[nextSpot].childNodes[0].nodeValue + '<br />';
		divSet.innerHTML = divSet.innerHTML + '<a href="' + 'news/index.cfm?mode=detail_' + xmlDoc.getElementsByTagName("content_type")[nextSpot].childNodes[0].nodeValue + '&' + xmlDoc.getElementsByTagName("content_type")[nextSpot].childNodes[0].nodeValue + '=' + xmlDoc.getElementsByTagName("spotlight_uuid")[nextSpot].childNodes[0].nodeValue + '"><strong>' + xmlDoc.getElementsByTagName("headline")[nextSpot].childNodes[0].nodeValue  + '</strong></a>' + '<br />';
		if (xmlDoc.getElementsByTagName("summary")[nextSpot].childNodes[0]) {
		    divSet.innerHTML = divSet.innerHTML + xmlDoc.getElementsByTagName("summary")[nextSpot].childNodes[0].nodeValue + '<br />';
		}

		//		divSet.innerHTML = divSet.innerHTML + xmlDoc.getElementsByTagName("summary")[nextSpot].childNodes[0].nodeValue + '<br />';
		thisLink = document.getElementById('moreLink');
		thisLink.href = 'news/index.cfm?mode=detail_' + xmlDoc.getElementsByTagName("content_type")[nextSpot].childNodes[0].nodeValue + '&' + xmlDoc.getElementsByTagName("content_type")[nextSpot].childNodes[0].nodeValue + '=' + xmlDoc.getElementsByTagName("spotlight_uuid")[nextSpot].childNodes[0].nodeValue;
		fadeIn();
	}
}

