/*
show_video_popup function
	* vid_name 					- name of SWF video (not critical)
	* video_id 					- id of dialog box
	* popup_width, popup_height - width and height of popup (must be integers)
	* vid_width, vid_height 	- width and height of video (must be strings)
	* streamer, file			- URL to video split into parts
	* type						- type of video stream (video=html, rmtp=streaming)
	* image						- image to show before image start streaming if any
	* output_id					- div that receives video stream output
*/

$.fn.show_video_popup = function(vid_name, video_id, popup_width, popup_height, vid_width, vid_height, streamer, file, type, image, output_id) 
{
	
	// Video dialog popup
	$(this).click(
	function()
	{
		$('#'+video_id).dialog({ 
			autoOpen:false, 
			resizable:false, 
			width: popup_width,		
			modal:true,
			close: function() {
				$('#'+video_id).dialog('destroy');
			}
		});
		$('#'+video_id).dialog('open'); 
		$('#'+video_id).dialog( "option", "height", popup_height);
		$('#'+video_id).dialog( "option", "position", "center");
		
		//Google Analytics Tracking
		var track_url = "/index/video/" + file;
		_gaq.push(['_trackPageview', track_url]);
		
		// FlashObject is here so it closes properly when dialog is destroyed, else, video will keep playing with no audio.
		var shockWaveObject = new SWFObject( "/flash/player.swf", vid_name, vid_width, vid_height, "6", "#cccccc" );
		shockWaveObject.addParam( "wmode", "transparent" );
		shockWaveObject.addParam( "quality", "medium" );
		shockWaveObject.addParam( "loop", "false" );
		shockWaveObject.addParam("allowfullscreen", "true");
		if (streamer != '')
		{
			shockWaveObject.addVariable("streamer", streamer);
		}
		shockWaveObject.addVariable("file", file);
		shockWaveObject.addVariable("type", type);
		shockWaveObject.addVariable("autostart", "true");
		shockWaveObject.addVariable("image", image);
		shockWaveObject.write( output_id );
		
		return false;		     
    });
	
	return false;	
}


/*
show_video_popup function
	* lookout					- div id starting text for the click function element
	* vid_name 					- name of SWF video (not critical)
	* video_id 					- id of dialog box
	* popup_width, popup_height - width and height of popup (must be integers)
	* vid_width, vid_height 	- width and height of video (must be strings)
	* streamer, file			- URL to video split into parts
	* type						- type of video stream (video=html, rmtp=streaming)
	* image						- image to show before image start streaming if any
	* output_id					- div that receives video stream output
*/

$.fn.show_multiple_video_popup = function(lookout, video_array, vid_name, video_id, streamer, type, output_id) 
{
	
	// Video dialog popup
	$('[id^="'+lookout+'"]').click(
	function()
	{
		var buttonId = $(this).attr("id");
		var video_attr = buttonId.substr( (lookout.length+1), (buttonId.length-(lookout.length+1)));
		
		//Google Analytics Tracking
		var track_url = "/index/video/" + video_attr;
		_gaq.push(['_trackPageview', track_url]);
		
		$('#'+video_id).dialog({ 
			autoOpen:false, 
			resizable:false, 
			width: video_array[video_attr]['pop_width'],		
			modal:true,
			close: function() {
				$('#'+video_id).dialog('destroy');
			}
		});
		$('#'+video_id).dialog('option', 'title', video_array[video_attr]['title']);
		$('#'+video_id).dialog('open');   
		$('#'+video_id).dialog( "option", "height", video_array[video_attr]['pop_height']);
		$('#'+video_id).dialog( "option", "position", "center");
		
		// FlashObject is here so it closes properly when dialog is destroyed, else, video will keep playing with no audio.
		var shockWaveObject = new SWFObject( "/flash/player.swf", vid_name, video_array[video_attr]['vid_width'], video_array[video_attr]['vid_height'], "6", "#cccccc" );
		shockWaveObject.addParam( "wmode", "transparent" );
		shockWaveObject.addParam( "quality", "medium" );
		shockWaveObject.addParam( "loop", "false" );
		shockWaveObject.addParam("allowfullscreen", "true");
		shockWaveObject.addVariable("streamer", streamer);
		shockWaveObject.addVariable("file", video_array[video_attr]['flv']);
		shockWaveObject.addVariable("type", type);
		shockWaveObject.addVariable("autostart", "true");
		shockWaveObject.addVariable("image", video_array[video_attr]['image']);
		shockWaveObject.write( output_id );
		
		return false				     
    });
	
	return false;	
}