// JavaScript Document

document.write('<link href="/flash/pavideo.css" rel="stylesheet" type="text/css" />');
document.write('<script type="text/javascript" src="/flash/flowplayer-3.2.2.min.js"></script>');

siteStandardMP4Type='video/mp4; codecs="avc1.58A01E, mp4a.40.2"';
transparentControls='\'backgroundColor\': \'transparent\',backgroundGradient: \'none\',sliderColor: \'#FFFFFF\',sliderBorder: \'1.5px solid rgba(160,160,160,0.7)\',volumeSliderColor: \'#FFFFFF\',volumeBorder: \'1.5px solid rgba(160,160,160,0.7)\',timeColor: \'#ffffff\',durationColor: \'#535353\',tooltipColor: \'rgba(255, 255, 255, 0.7)\',tooltipTextColor: \'#000000\'';

function pinkertonVideo(title,filename,ipod,wmv,wmvhq,mp4hq,skin,vidWidth,vidHeight,contTop,contLeft,contRight,contBottom)
{
	var dispWidth=0;
	var dispHeight=0;
	var onclickcode='';
	var vidhref='';
	var noEmbed=false;
if(typeof(paVideoSupport) !== 'undefined')
{
  
  if(paVideoSupport.h264){
	  contLeft=0;
	  contRight=0;
	  contTop=0;
	  contBottom=0;
	  startDiv(filename,title,(parseInt(contLeft)+parseInt(vidWidth)+parseInt(contRight)));
	  if(paVideoSupport.isMobile || !paVideoSupport.replaceOK){
		  mp4Embedhtml5(filename,parseInt(vidWidth),parseInt(vidHeight));
	  }else{ 
	  onclickcode='mp4Replacehtml5(\''+filename+'\','+(parseInt(contLeft)+parseInt(vidWidth)+parseInt(contRight))+','+(parseInt(contTop)+parseInt(vidHeight)+parseInt(contBottom))+')';
	  }
  }else if(paVideoSupport.getFlash()){
	  startDiv(filename,title,(parseInt(contLeft)+parseInt(vidWidth)+parseInt(contRight)));
	  if(paVideoSupport.replaceOK){
		  onclickcode='flowplayer(\'videoThumb'+filename+'\', \'/flash/flowplayer-3.2.2.swf\', {\'clip\':{\'url\':\'/flash/media/'+filename+'.mp4\',\'autoPlay\':true,\'autoBuffering\':false},\'plugins\':{\'controls\':{\'timeFontSize\':9,\'fullscreen\':false,\'mute\':false,\'fastforward\':false}}});';
		      /*onclickcode='flashReplace(\''+filename+'\',\''+skin+'\','+(parseInt(contLeft)+parseInt(vidWidth)+parseInt(contRight))+','+(parseInt(contTop)+parseInt(vidHeight)+parseInt(contBottom))+')';*/
	  }else{
		  onclickcode='window.open(\'/flash/media/'+filename;
		  if(paVideoSupport.OS='Mac'){
			  if (mp4hq>0.0){
				  onclickcode=onclickcode+'_hq.mp4\')';
			  }else{
				  onclickcode=onclickcode+'.mp4\')';
			  }
		  }else{
		      if (wmvhq>0.0){
				  onclickcode=onclickcode+'_hq.wmv\')';
			  }else{
				  onclickcode=onclickcode+'.wmv\')';
			  }
		  }
		  /*flashEmbed(filename,skin,(parseInt(contLeft)+parseInt(vidWidth)+parseInt(contRight)),(parseInt(contTop)+parseInt(vidHeight)+parseInt(contBottom)));*/
	  }
  }else{
	  noEmbed=true;
	  contLeft=0;
	  contRight=0;
	  contTop=0;
	  contBottom=0;
	  startDiv(filename,title,(parseInt(contLeft)+parseInt(vidWidth)+parseInt(contRight)));
	  switch (paVideoSupport.OS)
	  {
		  case "iPhone/iPod":
		    if (ipod>0.0){vidhref='/flash/media/'+filename+'.mp4';}else{vidhref='/flash/media/'+filename+'_hq.mp4';}
			break;
		  case "Mac":
		    if (mp4hq>0.0){vidhref='/flash/media/'+filename+'_hq.mp4';}else{vidhref='/flash/media/'+filename+'.mp4';}
			break;
		  case "Win":
		     if (wmvhq>0.0){vidhref='/flash/media/'+filename+'_hq.wmv';}else{ vidhref='/flash/media/'+filename+'.wmv';}
			break;
		  default:
		    if (wmvhq>0.0){vidhref='/flash/media/'+filename+'_hq.wmv';}else{ vidhref='/flash/media/'+filename+'.wmv';}
	  }
	  
  }
  
  if(paVideoSupport.isMobile & !noEmbed){
	 ipod=false;
	 wmv=false;
     hq=false;
  }
}else{
  noEmbed=true;
  contLeft=0;
  contRight=0;
  contTop=0;
  contBottom=0;
  startDiv(filename,title,(parseInt(contLeft)+parseInt(vidWidth)+parseInt(contRight)));
  if (wmvhq>0.0){vidhref='/flash/media/'+filename+'_hq.wmv';}else{ vidhref='/flash/media/'+filename+'.wmv';}
}
  if(onclickcode!='' | vidhref!='')
  {
   document.write('<div class="videoThumb" id="videoThumb'+filename+'" style="background-image: url(\'/flash/media/'+filename+'.jpg\');width:'+parseInt(vidWidth)+'px;height:'+parseInt(vidHeight)+'px;margin-left:'+contLeft+'px;margin-right:'+contRight+'px;margin-top:'+contTop+'px;margin-bottom:'+contBottom+'px;"><a class="videoPlay" style="margin-left:auto;margin-right:auto;top:'+((parseInt(vidHeight)/2)+parseInt(contTop)-61)+'px;"'); 
   if(onclickcode!=''){document.write(' onclick="'+onclickcode+'"');}
   if(vidhref!=''){document.write(' href="'+vidhref+'"');}
   document.write('></a></div>');
  }
  
  
  document.write('<div class="videoEnd"></div>');
  if(ipod>0.0 | wmv>0.0 | wmvhq>0.0 | mp4hq>0.0)
  {
	writeDownloads(filename,(parseInt(contLeft)+parseInt(vidWidth)+parseInt(contRight)),ipod,wmv,wmvhq,mp4hq);  
  }
  
  document.write('</div>');
  
}


