var isinitVideo = false;

$(document).ready(function() { 
	init_videogallery();  
});

function setVideo(flvvideo, mediaId, adSensitivity, editorialFrame) {

	var getFlashMovie1 = getFlashMovie();

	if (!isinitVideo) { 
	
        $(".videoContent").show();
        
		//var assetsPrefix = 'http://travel.localhost/';
		var assetsPrefix = '/system/modules/com.sky.travel/';
		var tracking_account = (typeof(hitbox_tracking_account) != 'undefined' && hitbox_tracking_account != '') ? hitbox_tracking_account : "DM550824IAEV;DM570829CIEA";
		editorialFrame = (editorialFrame != 'undefined' && editorialFrame != '') ? editorialFrame : null;
		
		var flashvars = {
			    settingsUrl: assetsPrefix+"assets/vp/data/config.xml",
			    auto_play: false,
			    unique_id: mediaId,
			    ad_channel: "Sky Travel:External",
			    tracking_account: tracking_account,
			    editorialFrame: editorialFrame,
			    video_url: flvvideo,
			    playerHeight: "282",
			    playerWidth: "500",
			    brandedPlayBtn: "true"
			};
		var params = {
			    allowfullscreen : "true",
			    bgcolor : "#000000"
			};
		var attributes = {
			    id: "video-player",
			    name: "video-player"
			};
		var swfobj = swfobject.embedSWF(assetsPrefix+"assets/vp/OBU_Player.swf", "video-player", "500", "282", "9.0.28", assetsPrefix+"assets/vp/expressInstall.swf", flashvars, params, attributes);
		isinitVideo = true;
	} else {
		getFlashMovie()._load(flvvideo, mediaId, adSensitivity);
		getFlashMovie()._play();
	}
}

function getFlashMovie() {
	if (navigator.appName.indexOf("Microsoft") != -1)  { 
		return window["video-player"];
	} else  {
		return document["video-player"];
	}
}

function init_videogallery() {

	nodeId = '.widgetvideoplayer ';
	if ( $(nodeId).length > 0 ) {		

		$(nodeId+'ul li').click(function(){ 
			
			return true;
			/*
			//activate onclick state for in-page video loading
			var title = $('h3', this).text();
			var description = $('.wv_desc', this).html();
			var duration = $('.date em', this).html();
			var flvurl = $('.flvurl', this).html();
			var mediaId = $('.wv_uniqueid', this).text();
			var wv_editorialframe = $('.wv_editorialframe', this).text();
			var adSensitivity = 1;
			$('#video-player-title p strong').text(title);
			$('#video-player-description p').text(description);
			$('#video-player-duration p').text("");
			if (duration!=null && duration.length>0) {
				$('#video-player-duration p').text("Duration: "+duration);
			}
			try {
				setVideo(flvurl, mediaId, adSensitivity, wv_editorialframe);
			} catch(err) { }
			return false;
			*/
		});
	}
}

function videogallery_initfirstvideo() {
	//initialise first node
	var nodeId = '.widgetvideoplayer ';
	var defNode = 0;
	//$(nodeId+'ul li:eq('+defNode+')').click();			//click/load first video
	var title = $(nodeId+'ul li:eq('+defNode+') h3').text();
	var description = $(nodeId+'ul li:eq('+defNode+') .wv_desc').html();
	var duration = $(nodeId+'ul li:eq('+defNode+') .date em').html();
	var flvurl = $(nodeId+'ul li:eq('+defNode+') .flvurl').text();
	var mediaId = $(nodeId+'ul li:eq('+defNode+') .wv_uniqueid').text();
	var wv_editorialframe = $(nodeId+'ul li:eq('+defNode+') .wv_editorialframe').text();
	var adSensitivity = 1;
	$('#video-player-title p strong').text(title);
	$('#video-player-description p').text(description);
	$('#video-player-duration p').text("");
	if (duration!=null && duration.length>0) {
		$('#video-player-duration p').text("Duration: "+duration);
	}
	try {
		setVideo(flvurl, mediaId, adSensitivity, wv_editorialframe);
	} catch(err) { }
	return false;
}

//custom load a video
function videogallery_customvideo(flvurl, mediaId, adSensitivity, wv_editorialframe) {
	try {
		setVideo(flvurl, mediaId, adSensitivity, wv_editorialframe);
	} catch(err) { }
	return false;
}
