//	-------------------------------------
//	Global variables
//	-------------------------------------


//	-------------------------------------
//	Swap video
//	-------------------------------------
//	swap_video() switches out the
//	currently playing video for the newly
//	requested video.
//	-------------------------------------

function swap_video( url, result, oldid, newid, large_loader )
{
	var large		= $(large_loader);
	var target		= $(result);
	var pars		= '';
	
	//	Show loading
	Element.hide( large );
	Element.toggle( large );
	
	//	Show spinner
	Element.show( 'spinner' + newid );
	
	//	Play buttons
	play_buttons( oldid, newid );
	
	//	Stop video
	stop_player(oldid);
	
	//	Remove video
	remove_video( result );
	
	//	Fetch video
	var	aj			= new Ajax.Request( url, { method: 'post', postBody: pars, onSuccess: put, onFailure: fail } );

	function put(t)
	{
		//	Hide loader
		Element.toggle(large);
	
		//	Hide spinner
		Element.hide( 'spinner' + newid );
		
		//	Place video
		var output				= t.responseText;
		target.innerHTML		= output;
	}
	
	function fail()
	{
		//	Hide loader
		Element.toggle(large);
	
		//	Hide spinner
		Element.hide( 'spinner' + newid );
		
		//	Show no_load image
		Element.toggle('no_load');
	}
}

//	End Swap Video



//	-------------------------------------
//	Remove video
//	-------------------------------------
//	remove_video() removes the requested
//	video.
//	-------------------------------------

function remove_video(which)
{
	var video		= $(which);
	
	video.innerHTML	= '';
}

//	End remove video



//	-------------------------------------
//	Play Buttons
//	-------------------------------------
//	play_buttons() swap the on and off
//	play buttons.
//	-------------------------------------

function play_buttons( oldid, newid  )
{
	var id	= $(oldid).value;
	
	Element.show( 'play' + id + 'on' );
	Element.hide( 'play' + id + 'off' );
	Element.toggle( 'play' + newid + 'on' );
	Element.toggle( 'play' + newid + 'off' );
}

//	End play buttons



//	-------------------------------------
//	Stop player
//	-------------------------------------
//	stop_player() stops the currently
//	playing video because just swapping
//	out the iner html is not necessarily
//	enough to shut 'er down. Safari in
//	particular.
//	-------------------------------------

function stop_player(which)
{
	var id	= $(which).value;
	var id	= 'document.' + 'vid' + id;
	var obj	= eval(id);
	obj.Stop();
}

//	End stop player