	var counter;
	var aj_secsremaining;
	var sliderlength = 47;
	var slidertext;


function getServerText() {

   var myurl = 'http://' + document.domain + '/g.php';
  
   myRand = parseInt(Math.random() * 999999999999999);
   var modurl = myurl + "?rand=" + myRand;
   xmlhttpPost(modurl) }

function xmlhttpPost(strURL) {
   var xmlHttpReq = false;
   var self = this;
   // Mozilla/Safari
   if (window.XMLHttpRequest) {
      self.xmlHttpReq = new XMLHttpRequest();
      }
   // IE
   else if (window.ActiveXObject) {
      self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }
   self.xmlHttpReq.open('POST', strURL, true);
   self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   self.xmlHttpReq.onreadystatechange = function() {
      if (self.xmlHttpReq.readyState == 4) {
         updatepage(self.xmlHttpReq.responseText);
         }
      }
   //process no query string
   self.xmlHttpReq.send("");
   }

function updatepage(str) {

   var aj_results = str.split("~");
   var aj_secsremaining = aj_results[11];
   // update screen
   
   //playing ingo
   document.getElementById('upd10').innerHTML = "now playing in " + aj_results[6] + " at " + aj_results[5] +"bpm"
   
   //track info and waveform
   document.getElementById('pl_title').innerHTML = aj_results[3]
   document.getElementById('pl_artist').innerHTML = aj_results[4]
   document.getElementById('pl_peak').innerHTML = aj_results[7]

   //stats
  document.getElementById('pl_s1').innerHTML = aj_results[0] + aj_results[1] 
  document.getElementById('pl_s2').innerHTML = aj_results[2] 


   
   //set seconds remaining to the countdown car - adding '-0' to convert to number
   countDownInterval = aj_secsremaining - 0;
   countDownTime = countDownInterval + 5;  
   countDown()}

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) }

function countDown() {
   countDownTime--;
   
   	//build up the slider effect
      	sliderpos =  Math.floor((sliderlength/countDownInterval) * countDownTime);
   	slidertext ='[-';
   
   	for (i=1;i<=(sliderlength-sliderpos);i++)
   	{slidertext += '-';}
   
   	slidertext += '()';
   
   	for (i=(sliderlength-sliderpos);i<=(sliderlength+1);i++)
   	{slidertext += '-';}
   
	slidertext += '-]';
	
	
   if (countDownTime == 0) {
      countDownTime = countDownInterval;
      getServerText() }
   else if (countDownTime < 0) countDownTime = 30;

  
     document.getElementById('pl_remaining').innerHTML = secsToMins(countDownTime);   
stopCountDown();
   counter = setTimeout("countDown()", 1000);

   }


