/*
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
	* title						- title for the dialog box (optional) - Added by Sujit on 2/9/2011
*/

$.fn.show_video_popup = function(vid_name, video_id, popup_width, popup_height, vid_width, vid_height, streamer, file, type, image, output_id, title) 
{
	// 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");
		if (title) {
			$('#'+video_id).dialog("option", "title", title);
		}
		
		// FlashObject is here so it closes properly when dialog is destroyed, else, video will keep playing with no audio.
		var shockWaveObject = new SWFObject( "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.addVariable("stretching", "exactfit");
		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

	Note: If you have two links to same video, just add "_secondvid" to second link and it will treat them the same.
*/

$.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)));
		
		hasSecondVid = video_attr.indexOf('_secondvid');
		if (hasSecondVid != -1) {
			video_attr = video_attr.substr(0, hasSecondVid);
		}

		// If we have multiple links to sme
		
		//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");
		if(video_array[video_attr]['flv'].indexOf("mp4.schweser.com") > 0){
			shockWaveObject.addVariable("type", "video");
		}
		else{
			shockWaveObject.addVariable("streamer", streamer);
			shockWaveObject.addVariable("type", type);
		}
		shockWaveObject.addVariable("file", video_array[video_attr]['flv']);
		shockWaveObject.addVariable("autostart", "true");        

        //image would not be called if its null
        var img = video_array[video_attr]['image'];
        if (img == '' || img == null || img === undefined){}
        else
            shockWaveObject.addVariable("image", video_array[video_attr]['image']);

		shockWaveObject.write( output_id );
		
		return false				     
    });
	
	return false;	
}
