/**
 *  song.js:
 *
 */
//GLOBALS

// Hook for Internet Explorer.
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub NowPlaying_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call NowPlaying_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}

// Handle all the FSCommand messages in a Flash movie.
function NowPlaying_DoFSCommand(command, args) {
	var NowPlayingObj = isInternetExplorer ? document.all.NowPlaying : document.NowPlaying;
	//alert( "FSCommand: " + args );
	 SongManager.SetNowPlaying( args );
}

//song object
function KickAxeSong( name, id, album )
{
	this.name = name;
//	this.url = url;
	this.id = id;
	this.album = album;
	this.flash = null;
    return this;
};

SongManager = new Object();

////////////////////////////////////////////////////////////////////////////////////////

function SongManager()
{
	this.obj = null;
	this.nowPlaying = null;
    return this;
};


////////////////////////////////////////////////////////////////////////////////////////
SongManager.Init = function( obj )
{
	this.obj = this;
	this.admin = obj.admin;

	this.flashSongs = document.getElementsByName("PlaySong");
	//alert( goFlashSongs.length );

	for( i=0; i < SONG.length; i++ ) {
		this.SetSong(i);
	}

	//alert( "Song Manager Initialized");
	//show everything now that we are done
	divMain = document.getElementById("MainDiv");
	divMain.style.display="block";
    return this;
};
/*********************************************************
    SET SONG
 ********************************************************/
SongManager.SetSong = function( iSong ) {

	oSong = this.flashSongs[iSong];
	//alert( SONG[iSong].url );
	oSong.SetVariable("Song", SONG[iSong].name );
//	oSong.SetVariable("SongUrl",  SONG[iSong].url );
	oSong.SetVariable("SongId",  SONG[iSong].id );
	oSong.SetVariable("Album",  SONG[iSong].album );
	SONG[iSong].flash = oSong;


}
/*********************************************************
    SET NOW PLAYING
 ********************************************************/
 SongManager.SetNowPlaying = function( args ) {
	if( args.length ) {
		for( i=0; i < SONG.length; i++ ) {
	     	if( SONG[i].name == args ) {
	     		//alert( SONG[i].name );
	     		if( this.nowPlaying != null ) {
	     			//turn off currently playing song
					this.nowPlaying.flash.GotoFrame(2); //Frame 2 stops the logo and resets the buttons
	     		}
	     		this.nowPlaying = SONG[i];
	     		break;

	     	}

		}
	} else {
		this.nowPlaying = null;
	}

 }

 /*********************************************************
    EDIT SONG
 ********************************************************/
 SongManager.EditSong = function( id ) {

 	alert("Edit Song " + id );
	el = document.getElementById( "EditSongDiv" );
	el.style.display = "inline";
	el = document.getElementById( "MainDiv" );
	el.style.display = "none";
	id= event.srcElement.id;

 }