function startDiv(filename,title,width){
	document.write('<div class="paVideo" id="paVideo'+filename+'" style="width:'+width+'px">');
if(title!='' & title!=false)
{
  if (title.indexOf('</')>=0) 
  {
   document.write(title);
  }else{
	document.write('<h2>'+title+'</h2>');  
  }
}	
}

function mp4Replacehtml5(filename,width,height)
{
	var newDiv = document.createElement("div");
	newDiv.setAttribute("height",height);
	newDiv.setAttribute("width",width);
	newDiv.setAttribute("class","paVideoContainer");
	newDiv.innerHTML='<video src="/flash/media/'+filename+'.mp4" poster="/flash/media/'+filename+'.jpg" controls="controls" type="'+siteStandardMP4Type+'" autoplay="autoplay" width="'+width+'" height="'+height+'"></video>';

    var para = document.getElementById("paVideo"+filename);
    var divElm = document.getElementById("videoThumb"+filename);
    var replaced = para.replaceChild(newDiv,divElm);
}

function mp4Embedhtml5(filename,width,height)
{
		document.write('<video src="/flash/media/'+filename+'.mp4" poster="/flash/media/'+filename+'.jpg" controls="controls" preload="none" type="'+siteStandardMP4Type+'" width="'+width+'" height="'+height+'"></video>');
}

function flashReplace(filename,skin,width,height)
{
	var newDiv = document.createElement("div");
	newDiv.setAttribute("height",height);
	newDiv.setAttribute("width",width);
	newDiv.setAttribute("class","paVideoContainer");
    newDiv.innerHTML='<style type="text/css">#FLVPlayer {visibility:visible;}</style><script src="/flash/swfobject_modified.js" type="text/javascript"></script><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+width+'" height="'+height+'" id="FLVPlayer"> <param name="movie" value="/flash/FLVPlayer_Progressive.swf" /> <param name="quality" value="high"> <param name="wmode" value="opaque"> <param name="scale" value="noscale"> <param name="salign" value="lt"> <param name="FlashVars" value="&amp;MM_ComponentVersion=1&amp;skinName=/flash/'+skin+'&amp;streamName=/flash/media/'+filename+'&amp;autoPlay=true&amp;autoRewind=false" /> <param name="swfversion" value="8,0,0,0"> <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. --> <param name="expressinstall" value="/flash/expressInstall.swf"> <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. --> <!--[if !IE]>--> <object type="application/x-shockwave-flash" data="/flash/FLVPlayer_Progressive.swf" width="'+width+'" height="'+height+'"> <!--<![endif]--> <param name="quality" value="high"> <param name="wmode" value="opaque"> <param name="scale" value="noscale"> <param name="salign" value="lt"> <param name="FlashVars" value="&amp;MM_ComponentVersion=1&amp;skinName=/flash/'+skin+'&amp;streamName=media/'+filename+'&amp;autoPlay=true&amp;autoRewind=false" /> <param name="swfversion" value="8,0,0,0"> <param name="expressinstall" value="/flash/expressInstall.swf"> <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. --> <div> <h4>Content on this page requires a newer version of Adobe Flash Player.</h4> <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p> </div> <!--[if !IE]>--> </object> <!--<![endif]--> </object><script type="text/javascript">swfobject.registerObject("FLVPlayer");</script>';
	
	var para = document.getElementById("paVideo"+filename);
    var divElm = document.getElementById("videoThumb"+filename);
    var replaced = para.replaceChild(newDiv,divElm);
}

