	var http = getXMLHTTPRequest();
	var counter;
	
	function songinfo(songid)
	{
		// Duplicate of /songinfo.js
		songwin = window.open("http://www.fuelradio.fm/songinfo.php?songid="+songid, "songinfowin", "location=no,status=no,menubar=no,scrollbars=yes,resizeable=yes,height=500,width=790");
	}

      function getXMLHTTPRequest() {
      try {
      req = new XMLHttpRequest();
      } catch(err1) {
        try {
        req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (err2) {
          try {
          req = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (err3) {
            req = false;
          }
        }
      }
      return req;
      }



      function getServerText() {
        var myurl = 'http://www.fuelradio.fm/aj_TimeRemain.php'; // enter the full path to the aj_TimeRemain.php path
        var myRand = parseInt(Math.random()*999999999999999);
        var modurl = myurl+"?rand="+myRand;
        http.open("GET", modurl, true);
        http.onreadystatechange = useHttpResponse;
        http.send(null);
      }

      function useHttpResponse() {
               if (http.readyState == 4) {
          if(http.status == 200) {
	  		// alert('Current song says hello');
          	// parse data returned from aj_TimeRemain.php
          	var aj_results = http.responseText.split("|");

          	var aj_duration = aj_results[0];
          	var aj_secsremaining = aj_results[1];
          	var aj_title = '"' + aj_results[2] + '"';
          	var aj_artist = aj_results[3];
			var aj_album = aj_results[4];
			var aj_mmss = aj_results[5];
			var aj_picture = aj_results[6];
			var aj_buycd = aj_results[7];
			var aj_songid = aj_results[8];
			var aj_website = aj_results[9];		
			var aj_songtype = aj_results[10];
			var aj_requestid = aj_results[11];
			
          	// update title and artist divs
			
			var aj_favorites = " <a href='http://www.fuelradio.fm/premiumfuel.php?artist=" + aj_artist + "&songid=" + aj_songid + "&title=" + escape(aj_title) + "&add_to_favorites=true' title='Add to favorites'><img src='http://www.fuelradio.fm/images/Favorites.png' width='18px' height='18px' border='0' /></a>";
			var aj_songinfo = ' <a href="javascript:songinfo(' + aj_songid + ');" title="Song Info"><img src="http://www.fuelradio.fm/images/Info.png" width="18px" height="18px" border="0" alt="Song Info" /></a>'; 			

			if(aj_title == undefined)
	          	document.getElementById('title').innerHTML =  "Error - check announcements";			
			else if(aj_requestid > 0)
	          	document.getElementById('title').innerHTML =  aj_title + " <span title='Requested' class='requested'>*</span>";
			else
				document.getElementById('title').innerHTML =  aj_title;
			
			if(aj_artist == undefined)
	          	document.getElementById('artist').innerHTML =  "&nbsp;";	
			else
	          	document.getElementById('artist').innerHTML =  '<a href="playlist.php?artist=' + aj_artist + '" title="Artist page" class="artist">' + aj_artist + '</a>';
			
			if(aj_album == undefined)
	          	document.getElementById('album').innerHTML =  "&nbsp;";	
			else
				document.getElementById('album').innerHTML = aj_album;
				
			// document.getElementById('mmss').innerHTML = aj_mmss;
			if(aj_picture=="" || aj_picture==undefined)
				aj_picture="na.jpg";
			document.getElementById('picture').src = "http://www.fuelradio.fm/pictures/" + aj_picture;		
			document.getElementById('picture').alt = "" + aj_artist;
			document.getElementById('picturelink').title = "" + aj_artist;
			document.getElementById('picturelink').target = "_top";		
			
			if(aj_buycd=="" && aj_songtype=='C')
			{
				document.getElementById('picturelink').href = "";				
				document.getElementById('buycdbutton').innerHTML = "";				
			}
			else if(aj_buycd=="")
			{
				document.getElementById('picturelink').href = "http://www.fuelradio.fm/playlist.php?artist="+escape(aj_artist);				
				aj_buycd = 'http://www.amazon.com/gp/search?ie=UTF8&keywords='+aj_artist+'+'+aj_album+'&tag=therefineryroc-20&index=music&linkCode=ur2&camp=1789&creative=9325';
				document.getElementById('buycdbutton').innerHTML = '<a href="' + aj_buycd + '" title="Search Amazon" target="blank"><img src="http://www.fuelradio.fm/images/buynow.png" alt="Search Amazon" border="0"></a> <!--<a href="' + aj_buycd + '" title="Search Amazon for this album" target="blank"><img src="http://www.fuelradio.fm/images/Dollar.png" alt="Search Amazon for this album" width="12px" height="12px" border="0" /></a>-->' + aj_favorites + aj_songinfo;
			}
			else	
			{
				document.getElementById('picturelink').href = "http://www.fuelradio.fm/playlist.php?artist="+escape(aj_artist);
				document.getElementById('buycdbutton').innerHTML = '<a href="' + aj_buycd + '" title="Buy CD!" target="blank"><img src="http://www.fuelradio.fm/images/buynow.png" alt="Buy CD!" border="0" /></a> <!--<a href="' + aj_buycd + '" title="Buy CD on Amazon.com" target="blank"><img src="http://www.fuelradio.fm/images/Dollar.png" alt="Buy CD on Amazon.com" width="12px" height="12px" border="0" /></a>-->' + aj_favorites + aj_songinfo;
			}
			
			// var artisticonlink = document.getElementById('artisticonlink'); 
			// var artisticonlinktitle = artisticonlink.getAttribute('title');
			// artisticonlinktitle = "AJAX: Search playlist for " + aj_artist;
			// var artisticonlinkhref = artisticonlink.getAttribute('href');
			// artisticonlinkhref = "http://www.google.com?q=" + aj_artist;

            //set seconds remaining to the countdown car - adding '-0' to convert to number

            countDownInterval = aj_secsremaining - 0;
            countDownTime = countDownInterval + 1;
			
            countDown();
			getHistory();
			
          }
        } else {
        //document. getElementById('actual').innerHTML = "";
        }
      }

    function countDown() {
      countDownTime--;
      if (countDownTime == 0) {
        countDownTime = countDownInterval;
        getServerText()
      }
      else if (countDownTime < 0)
        countDownTime = 30;
      if (document.all)
        document.all.countDownText.innerText = secsToMins(countDownTime);
      else if (document.getElementById)
        document.getElementById("countDownText").innerHTML = secsToMins(countDownTime);
      stopCountDown();
      counter = setTimeout("countDown()", 1000);
    }

    function secsToMins(theValue) {
      var theMin = Math.floor(theValue / 60);
      var theSec = (theValue % 60);
      if (theSec < 10)
        theSec = "0" + theSec;
      return(theMin + ":" + theSec);
    }

	function stopCountDown()
		{
		clearTimeout(counter)
		}
		
		
// Additional functions to get song history. Should be combined with Current Song but done here to separate for initial setup	
  function getHistory() {
	var myurl = 'http://www.fuelradio.fm/aj_History.php'; // enter the full path to the aj_History.php path
	var myRand = parseInt(Math.random()*999999999999999);
	var modurl = myurl+"?rand="+myRand;
	http.open("GET", modurl, true);
	http.onreadystatechange = useHttpResponseOnHistory;
	http.send(null);
  }
  
  function useHttpResponseOnHistory() {
	if (http.readyState == 4) {
	  if(http.status == 200) {
  		// alert('History says hello');
		// parse data returned from aj_History.php
		var aj_results = http.responseText.split("|");
		// alert('Length: ' + aj_results.length); 
		var index = 1; 
		var historyId = 0;
		var titleIdName = '';
		var artistIdName = '';

		for(index; index < aj_results.length-1; index++)
		{
			historyId = index; 
			titleIdName = 'title' + historyId; 
			artistIdName = 'artist' + historyId;
			var song = aj_results[index].split(' - ');
	  		//alert('' + historyId);
			//alert('' + titleIdName); 
			//alert('' + artistIdName); 
			//alert('Title: ' + aj_results[index]);  
			var artist = document.getElementById(artistIdName);
			artist.innerHTML = '<a href="playlist.php?artist=' + song[0] + '" title="Artist page" class="artist">' + song[0] + '</a>';
			var title = document.getElementById(titleIdName);
			var titletext = '';
			if(song[2]!='')
			{
				titletext = '"' + song[1] + '" ' + song[2];
			}
			else
			{
				titletext = '"' + song[1] + '"'; 	
			}
            title.innerHTML = titletext; 
			
			// if(title==null) 
			// { alert(''+index); }
			//alert('Artist: ' + aj_results[index]); 	
			//index = index+1;
			//alert('Artist: ' + aj_results[index]); 				
			//artist = document.getElementById(artistIdName).innerHTML; 
			//artist = aj_results[index]; 
		}	
	  }
	}
  }  // end function useHttpResponseOnHistory
 