// XSPF Player JavaScript Control
//
// By Michael Chaney, Michael Chaney Consulting Corporation
// Copyright 2006 Michael Chaney Consulting Corporation
//
// This code is released under the same BSD-style license as the XSPF Player.
// For more info: http://musicplayer.sourceforge.net/

function XSPFPlayer(mdiv, width, height, flash_file) {
	if (isAppleTouchDevice) {
		this.$window=null;
	} else {
		if (!flash_file) {
      	flash_file='/flash/mp3player.swf';
      	this.fixed=true;
   	}
		this.obj = new SWFObject(flash_file, "single", width, height, "7");
		this.div = mdiv;
		this.obj.addVariable('autoplay','false');
   	this.obj.addParam("wmode","transparent");
   	this.obj.addParam("menu","false");
		this.obj.addVariable('song_url', '/nada.mp3');
		this.obj.addVariable('song_title', ' ');
		this.obj.write(this.div);
	}
}

XSPFPlayer.prototype.play_song = function(title, song_url) {
	if (isAppleTouchDevice) {
		this.$window = window.open(song_url, 'playerwindow');
	} else {
		this.obj.addVariable('autoplay','true');
		this.obj.addVariable('song_url', song_url);
		this.obj.addVariable('song_title', title.replace(/ ?& ?/g, ' and '));
		this.obj.write(this.div);
	}
}

XSPFPlayer.prototype.stop = function() {
	if (isAppleTouchDevice) {
		this.$window.close();
		this.$window = null;
	} else {
		this.obj.addVariable('autoplay','');
		this.obj.write(this.div);
	}
}
