/*
	09/12/2009 - Change to use flash object and new player
	09/08/2010 - MSO8768 - Added widescreen toggle in processResponseVideos. DD.
*/

// Ajax Connection code
function makeRequestVideos(url) {
	new Ajax.Request(url,{onSuccess:processResponseVideos})

}


var curFlashVideo;
function processResponseVideos(transport) {
	var xmldoc = transport.responseXML;

	// Get the form fields
	var num_videos = xmldoc.getElementsByTagName('video').length - 1;		
	var str_tmp = '';
	

	for (var i = 0; i <= num_videos; i++) {
		var intID = xmldoc.getElementsByTagName('vidId').item(i).firstChild.data;
		var str_Filename = xmldoc.getElementsByTagName('streams').item(i).firstChild.data;
		var fullscreenVal = xmldoc.getElementsByTagName('extraOptions').item(i).firstChild.data;
		var xml_file = xmldoc.getElementsByTagName('xml_file').item(i).firstChild.data;
		if (xmldoc.getElementsByTagName('htmltarget').item(i)) {
			var html_target = xmldoc.getElementsByTagName('htmltarget').item(i).firstChild.data;
		} else {
			var html_target = 'widgetMainVideo';
		}
		if (xmldoc.getElementsByTagName('player').item(i)) {
			if (xmldoc.getElementsByTagName('player').item(i).firstChild.data == 'wide') {
				var playerName = 'plaPlayerWidescreen.swf';
				var playerHeight = "152";
			} else {
				var playerName = 'plaPlayer3.swf';
				var playerHeight = "190";
			}
		} else {
			var playerName = 'plaPlayer3.swf';
			var playerHeight = "190";
		}
		if (str_Filename == 'undefined') str_Filename = '/images/spacer.gif';
		
		
		/*str_tmp = str_tmp +'<object id="videoPlayer" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="270" height="190">';
		str_tmp = str_tmp +'<param name="movie" value="/templates/widgets/plaPlayer3.swf" />';
		str_tmp = str_tmp +'<param name="FlashVars" value="videos=/images/videos/file'+intID+'.xml" />';
		str_tmp = str_tmp +'<param name="allowFullScreen" value="true" />';
		str_tmp = str_tmp +'<param NAME="wmode" VALUE="opaque" />';
		str_tmp = str_tmp + '<param name="allowScriptAccess" value="always">';
		str_tmp = str_tmp +'<embed id="videoPlayer" src="/templates/widgets/plaPlayer3.swf" FlashVars="videos=/images/videos/file'+intID+'.xml" allowFullScreen="true" width="270" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		str_tmp = str_tmp +'</object>';
		//str_tmp = str_tmp +'</noscript>';*/


		
		var newFlashVideo = new SWFObject("/templates/widgets/"+playerName, "videoPlayer", "270", playerHeight, "8.0.15", "#ffffff", true);
  		newFlashVideo.addVariable("videos", "/images/videos/"+xml_file);
		newFlashVideo.addVariable("allowFullScreen","true");
		newFlashVideo.addParam("allowScriptAccess", "always");
		newFlashVideo.addParam("allowFullScreen", "true");
	    //newFlashVideo.write("widgetMainVideo");
		newFlashVideo.write(html_target);
		curFlashVideo = newFlashVideo;

	}


	/*if (fullscreenVal == 1){	
		flashMovie = document.getElementById("videoPlayer");

		if (flashMovie) {
			setTimeout(function(){
			
				flashMovie.externalGoFullScreen();
			},3000);
           // flashMovie.externalGoFullScreen();
        }
	} else {
		$('widgetMainVideo').innerHTML = str_tmp;
		//playMovieNow('videoPlayer');
	}&*/

} 


/*function showFullscreen() {
	debugger
	if (flashMovie) {
        flashMovie.externalGoFullScreen();
	}
}

function getFlashMovie(movieName) {   var isIE = navigator.appName.indexOf("Microsoft") != -1;   return (isIE) ? window[movieName] : document[movieName];  }*/


//************************    Large Video Request Code    ******************

// Ajax Connection code
function makeRequestVideosLarge(url) {
	new Ajax.Request(url,{onSuccess:processResponseVideosLarge});
}

