var VIDEO_COMPONENT_AJAX_URL = "/common/ajax/front/components/VideoDisplay/ajax.php";
var VIDEOLIST_COMPONENT_AJAX_URL = "/common/ajax/front/components/VideoList/ajax.php";


/* Select Embed Code or URL */
function fncVideoDisplayComponent_Select(elm) {
	$(elm).focus();
	$(elm).select();
}

/* 
* Video List 
* For main video list component
*/
function fncVideoListComponent_VideoList_Load(offset, object){
	elm                	= $(object.elm);
	uniqid             	= object.uniqid;
	
	// find view all div, turn it temporarily into a loading bar
	$('VideoList_'+uniqid).down('.vl_viewall').update('<center><br><img src="/common/templates/default/images/loadingsmall.gif" /><br><br></center>');
	
	new Ajax.Updater({success:$('VideoList_'+uniqid).down('.vl_ajax')}, VIDEOLIST_COMPONENT_AJAX_URL, {
		parameters: { 
			action             	: 'VideoList_Load',
			offset             	: offset,
			uniqid             	: uniqid
		},
		evalScripts : true,
							
		onSuccess: function(transport){
		
		},
		
		onFailure: function(transport){
			$('VideoList_'+uniqid).down('.vl_viewall').update('Error retrieving news. Please refresh the page.'); 
		}
	});
	
}

/* 
* Video List 
* For MAIN video display component
*/
function fncVideoDisplayComponent_VideoList_Load(offset, object){
	$('VideosRelated').innerHTML = '<center><br><br><br><br><br>Loading<br><img src="/common/templates/default/images/loading.gif" /><br><br><br><br><br></center>';
	
	elm               	= $(object.elm);
	int_page_tag_id   	= object.int_page_tag_id;
	page_name           = object.page_name;
	int_rows            = object.int_rows;
	thumb_w				= object.thumb_w;
	thumb_h				= object.thumb_h;
	
	new Ajax.Updater({success : $('VideosRelated').down()}, VIDEO_COMPONENT_AJAX_URL, {
		parameters: { action           	: 'VideoList_Load',
					offset             	: offset,
					int_page_tag_id		: int_page_tag_id,
					page_name          	: page_name,
					int_rows			: int_rows,
					thumb_w				: thumb_w,
					thumb_h				: thumb_h
		},
		evalScripts : true,
		onLoading: function() {
			
		},
		onComplete: function() {
			
		}
	});
}




/* Load SWF Object 

arr_files['video_filename']
arr_files['video_thumbnail']
arr_files['preroll']['playlist_file']
arr_files['preroll']['url']	

LEGACY: After we upgraded to player 5.3+, this is not used anymore. -yaz

*/
function loadSWFObject(arr_files, video_player_div, video_width, video_height) {
		
	var embed_player = '_Embed_'+video_player_div;
	
	var video_player = new SWFObject('/common/js/external/jw_media_player/mediaplayer.swf',embed_player, video_width, video_height,'7', '#000000', true);

	video_player.addParam('allowfullscreen'				, 'true');
	video_player.addParam('wmode'						, 'transparent');
	
	video_player.addVariable('stretching'				, 'uniform');
	video_player.addVariable("backcolor"				, "0x000000");
	video_player.addVariable("frontcolor"				, "0xFFFFFF");
	video_player.addVariable("lightcolor"				, "0xFFFFFF");
	video_player.addVariable("screencolor"				, "0x000000");
	
	video_player.addVariable("width"					, video_width);
	video_player.addVariable("height"					, video_height);
	
	if(arr_files['preroll']) {
		video_player.addVariable("file", 				arr_files['preroll']['playlist_file']);
		video_player.addVariable("autostart"			, 'false');
		video_player.addVariable("repeat"				, 'list');
		
		if(arr_files['preroll']['url']) {
			video_player.addVariable("displayclick" 	, 'link');
			video_player.addVariable("linktarget"		, '_blank');
		}
						
	} else {
		video_player.addVariable("file", 				arr_files['video_filename']);
		video_player.addVariable("image", 				arr_files['video_thumbnail']);
		
	}
	
	video_player.write(video_player_div);
}

