// JavaScript Document

function launchImage(theURL,Width,Height){
	  var Scrollbars = "no";
	  if(screen.height<Height){
	  var Height = (screen.height-200);
	  var Scrollbars = "yes";
	  }
	  
	  if(screen.width<Width){
	  var Width = (screen.width-200);
	  var Scrollbars = "yes";
	  }
	  else{
	  var Width = Width;
	  }
	  var Left = (screen.width-Width)/2;
	  var Top = (screen.height-Height)/2;
	  var params = ('toolbar=no,scrollbars=' + Scrollbars + ',resizable=no,left=' + Left +',top=' + Top +',width=' + Width + ',height=' + Height);
	  
	Pop = window.open(theURL, "LaunchImage", params);
	
	Pop.focus();
}
function launch(URL) {
        
		var Width = (screen.width-(screen.width/50)); 
		var Height = (screen.height-(screen.height/10));
	    var params = ('toolbar=no,scrollbars=Yes,left=0,top=0,resizable=yes,width=' + Width + ',height=' + Height);
		pop = window.open(URL, 'newWindow', params);
		pop.focus();
	}


function getControlIcon(action,style){
	var imgTag = '<img src="../_media/graphics/icons/'+style+action+'.gif" border=\"0\" />';
	//alert(imgTag);
	return imgTag;
	
}

function getControls(style){

	var embedThis = '<a href="Javascript:PlayClick();">'+getControlIcon('Play',style)+'</a>';
	embedThis += '<a href="Javascript:StopClick();">'+getControlIcon('Stop',style)+'</a>';	
	embedThis += '<a href="Javascript:PauseClick();">'+getControlIcon('Pause',style)+'</a>';
	embedThis += '<a href="Javascript:MuteAudioClick();">'+getControlIcon('Mute',style)+'</a>';
	return embedThis;
}	
	
function renderReal(file,width,height,style){
	if (pluginlist.indexOf("RealPlayer")!=-1){
	
	} else {
		var p=window.confirm("RealPlayer is required to view this video Click okay to Launch Real Player Download Page")
		if (p){
		window.open('http://www.real.com/realcom/R?href=http%3A%2F%2Fforms.real.com%2Freal%2Fplayer%2Fdownload.html');
		} else {
		alert("Real Player is required to view this Video, Please visit real.com when you are ready to download the plug-in")
		}
		
	}
	var embedThis = '<embed controls="ImageWindow" type="audio/x-pn-realaudio-plugin"src=\''+file+'\' width="'+width+'" height='+height+' autostart="TRUE" name="MediaPlayer" console="theclip"></embed>';
	embedThis += getControls(style);
//	alert(embedThis);
	document.getElementById("player").innerHTML = embedThis;
}
function renderMov(file,width,height){
	var embedThis = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="465" height="340" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0" align="middle" >';
	embedThis += '<param name="src" value="'+file+'" />';
	embedThis += '<param name="autoplay" value="true" />';
	embedThis += '<embed controls="all" name="MediaPlayer" src="'+file+'" width="'+width+'" height='+height+' pluginspage=http://www.apple.com/quicktime/download/ align="middle" autoplay="true" bgcolor="black" ></embed></object>';
	
	document.getElementById("player").innerHTML = embedThis;
}
function renderMP4(file,width,height){
	renderMov(file,width,height);
}
function renderWMV(file,width,height){
	var embedThis = '<object id="MediaPlayer" width=465 height=340 classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components…" type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">';
	embedThis += '<param name="filename" value="'+file+'">';
	embedThis += '<param name="Showcontrols" value="True">';
	embedThis += '<param name="autoStart" value="True">';
	//embedThis += '<PARAM name="controls" value="all">';
	embedThis += '<embed type="application/x-mplayer2" src="'+file+'" name="MediaPlayer" width="'+width+'" height='+height+'></embed>';
	
	document.getElementById("player").innerHTML = embedThis;
}

function renderFlash(file,width,height){

	
	
	
// <![CDATA[
var fo = new SWFObject("|||relRoot|||_media/flash/video-player.swf", "FlowPlayer", width, height, "7", "#ffffff", true);
// need this next line for local testing, it's optional if your swf is on the same domain as your html page
fo.addParam("allowScriptAccess", "always");
fo.addVariable("config", "{ fullScreenScriptURL: 'http://powersimple.com/flowplayer/fullscreen.js?id=12', showPlayListButtons: true, playList: [ {overlayId: 'play' }, { url: '"+file+"' } ], initialScale: 'fit' }");
fo.write("player");// ]]\]

}
function showVideo(file,fileType,width,height,style){
	
	document.getElementById("playerHolder").className = style;
	
	if(fileType == 'flv'){
		
		
			var ready = false;
			var version = parseInt(GetSwfVer());
			var neededVersion = "Flash Player is required";
			//alert("v"+version);
			if (pluginlist.indexOf("Flash")!=-1){
				
				if(version >= 8){
					ready = true;	
				} else {
				var neededVersion = "An updated version of your Flash Player is required";
				}	
			}
			
			if(!ready){
				var p=window.confirm(neededVersion + " to view this video Click okay to Adobe Flash Player Download Page")
				if (p){
				window.open('http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player.exe');
				} else {
				alert(neededVersion + "to view this Video, Please visit adobe.com when you are ready to download the plug-in");
				}
			} else {
				renderFlash(file,width,height);
			}
		
	} else if(fileType == 'rm'){
		renderReal(file,width,height,style);
	} else if(fileType == 'mov'){
		renderMov(file,width,height);
	} else if(fileType == 'mp4'){
		renderMP4(file,width,height);
	} else if(fileType == 'wmv'){
		renderWMV(file,width,height);
	} else {}
	if(document.all){
		alert(document.getElementById("playerHolder").className);
	}

}
/*
function formats(file,fileType,width,height,formatList,path){
	l = formatList.split(",");
	formats = '<ul class="formats">';
	for(f in l){
		formats += '<li class="formatIcon"><a href="Javascript:showVideo('+file+','+fileType+','+width+','+height+');">'+f<img src="'+path+'_media/graphics/icons/'+f[l]+'.gif"></a></i>';
	}
	formats += '</ul>';
	document.getElementById('formatListIcons').innerHTML = formats;
	alert(formats);
	
}
*/
//document.getElementById("player").innerHTML = '';

var agt=navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);

if (ie && win) {	pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") + detectIE("SWCtl.SWCtl.1","Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") + detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") + detectIE("PDF.PdfCtrl.5","Acrobat Reader"); }
if (ns || !win) {
		nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
		pluginlist = detectNS("image/svg-xml","SVG Viewer") + detectNS("application/x-director","Shockwave Director") + detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin","RealPlayer") + detectNS("video/quicktime","QuickTime") + detectNS("application/x-mplayer2","Windows Media Player") + detectNS("application/pdf","Acrobat Reader");
}

function detectIE(ClassID,name) { result = false; document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); if (result) return name+','; else return ''; }
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }

pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);


//SAMPLE USAGE- detect "Flash"
//if (pluginlist.indexOf("Flash")!=-1)
//document.write("You have flash installed")
// Flash Player Version Detection - Rev 1.5
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;			
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

function mooBox(url, caption, dimensions){
	MOOdalBox.open(url, caption, dimensions);
}