
	function Headline() {
		this.id = 0;
		this.headline = "<Enter Headline Here>";		
		this.headlineURL = "";
		this.secondsToDisplay = 5;
	}

	function Headline(x) {
		if (x != null) {
		    this.id = x.getElementsByTagName("id")[0].firstChild.data;
		    this.headline = x.getElementsByTagName("headline")[0].firstChild.data;				
		    if (x.getElementsByTagName("url")[0].hasChildNodes())
		    {
			    this.headlineURL = x.getElementsByTagName("url")[0].firstChild.data;
		    }
		    else
		    {
			    this.headlineURL = "";
		    }	
		    this.secondsToDisplay = parseInt(x.getElementsByTagName("secondsToDisplay")[0].firstChild.data);
		} else {
		    this.id = 0;
			this.headline = "No current news to display.  Please check back later.";
			this.headlineURL = "";
			this.secondsToDisplay = 5;
	    }
	}

	Headline.prototype.toString = function (){
				
		var ret = "";
		var styling = "";

		if (this.headlineURL != "")
		{
		    if (this.headlineURL.substr(0,4) != "http" && this.headlineURL.substr(0,5) != "https") {
		        this.headlineURL = "http://" + this.headlineURL;
		    }
			ret += "<a href='" + this.headlineURL + "' target='_blank'>";
		}
		
		// Set up styling -- uncomment to apply styling
		//styling = "font-family: " + this.font + "; font-size: " + this.fontSize + "px; ";
		
		//if (this.headlineURL == "")
		//{
		//	styling += "color: " + this.fontColor + "; ";
		//	if (this.bold)
		//	{
		//		styling += "font-weight: bold; ";
		//	}
		//	
		//	if (this.italic)
		//	{
		//		styling += "font-style: italic; ";
		//	}
		//	
		//	if (this.underline)
		//	{				
		//		styling += "text-decoration: underline; ";
		//	}
		//}
		
		
		//ret += "<span style='" + styling + "'>" + this.headline + "</span>";
		ret += this.headline;
		//styling = "";
		if (this.headlineURL != "")
		{
			ret += "</a>";
		}

		return ret;

	}

	function GetHeadlineServiceURL() {		
		if (location.hostname == "localhost") {		    
		    return "http://" + location.hostname + ":" + location.port + "/Bi Energy Group";
		}
		else {
		    return "http://" + location.hostname;
		}
	}

	function GetHeadline(id) 
	{	
		var url = GetHeadlineServiceURL();
		url += "/PTXService.asmx/GetHeadline"
		xmlhttp.onreadystatechange = state_Change;
		xmlhttp.open("POST", url, false);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");		
		xmlhttp.send("id=" + id);
	} 

	function getAllHeadlines() 
	{		
		//alert("http://www.pelletex.com/PTXService.asmx/GetAllHeadlines");
		xmlhttp.onreadystatechange = onResponse;
		//alert("open");
		xmlhttp.open("POST", GetHeadlineServiceURL()  + "/PTXService.asmx/GetAllHeadlines");
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	
		//xmlhttp.setRequestHeader("Content-Length", "0");
		//alert("send");
		xmlhttp.send("dummydata");
	}

	function checkReadyState()
	{
		document.getElementById("headline").innerText = "Loading news...";

		// if xmlhttp shows "loaded"
		if (xmlhttp.readyState == 4)
		{
			if (xmlhttp.status == 200)
			{
				return true;
			}
			else
			{
				//alert(xmlhttp.status);
				//document.getElementById("headline").innerHTML = xmlhttp.responseText;
				alert("WE'VE GOT PROBLEMS!");
			}
		}		
	}	

	function onResponse()
	{
		//alert("onResponse");
		if (checkReadyState())
		{
			var response = xmlhttp.responseXML.documentElement;
			x = response.getElementsByTagName("Headline");
			allHeadlines = new Array(x.length);

			if (allHeadlines.length == 0)
			{
				allHeadlines = new Array(1);
				allHeadlines[0] = new Headline();
			}
			else {
				for (i = 0; i < x.length; i++)
				{				
					//document.write(x[i].getElementsByTagName("id")[0].firstChild.data + "<br>");
					allHeadlines[i] = new Headline(x[i]);
				}	
			}	
			
			rotateHeadlines();
		}
	}

	//function goToFullyQualifiedURL() {
	//	if (location.href.indexOf("exfactory.com") == -1)
	//	{
	//		location.href = "http://xf.exfactory.com";
	//	}
	//}

	function rotateHeadlines() {
		document.getElementById("headline").innerHTML = allHeadlines[idx].toString();
		var time = allHeadlines[idx].secondsToDisplay * 1000;

		//alert(time);

		idx++;
		if (idx >= allHeadlines.length)
		{
			idx = 0;
		}

		setTimeout("rotateHeadlines()", time);
	}

	function pauseMarquee() {
		document.getElementById('headlineMarquee').scrollAmount = 0;

		var time = allHeadlines[idx].secondsToDisplay * 1000;

		//alert(time);

		idx++;
		if (idx >= allHeadlines.length)
		{
			idx = 0;
		}

		setTimeout("pauseMarqueePart2()", time);		
	}

	function pauseMarqueePart2() {
		document.getElementById('headlineMarquee').scrollAmount = 1;
		//setTimeout("pauseMarquee()", 2000);		
		if (idx == 0)
		{
			setTimeout("pauseMarquee()", 3570);
		}
		else 
		{
			setTimeout("pauseMarquee()", 3550);
		}
	}

	function rotateHeadlines2() {
		var headlineRot = "<marquee id='headlineMarquee' direction='up' scrollAmount='1' onMouseover='this.scrollAmount = 0;' onMouseout='this.scrollAmount = 1;' height='20'>";
		
		for (i = 0; i < allHeadlines.length; i++)
		{
			headlineRot += allHeadlines[i].toString();
			if (i + 1 != allHeadlines.length)
			{
				headlineRot += "<br><br>";
			}			
		}

		headlineRot += "</marquee>";

		document.getElementById("headline").innerHTML = headlineRot;
		//setTimeout("pauseMarquee()", 2000);
	}

	var xmlhttp = false;
	var allHeadlines;
	var idx = 0;

	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	} 			