function flashEmbed(filename,skin,width,height)
{
    document.write('<style type="text/css">#FLVPlayer {visibility:visible;}</style><script src="/flash/swfobject_modified.js" type="text/javascript"></script><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+width+'" height="'+height+'" id="FLVPlayer"> <param name="movie" value="/flash/FLVPlayer_Progressive.swf" /> <param name="quality" value="high"> <param name="wmode" value="opaque"> <param name="scale" value="noscale"> <param name="salign" value="lt"> <param name="FlashVars" value="&amp;MM_ComponentVersion=1&amp;skinName=/flash/'+skin+'&amp;streamName=/flash/media/'+filename+'&amp;autoPlay=false&amp;autoRewind=false" /> <param name="swfversion" value="8,0,0,0"> <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. --> <param name="expressinstall" value="/flash/expressInstall.swf"> <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. --> <!--[if !IE]>--> <object type="application/x-shockwave-flash" data="/flash/FLVPlayer_Progressive.swf" width="'+width+'" height="'+height+'"> <!--<![endif]--> <param name="quality" value="high"> <param name="wmode" value="opaque"> <param name="scale" value="noscale"> <param name="salign" value="lt"> <param name="FlashVars" value="&amp;MM_ComponentVersion=1&amp;skinName=/flash/'+skin+'&amp;streamName=media/'+filename+'&amp;autoPlay=false&amp;autoRewind=false" /> <param name="swfversion" value="8,0,0,0"> <param name="expressinstall" value="/flash/expressInstall.swf"> <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. --> <div> <h4>Content on this page requires a newer version of Adobe Flash Player.</h4> <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p> </div> <!--[if !IE]>--> </object> <!--<![endif]--> </object><script type="text/javascript">swfobject.registerObject("FLVPlayer");</script>');
}

function writeDownloads(filename,width,ipod,wmv,wmvhq,mp4hq)  
{
	
	document.write('<div class="videoLink" style="width:'+width+'px;"><p>Download Video: ');
	
	if(ipod>0.0)
	{
		document.write('<a href="/flash/media/'+filename+'.mp4">Small&nbsp;(mp4/iPod');
		if(ipod!=true){document.write('&nbsp;'+ipod+'MB) ');}
		document.write('</a>');
	}
	if(wmv>0.0)
	{
		document.write('<a href="/flash/media/'+filename+'.wmv">Small&nbsp;(wmv');
		if(wmv!=true){document.write('&nbsp;'+wmv+'MB) ');}
		document.write('</a>');
	}
	if(wmvhq>0.0)
	{
		document.write('<a href="/flash/media/'+filename+'_hq.wmv">Large&nbsp;(wmv');
		if(wmvhq!=true){document.write('&nbsp;'+wmvhq+'MB) ');}
		document.write('</a>');
	}
	if(mp4hq>0.0)
	{
		document.write('<a href="/flash/media/'+filename+'_hq.mp4">Large&nbsp;(mp4');
		if(mp4hq!=true){document.write('&nbsp;'+mp4hq+'MB) ');}
		document.write('</a>');
	}
	document.write('</p></div>');
	
}

if(typeof(paVideoSupport) == 'undefined')
{
var paVideoSupport = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
		this.h264=this.geth264();
		this.isMobile=this.getMobile();
		this.replaceOK=this.checkReplace();
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	 getMobile: function() {
		 if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('Android') != -1)) {return true;}else{return false;}
	},
	 geth264: function() {
		var t=''
		try{
		  var v = document.createElement("video");
		  t = v.canPlayType(siteStandardMP4Type);
		}catch(err){t='error';}
		if((t=='probably' | t=='maybe') & this.browser!='Explorer'){return true;}else{return false;}
	},
	checkReplace: function() {
		return true;
	},
	getFlash: function() {
		var retV=false;
		try{
		  retV=DetectFlashVer(8, 0, 0);
		}catch(err){}
		return retV;
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.userAgent,
			subString: "iPhone",
			identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
paVideoSupport.init();
}


// Flash Player Version Detection - Rev 1.6
// 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];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			//alert("flashVer="+flashVer);
		}
	}
	// 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;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}