function processResponseVideosLarge(transport) {
	var xmldoc = transport.responseXML;

	// Get the form fields
	var num_videos = xmldoc.getElementsByTagName('video').length - 1;		
	var str_tmp = '';
	
	for (var i = 0; i <= num_videos; i++) {
		var intID = xmldoc.getElementsByTagName('vidId').item(i).firstChild.data;
		var str_Filename = xmldoc.getElementsByTagName('streams').item(i).firstChild.data;
		if (str_Filename == 'undefined') str_Filename = '/images/spacer.gif';
		
		//str_tmp = str_tmp +'<script type="text/javascript">AC_FL_RunContent( \'codebase\',\'http:\/\/download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\',\'width\',\'270\',\'height\',\'190\',\'allowFullScreen\',\'true\',\'pluginspage\',\'http:\/\/www.macromedia.com/go/getflashplayer\',\'movie\',\'\/templates\/widgets\/plaPlayer3\',\'FlashVars\',\'videos=/images/videos/'+str_Filename+'\' ); ';
		//str_tmp = str_tmp +'\n</script><noscript>';
		str_tmp = str_tmp +'<object id="videoPlayer" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="270" height="190">';
		str_tmp = str_tmp +'<param name="movie" value="/templates/widgets/plaPlayer3.swf" />';
		str_tmp = str_tmp +'<param name="FlashVars" value="videos=/images/videos/file'+intID+'.xml" />';
		str_tmp = str_tmp +'<param name="allowFullScreen" value="true" />';
		str_tmp = str_tmp +'<param NAME="wmode" VALUE="opaque" />';
		str_tmp = str_tmp + '<param name="allowScriptAccess" value="always">';
		str_tmp = str_tmp +'<embed src="/templates/widgets/plaPlayer3.swf" FlashVars="videos=/images/videos/file'+intID+'.xml" allowFullScreen="true" width="270" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		str_tmp = str_tmp +'</object>';
		//str_tmp = str_tmp +'</noscript>';
	}
	
	$('widgetMainVideo').innerHTML = str_tmp;
	//setTimeout(playMovieNow('videoPlayer'),500);
	playMovieNow('videoPlayer');

} //function


function playMovieNow(str_objectID) {
	try {
		thisMovie(str_objectID).playVideo();
	} catch (e) {
		setTimeout(function(){playMovieNow('videoPlayer')},100);	
	}
}

function thisMovie(movieName){
	if (window.document[movieName]) return window.document[movieName];
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName]) return document.embeds[movieName]; 
		else return document.getElementById(movieName);
	}
}







//************************** end of large video request *************************


//centenary code

// Ajax Connection code
function makeRequestVideosCent(url) {
	new Ajax.Request(url,{onSuccess:processResponseVideosCent});
}

function processResponseVideosCent(transport) {
	var xmldoc = transport.responseXML;

	// Get the form fields
	var num_videos = xmldoc.getElementsByTagName('video').length - 1;		
	var str_tmp = '';
	
	for (var i = 0; i <= num_videos; i++) {
		var intID = xmldoc.getElementsByTagName('vidId').item(i).firstChild.data;
		var str_Filename = xmldoc.getElementsByTagName('streams').item(i).firstChild.data;
		var xml_file = xmldoc.getElementsByTagName('xml_file').item(i).firstChild.data;
		if (str_Filename == 'undefined') str_Filename = '/images/spacer.gif';
		
		//str_tmp = str_tmp +'<script type="text/javascript">AC_FL_RunContent( \'codebase\',\'http:\/\/download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\',\'width\',\'270\',\'height\',\'190\',\'allowFullScreen\',\'true\',\'pluginspage\',\'http:\/\/www.macromedia.com/go/getflashplayer\',\'movie\',\'\/templates\/widgets\/plaPlayer3\',\'FlashVars\',\'videos=/images/videos/'+str_Filename+'\' ); ';
		//str_tmp = str_tmp +'\n</script><noscript>';
		str_tmp = str_tmp +'<object id="videoPlayer" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="270" height="190">';
		str_tmp = str_tmp +'<param name="movie" value="/templates/widgets/plaPlayer3.swf" />';
		//str_tmp = str_tmp +'<param name="FlashVars" value="videos=/images/videos/file'+intID+'.xml" />';
		str_tmp = str_tmp +'<param name="FlashVars" value="videos=/images/videos/'+xml_file+'" />';
		str_tmp = str_tmp +'<param name="allowFullScreen" value="true" />';
		str_tmp = str_tmp +'<param NAME="wmode" VALUE="opaque" />';
		str_tmp = str_tmp + '<param name="allowScriptAccess" value="always">';
		str_tmp = str_tmp +'<embed src="/templates/widgets/plaPlayer3.swf" FlashVars="videos=/images/videos/file'+intID+'.xml" allowFullScreen="true" width="270" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		str_tmp = str_tmp +'</object>';
		//str_tmp = str_tmp +'</noscript>';
	}

	$('widgetMainVideo' + intID).innerHTML = str_tmp;
	//setTimeout(playMovieNow('videoPlayer'),500);
	playMovieNow('videoPlayer');

} //function




