// music streaming stuff -----------------------------------------
// stream from within a div
var streaming = false;
var playerQueue = '';
var containerQueue = '';
var playerHtml;

function streamTrack( streamPage, containerId )
{
	if( streaming == false )
	{
		// if nothing's open, open up and play the stream
		streaming = true;
		openMp3Player( streamPage, containerId );
	}
	else
	{
		// store next stream to play and close the current stream
		playerQueue = streamPage;
		containerQueue = containerId;
		closePlayer();
	}
	
	//return false;
}

function getStream( streamPage )
{
	// make call for new mp3 streamer
	new Ajax.Updater( $('currentPlayer') , streamPage, {
	  //parameters:{trackNum:}, 
	  method:'post',
	  evalScripts:true,
	 // insertion: Insertion.Before,
	  onComplete: showMp3Player
	});
}

function openMp3Player( streamPage, containerId )
{
	//hideFlash();
	new Insertion.Before( $(containerId), '<div id="currentPlayer"></div>' );
	$('currentPlayer').hide();
	Effect.BlindDown(  $('currentPlayer'), { duration:.8, scaleContent:false, afterFinish: function(){ getStream(streamPage); } } );
	
}

function showMp3Player()
{
	//showFlash();
	//$('currentPlayer').show();
}

function closePlayer()
{
	//hideFlash();
	// kill player
	$('musicSwfDiv').remove();
	Effect.BlindUp(  $('currentPlayer'), {duration:.8, scaleContent:false, afterFinish: checkPlayerQueue} );
}

function checkPlayerQueue()
{
	// set flag
	streaming = false;
	$('currentPlayer').remove();
	
	if( playerQueue != '' )
	{
		// play stream if one was in the queue
		streamTrack( playerQueue, containerQueue );
		// reset the queue
		playerQueue = '';
		containerQueue = '';
	}
}

