/*
	module name: lu-xspf_jukebox.js
	date: Friday, March 27, 2009
	version: 1.0 of wrapper, 5.9.5 of Flash
	author: Jay Dansand (jay.dansand@gmail.com) for Lawrence University ITS
	purpose:
		Provide a JavaScript wrapper to create instances of the XSPF Jukebox Flash application.
	configuration:
		None.
	usage:
		Instantiate the player with:
			new XSPFJukebox(playlist, [options, [container]])
				file - required. String with URL (relative or absolute) to a playlist or media file.
				options - optional.  Key:value array of param values to pass to the Flash applet (see Flash's documentation)
				container - optional.  String ID, Number Index, or Element reference to the destination for the Flash applet.
					NOTE: The element referenced, if pre-existing, will be replaced by the proper OBJECT/EMBED element.
						If it does not exist, it will be created.
		
		Object provides (read-only functions/variables):
			.getSelf() - Object self reference.
			.getWidth() - Number width of applet.
			.getHeight() - Number height of applet.
			.getPath() - String path to base of JavaScript/Flash files.
			.getExpressInstaller() - String path to Adobe ExpressInstall applet.
			.getContainer() - Object reference to Flash object/embed.
			.getContainerID() - String ID of Flash object.
			.getOptions() - Array of options passed to Flash applet.
			.Version - String version of this Flash/wrapper.
			
			Flash controls (return True if no error, False on error):
			Play() - Start playback.
			Stop() - Stop playback.
			Next() - Go to next file in the playlist.
			Prev() - Go to previous file in the playlist.
			setTrack(#) - Go to track # in the playlist.
			toggleShuffle() - Toggle shuffle on/off.
			toggleRepeat() - Toggle repeat on/off.
			addTrack(id, file_url, title, creator, info_url, purchase_url, image_url, annotation) - Add track to the playlist.
*/

function XSPFJukebox(playlist, options, container)
{
	var __path = __scripts['xspf jukebox']['path'];
	var __expressInstaller = __scripts['swfobject']['path'] + "/expressInstall.swf";
	var __width = 400;
	var __height = 170;
	var __self = this;
	//Configure the player:
	var __options = (options) ? options : new Array();
	if (!__options.track_url) __options.playlist_url = (playlist) ? playlist : __path + "/lu_noplaylist.xml";
	//Force some options:
	__options.skin_url = __path + "/skins/Original";
	__options.autoload = "true";
	__options.autoplay = "false";
	__options.load_message = "Click to Start";
	__options.loadurl = ""; //don't allow a circumvention of these defaults
	__options.gotoany = "true";
	__options.crossFade = (__options.crossFade) ? __options.crossFade : false;
	//
	this.getSelf = function () { return __self; };
	this.getWidth = function () { return __width; };
	this.getHeight = function () { return __height; };
	this.getPath = function () { return __path; };
	this.getExpressInstaller = function () { return __expressInstaller; };
	this.getOptions = function () { return __options; };
	var __container = createContainer(container, "XSPFJukebox").id;
	this.getContainer = function () { return document.getElementById(__container); };
	this.getContainerID = function () { return __container; };
	this.create(); //Instantiate the player
}

XSPFJukebox.prototype = {
	Version: '5.9.5',
	create: function ()
	{
		swfobject.embedSWF(this.getPath() + "/xspf_jukebox.swf", this.getContainerID(),
			this.getWidth(), this.getHeight(), "8.0.0", this.getExpressInstaller(), this.getOptions());
	},
	Play: function () { try { this.getContainer().playTrack(); } catch(e) { return false; } return true; },
	Stop: function () { try { this.getContainer().stopTrack(); } catch(e) { return false; } return true; },
	Next: function () { try { this.getContainer().nextTrack(); } catch(e) { return false; } return true; },
	Prev: function () { try { this.getContainer().prevTrack(); } catch(e) { return false; } return true; },
	setTrack: function (id) { try { this.getContainer().gotoTrack(id); } catch(e) { return false; } return true; },
	toggleShuffle: function () { try { this.getContainer().shuffleToggle(); } catch(e) { return false; } return true; },
	toggleRepeat: function () { try { this.getContainer().repeatToggle(); } catch(e) { return false; } return true; },
	addTrack: function (id, file_url, title, creator, info_url, purchase_url, image_url, annotation)
		{ try { this.getContainer().addTrack(id, file_url, title, creator, info_url, purchase_url, image_url, annotation); } catch(e) { return false; } return true; }
};
