var feedHeight;
var divHeight = 115;
var divWidth = 160;
var divContainerPaddingTop = 6;
var divContainerPaddingBottom = 0;
var divContainerPaddingRight = 8;
var divContainerPaddingLeft = 8;
var feedPause = 10000;
var feedSpeed = 10; //lower = faster, 0 is the fastest

if(navigator.appName == "Microsoft Internet Explorer"){ feedSpeed = 10; }

var xmlhttp;
var url = "xml/pressTrimmed.php";

function loadXMLDoc()
{
	xmlhttp = null;
	if (window.XMLHttpRequest) // code for IE7, Firefox, Opera, etc.
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) // code for IE6, IE5
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null)
	{
		xmlhttp.onreadystatechange = state_Change;
		xmlhttp.open("GET", url, true);
		xmlhttp.send(null);
	}
	else
	{
		alert("Your browser does not support XMLHTTP.");
	}
}

function state_Change()
{
	if (xmlhttp.readyState == 4) //4 = "loaded"
	{
		if (xmlhttp.status == 200) //200 = "OK"
		{
			try //Internet Explorer
			{
				xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.loadXML(xmlhttp.responseText);
			}
			catch(e)
			{
				try //Firefox, Mozilla, Opera, etc.
				{
					parser = new DOMParser();
					xmlDoc = parser.parseFromString(xmlhttp.responseText,"text/xml");
				}
				catch(e)
				{
					alert(e.message);
					return;
				}
			}
			xmlDoc.async = false;

			//document.getElementById("div_rssTitle").innerHTML += "<a href=\"" + xmlDoc.getElementsByTagName("link")[0].childNodes[0].nodeValue + "\">" + xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue + " <img alt=\"\" src=\"rss/rss.png\" align=\"middle\" border=\"0\" /></a>";

			var rssItem = xmlDoc.getElementsByTagName("item");

			for(i = 0; i < rssItem.length; i++)
			{
				document.getElementById("div_rssItems").innerHTML += "<div class=\"rssA\" id=\"div_container\" style=\"width:" + (divWidth - (divContainerPaddingLeft * 2)) + "px; height:" + divHeight + "px; padding:" + divContainerPaddingTop + "px " + divContainerPaddingRight + "px " + divContainerPaddingBottom + "px " + divContainerPaddingLeft + "px; overflow:hidden;\" align=\"left\"><a href=\"" + rssItem[i].getElementsByTagName("link")[0].childNodes[0].nodeValue + "\"><b>" + rssItem[i].getElementsByTagName("title")[0].childNodes[0].nodeValue + "</a></b><br /><font style=\"color:#000000; font-size:8pt;\">" + rssItem[i].getElementsByTagName("description")[0].childNodes[0].nodeValue + "</font></div>";
			}

			feedHeight = rssItem.length;
			scroller();
		}
		else
		{
			alert("Problem retrieving XML data:" + xmlhttp.statusText);
		}
	}
}

var rssTimer;
var locationCounter = 1;
var locationCounter2 = divContainerPaddingTop * 2;
var newLocation = 0;
var feedMaxHeight = 0;

function scroller()
{
	clearTimeout(rssTimer);
	rssTimer = setTimeout("scroller()", feedSpeed);
	feedMaxHeight = ((-divHeight * (feedHeight)) + 1) - (divHeight / 2);

	//alert(parseInt(document.getElementById("div_rssItems").style.top));

	if(parseInt(document.getElementById("div_rssItems").style.top) < feedMaxHeight){ document.getElementById("div_rssItems").style.top = divHeight + "px"; }

	//for(i = 0; i > feedMaxHeight; i--)
	//{
		//newLocation = -divHeight * locationCounter;
		//if(navigator.appName != "Microsoft Internet Explorer"){ newLocation = ((-divHeight * locationCounter) - locationCounter2); }
		newLocation = ((-divHeight * locationCounter) - locationCounter2);
		//alert(newLocation);
		if((parseInt(document.getElementById("div_rssItems").style.top) == newLocation || parseInt(document.getElementById("div_rssItems").style.top) == 0) && (parseInt(document.getElementById("div_rssItems").style.top) != feedMaxHeight && parseInt(document.getElementById("div_rssItems").style.top) >= feedMaxHeight + (divHeight / 2)))
		{
			clearTimeout(rssTimer);
			rssTimer = setTimeout("scroller()", feedPause);
			if(parseInt(document.getElementById("div_rssItems").style.top) != 0)
			{
				locationCounter++;
				locationCounter2 = (locationCounter2 + divContainerPaddingTop);
				//alert(parseInt(document.getElementById("div_rssItems").style.top) + " - " + newLocation + " " + " - " + feedMaxHeight + " - " + (feedMaxHeight + (divHeight / 2)));
			}
			else{ locationCounter = 1; locationCounter2 = divContainerPaddingTop; }
		}
	//}
	document.getElementById("div_rssItems").style.top = (parseInt(document.getElementById("div_rssItems").style.top) - 1) + "px";
}
