// this javascript file contains commands for extracting data from the nowplaying.xml file

// function that creates a XMLHttpRequest or ActiveXObject depending on browser.
// it also starts the function for retrieving metadata from an XML file	
function metadata_object()
	{
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP Requests!");
	  }
	retrieve_newdata();
	 }
	 
// function for retrieving metadata from an XML file.
	
function retrieve_newdata()
	{
	try
		{
		url = "nowplaying.xml";
		url = url + "?" + new Date().getTime();
		xmlDoc=null;
		xhttp.open("GET",url,false);
		xhttp.send("");
		xmlDoc=xhttp.responseXML;
		
		// To allow fields to be read from the XML file, uncomment the relavent lines below.
		// Make sure to add the correct id to your HTML file else the javascript will error.
		
		document.getElementById("bsi_artist").innerHTML=xmlDoc.getElementsByTagName("artist")[0].childNodes[0].nodeValue;
		document.getElementById("bsi_title").innerHTML=xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
		document.getElementById("bsi_album").innerHTML=xmlDoc.getElementsByTagName("album")[0].childNodes[0].nodeValue;
		document.getElementById("bsi_year").innerHTML=xmlDoc.getElementsByTagName("year")[0].childNodes[0].nodeValue;
		document.getElementById("bsi_recent_short3").innerHTML=xmlDoc.getElementsByTagName("recent_short3")[0].childNodes[0].nodeValue;
		document.getElementById("bsi_recent_short4").innerHTML=xmlDoc.getElementsByTagName("recent_short4")[0].childNodes[0].nodeValue;
		document.getElementById("bsi_recent_short5").innerHTML=xmlDoc.getElementsByTagName("recent_short5")[0].childNodes[0].nodeValue;
		
		setTimeout( "retrieve_newdata()",10000 );
		}
		
	// reloads data from XML file in case of error or incomplete data in XML file when read	
	catch (e)
		{
		setTimeout( "retrieve_newdata()",10000 );
		}
	}
