//This is what you need to know about the JPMC Player... Most of what you need is on line 54
//vidFile = (flv.flv) --- This is the name of the video in which you are using
//ccFile =  (closedCaptions.xml) --- This is the name of the XML file being used
//lang = (Eng) --- This is the defualt language oyou wish to use for CC... if you were using a Spanish Video then the Esp would be defult
//audioOnly = false - This is if you are using only audio and no video...it will hide the viewbox of the video - false means Viewbox shown, true means no video viewbox

var HAS_VALID_FLASH_VERSION = false;

/* this defines a global variable HAS_VALID_FLASH_VERSION to display alternative content to flash*/
try{
 _flvs = new SWFObject("/corporate/includes/multimedia/login.swf", "login", "256px", "22px", "9");
 HAS_VALID_FLASH_VERSION = _flvs.installedVer.versionIsValid(_flvs.getAttribute("version"));
} catch(e){
 HAS_VALID_FLASH_VERSION = false;
}

function supports_html5_video() {
  return !!document.createElement('video').canPlayType;
}

function showHTML5Player(){
 var flv = $.query.get("flv");
	 if(!supports_html5_video){
		 return;
	 }
	 if(document.createElement('video').canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"')==""){
		 return;
	 }
	 /*
	 if(flv.indexOf(".flv")!=-1){
		 return;
	 }
	 */
	 var flv_name = flv.substring(flv.lastIndexOf("/")+1, flv.length-4);
	 var _flv_w = 550;
	 var _flv_h = 310;
	 if(flv_name.indexOf("4x3")!=-1){
		 _flv_h = 413;
	 }
	 var _vs = '<video poster="/corporate/includes/images/' + flv_name + '.jpg" width="' + _flv_w + '" height="' + _flv_h + '" controls="controls">';
	 _vs = _vs + '<source src="/corporate/includes/multimedia/' + flv_name + '.mp4" type="video/mp4" />';
	 _vs = _vs + '</video>';
	 $("#twfVideo").html(_vs);
}

function twfEmbedRelatedVideo(flv){
 try{
 var flv_name = flv.substring(flv.lastIndexOf("/")+1, flv.length-4);
 var fp_name = "/corporate/includes/multimedia/142375_changes_550x310.swf";
 var _flv_w = 550;
 var _flv_h = 360;
 if(flv_name.indexOf("4x3")!=-1){
	 fp_name = "/corporate/includes/multimedia/142375_changes_550x413.swf";
	 _flv_h = 463;
 }
 var fo = new SWFObject(fp_name, "index", _flv_w, _flv_h, "9", "#000000");
 fo.addParam("scale", "noscale");
 fo.addParam("salign","lt");
 fo.addParam("allowScriptAccess","always");
 fo.addParam("flashVars","vidFile=" + flv + "&ccFile=/corporate/includes/javascript/" + flv_name + ".js&lang=Eng&audioOnly=false");  
 fo.addParam('allowfullscreen', 'true');
 $("#twfVideo").html("");
 fo.write("twfVideo");
 } catch(e){
 }
}

function twfEmbedVideo(){
 try{
 var flv = $.query.get("flv");
 var flv_name = flv.substring(flv.lastIndexOf("/")+1, flv.length-4);
 var fp_name = "/corporate/includes/multimedia/142375_changes_550x310.swf";
 var _flv_w = 550;
 var _flv_h = 360;
 if(flv_name.indexOf("4x3")!=-1){
	 fp_name = "/corporate/includes/multimedia/142375_changes_550x413.swf";
	 _flv_h = 463;
 }
 var fo = new SWFObject(fp_name, "index", _flv_w, _flv_h, "9", "#000000");
 //var fo = new SWFObject("/corporate/includes/multimedia/jpmc_video_player_2011.swf", "index", "620", "350", "9", "#000000");
 fo.addParam("scale", "noscale");
 fo.addParam("salign","lt");
 fo.addParam("allowScriptAccess","always");
 fo.addParam("flashVars","vidFile=" + flv + "&ccFile=/corporate/includes/javascript/" + flv_name + ".js&lang=Eng&audioOnly=false");  
 fo.addParam('allowfullscreen', 'true');
 fo.write("twfVideo");
 findRelatedVideos(flv);
 } catch(e){
 }
}

function findRelatedVideos(flv){
 try{
 var _tag = "";
 var max_related = 3;
 var related_urls = [];
 
 $(".parent_video").each(function(n){ 
  var _href_val = $(this).find("a:first").attr("href");
  if(_href_val==flv){
   _tag = $(this).find("div[tag]").attr("tag");
  }
 });
 
 $(".parent_video").each(function(n){ 
  if($(this).find("div[tag]").attr("tag")!=_tag){
   $(this).empty();
  }
 });
 
 if(_tag!=""){
  $(".cig_news_item").each(function(n){
   if( related_urls.length<max_related ){
	var _obj = {};
	_obj._href = $(this).find("a:first").attr("href");
	_obj._id = $(this).find("a:first").attr("id") || "";
	_obj._img_src = $(this).find(".news_img").attr("src");
	_obj._title = $(this).find(".news_title a:first")[0].childNodes[0].nodeValue;
    related_urls.push(_obj);
   }
  });
 }
 
 //$(".cig_news_item").attr("style","display: none;");
 
 var _str_html = "<div class='more_videos'>MORE VIDEOS</div>";
 _str_html = _str_html + "<div class='more_videos_wrapper'>";
 var _counter_htm = 0;
 for(i=0; i<related_urls.length; i++){
  _counter_htm = _counter_htm + 1;
  _str_html = _str_html + "<div class='related_image_container'>";
  _str_html = _str_html + "<a id='" + related_urls[i]._id + "' pcg='' href='javascript: twfEmbedRelatedVideo(\"" + related_urls[i]._href + "\")' title='" + related_urls[i]._title + "'>";
  if(related_urls[i]._img_src){
   _str_html = _str_html + "<img src='" + related_urls[i]._img_src + "' />";
  } else {
   _str_html = _str_html + "<div style='height: 40px; width: 10px; position: relative; float: left;'></div>";
  }
  _str_html = _str_html + "</a>";
  _str_html = _str_html + "<div class='related_title'>";
  _str_html = _str_html + related_urls[i]._title;
  _str_html = _str_html + "</div>";
  _str_html = _str_html + "<div class='related_link'>";
  _str_html = _str_html + "<a id='" + related_urls[i]._id + "' pcg=''  class='watch_video' href='javascript: twfEmbedRelatedVideo(\"" + related_urls[i]._href + "\")'><img alt='watch video' src='/corporate/includes/images/watch_video_13x13.jpg'>Watch Video</a>";
  _str_html = _str_html + "</div>";
  _str_html = _str_html + "</div>";
 }
 _str_html = _str_html + "</div>";
 _str_html = _str_html + "<div class='see_more_videos'><a href='#'>See More Videos</a></div>";
 if(_counter_htm==0){
  _str_html = "";
 }
 
 $("#related_articles").html(_str_html);
 } catch(e){
 }
}

try{
 window.onbeforeunload = function(){top.redirectFromBackButtonCookie();};
}catch(e){
}

try{
 if(HAS_VALID_FLASH_VERSION){
  twfEmbedVideo();
 } else {
  showHTML5Player();
 }
}catch(e){
}
