var xmlHttp;

function getData(url,stateChangedFunction)
{
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  xmlHttp.onreadystatechange=stateChangedFunction;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
} 

function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
  {
    //Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
  // Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}


function refreshCurrentSong()
{
  getData("ajaxcalls/getcurrentsong.php",setCurrentSong);
}

function customunescape(str)
{
	var str2 = unescape(str);	
	str2 = str2.replace(/&#x27;/gi,"'");
	str2 = str2.replace(/&amp;/gi,"&");
	str2 = str2.replace(/^\s*|\s*$/g,'');
	return str2;
}

function setCurrentSong()
{
  if (xmlHttp.readyState==4)
  {
	var stp1 = customunescape(xmlHttp.responseText);
	var stp2 = customunescape(document.getElementById("currentSong").innerHTML);
	if(stp1 != stp2) {
     	  document.getElementById("currentSong").innerHTML = xmlHttp.responseText;
          refreshSongHistory();
 	 } else
      setTimeout("refreshCurrentSong();",10000);
  }
}



function setSongHistory()
{
  if (xmlHttp.readyState==4)
  {
    document.getElementById("songHistory").innerHTML = xmlHttp.responseText;
    refreshAlbumArt();
  }
}

function refreshSongHistory()
{
    getData("ajaxcalls/getsonghistory.php",setSongHistory);
}

function refreshAlbumArt()
{
    getData("ajaxcalls/getart.php",setAlbumArt);
}

function setAlbumArt()
{
  if (xmlHttp.readyState==4)
  {
      document.getElementById("albumArt").innerHTML = xmlHttp.responseText;
      prepZooms();
      setTimeout("refreshCurrentSong();",10000);
  } 
}

function startTimer()
{
  fly();
  setupZoom();
  setTimeout("refreshCurrentSong();",10000);
}


