var player;

function playerReady(obj) {
	var id = obj['id'];
	var version = obj['version'];
	var client = obj['client'];
	player = document.getElementById(id);
	player.addModelListener("TIME", "moveBar"); 
};

function moveBar(obj) {

  //alert(obj.position + " " + obj.duration);
  var width = document.getElementById('song').offsetWidth;
  var pos = obj.position;
  var dur = obj.duration;
  
  var px_moved = (pos/dur)*(328-width);
  //alert((-328 + px_moved) + "px");
  //document.getElementById('song').style.backgroundPositionX = (-328 + px_moved) + "px";
  document.getElementById('song').style.backgroundPosition = (-328 + px_moved) + "px 0px";
}

function play() {
  if (document.getElementById('play-button').src == "http://tonightradio.com/widgets/play.gif") {
	
    //document.getElementById('song').style.backgroundColor = "#e5e5e5";
    document.getElementById('song').style.backgroundImage = "url('http://tonightradio.com/widgets/blockb.gif')";
    player.sendEvent('PLAY');
    document.getElementById('song').style.backgroundColor = "#e5e5e5";
    document.getElementById('play-button').src = "http://tonightradio.com/widgets/pause.gif"; 
  } else {
  
    //document.getElementById('song').style.backgroundColor = "#e5e5e5";
    document.getElementById('song').style.backgroundImage = "url('http://tonightradio.com/widgets/blockb.gif')";
    player.sendEvent('PLAY');
    document.getElementById('song').style.backgroundColor = "#fff";
    document.getElementById('play-button').src = "http://tonightradio.com/widgets/play.gif"; 
    
  } 
}

var so = new SWFObject('http://tonightradio.com/player/player.swf', 'ply', '200', '20', '9');
so.addParam('allowscriptaccess', 'always');
so.addParam('allowfullscreen', 'false');
so.addVariable('type', 'sound');
so.addVariable('file', document.getElementById('song-url').innerHTML);
so.addVariable('autostart', 'false');
so.addVariable('screencolor', '000');
so.write('player');

