
function get_cookie(name) {
   var search = name + "="
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search) 
      if (offset != -1) { // if cookie exists 
         offset += search.length 
         // set index of beginning of value
         end = document.cookie.indexOf(";", offset) 
         // set index of end of cookie value
         if (end == -1) 
            end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      } 
   }
}

function XSPFPlayer(mdiv, width, height,song_url) {
        this.obj = new SWFObject('http://knockcastle.com/xspf_player_slim.swf', 'myplayer', width, height, '7');
        this.div = mdiv;
        
        if (get_cookie('music')=='stop') {
          this.obj.addVariable('autoplay','');
          this.obj.addVariable('autoload','');
          var elStop = document.getElementById('stop');
          elStop.style.display = 'none';
        } else {
          this.obj.addVariable('autoplay','1');
          this.obj.addVariable('repeat_playlist','1');
          var elPlay = document.getElementById('play');
          elPlay.style.display = 'none';
        }
        this.obj.addVariable('song_url', song_url);
        this.obj.write(this.div);
}

XSPFPlayer.prototype.play_song = function(title, song_url) {
        this.obj.addVariable('autoplay','1');
        this.obj.addVariable('repeat_playlist','1');
        this.obj.addVariable('song_url', song_url);
        this.obj.addVariable('song_title', title);
        this.obj.write(this.div);
        document.cookie="music=stop; expires=01/01/1970 00:00:00";
        var elPlay = document.getElementById('play');
        elPlay.style.display = 'none';
        var elStop = document.getElementById('stop');
        elStop.style.display = '';
}

XSPFPlayer.prototype.stop = function() {
        this.obj.addVariable('autoplay','');
        this.obj.write(this.div);
        document.cookie ="music=stop; expires=31/12/2050 00:00:00";
        var elStop = document.getElementById('stop');
        elStop.style.display = 'none';
        var elPlay = document.getElementById('play');
        elPlay.style.display = '';
}
