// JavaScript Document
// Site: Churchill Flute Band Website
//       Multimedia Section (version 3)
// Author: Surreal Kid
// Date: 31st January 2008

function flash ( vars, div )
{
	this.vars = vars;
	this.player = null;
	this.playerName = null;
	this.playerType = null;
	this.playerPlaylist = null;
	this.playerDiv = div;
	
	this.loadList = function ( list, type )
	{
		this.playerPlaylist = list + '/playlist.xml';
		if ( this.playerType !== type )
		{
			this.loadPlayer ( type, this.playerPlaylist );
		}
		else
		{
			var playlist = {file: this.playerPlaylist};
			this.getPlayer().loadFile(playlist);
		}
		// wait a second for the object to load before jumping to the first track
		thisObj = this;
		setTimeout('thisObj.getPlayer().sendEvent("playitem", "0")',3000)
	}
	
	this.loadTrack = function ( track, list )
	{
		if ( this.playerPlaylist != list + '/playlist.xml' ) {
			this.loadList(list);
		}
		player = this.getPlayer().sendEvent('playitem', track);
	}
	
	this.loadPlayer = function ( type, list )
	{
		this.playerType = type;
		switch (type)
		{
			case 'photo':
				this.playerName = this.vars.photo.name;
				this.player = new SWFObject(this.vars.photo.href, this.vars.photo.name, flashVars.common.width, this.vars.photo.height, '7');
				for (var i in this.vars.photo.vars)
				{
					this.player.addVariable(i, this.vars.photo.vars[i])
				}
				break;
			default:
				this.playerName = this.vars.video.name;
				this.player = new SWFObject(this.vars.video.href, this.vars.video.name, flashVars.common.width, this.vars.video.height, '7');
				for (var i in this.vars.video.vars)
				{
					this.player.addVariable(i, this.vars.video.vars[i])
				}
		};
		
		for (var i in this.vars.params) {
			this.player.addParam(i, this.vars.params[i])
		};
		for (var i in this.vars.common) {
			this.player.addVariable(i, this.vars.common[i])
		}
		
		this.player.addVariable('file', list);
		this.player.write(this.playerDiv);
	};
	
	this.getPlayer = function() {
		if ( this.player == null ) {
			return null;
		} else if(navigator.appName.indexOf("Microsoft") != -1) {
			return window[this.playerName];
		} else {
			return document[this.playerName];
		}
	}
}