// full program video player and an embeddable version too

var v_players = new Array();

function v_embplay (targetvideoid, targetplayer){
	if(targetplayer == undefined){
		targetplayer = 'elplayer';
	}
	var thisplayer;
	for(var x = 0; x < v_players.length; x++){
		if(v_players[x].id = targetplayer){
			thisplayer = v_players[x].player;
		}
	}
	if(thisplayer.covemode){
		$("#commManagerDiv").remove();
		$("#npaplayer").remove();
	}
	$("#v_main").html('');
	$("#" + thisplayer.divtarget).html('');
	thisplayer.currentvideoid = targetvideoid;
	thisplayer.autoplay = true;
	thisplayer.initialise();
}

function v_seekpoint (targetseekpoint, targetplayer){
	if(targetplayer == undefined){
		targetplayer = 'elplayer';
	}
	var thisplayer;
	for(var x = 0; x < v_players.length; x++){
		if(v_players[x].id = targetplayer){
			thisplayer = v_players[x].player;
		}
	}
	if(thisplayer.covemode){
		thisplayer.player_module.playoffset(targetseekpoint);
	}
}

function v_chapter (seekchapter){
	var thisplayer;
	for(var x = 0; x < v_players.length; x++){
		thisplayer = v_players[x].player;
	}
	thisplayer.playchapter(seekchapter);
}

function v_fp (inarray) {
	this.timerinc = 0;
	this.covemode = false;
	this.ipadmode = false;
	this.mobilemode = false;
	this.chapteridx = 0;
	this.intcnt = 5;
	this.overlayon = false;
	this.loginterval = 60;
	this.relloader = 0;
	this.chaptercount = 0;
	this.showingchapteridx = -1;
	this.chaptercode = '';
	this.chaptersplotted = false;
	this.prepared = false;
	this.relatedrendered = false;
	this.externalexcerpt = false;
	this.embinfoup = false;
	this.firstrun = true;
	this.autoplay = false;
	this.showingchapter = false;
	this.commentobj = new Object();
	this.overrideshare = (inarray.sharedisable != undefined)? inarray.sharedisable:false;
	this.relup = false;
	this.reltimer = 0;
	var playerreg = new Object();
	this.iframemode = (inarray.iframemode != undefined)? inarray.iframemode:false;
	this.iframeupdate = (inarray.iframeupdate != undefined)? inarray.iframeupdate:'';
	this.playerid = (inarray.idcode != undefined)? inarray.idcode:'elplayer';
	playerreg.id = this.playerid;
	playerreg.player = this;
	v_players.push(playerreg);
	this.nocove = (inarray.nocove != undefined)? inarray.nocove:false;
	this.dvdlink = (inarray.dvdlink != undefined)? inarray.dvdlink:'';
	this.ituneslink = (inarray.ituneslink != undefined)? inarray.ituneslink:'';
	this.overridetitle = (inarray.overridetitle != undefined)? inarray.overridetitle:'';
	this.startscript = (inarray.startscript != undefined)? inarray.startscript:''; // this is for modes 2 + 3, expanding mode
	this.chdata = (inarray.chapter_data != undefined)? inarray.chapter_data:''; // this is for mode 3, chapter data listener
	this.chupd = (inarray.chapter_updates != undefined)? inarray.chapter_updates:''; // this is for mode 3, chapter change listener
	this.thumbnailoverride = (inarray.overridethumbnail != undefined)? inarray.overridethumbnail:'';
	this.startscriptrun = false;
	this.fakeurl = (inarray.fakeurl != undefined)? inarray.fakeurl:'';
	this.overridetimes = (inarray.override != undefined)? inarray.override:false;
	this.modecode = (inarray.mode != undefined)? inarray.mode:1; // 0: embed, 1: full show, 2: full show (smaller), 3: full show (chromeless), 4: external embed
	this.starttime = (inarray.starttime != undefined)? (inarray.starttime * 1000):0;
	this.endtime = (inarray.endtime != undefined)? (inarray.endtime * 1000):0;
	this.admode = (inarray.admode != undefined)? inarray.admode:false;
	this.currentvideoid = (inarray.videoid != undefined)? inarray.videoid:'';
	this.related = (inarray.related != undefined)? inarray.related:true;
	this.replayonly = (inarray.replayonly != undefined)? inarray.replayonly:false;
	this.fullshow = (inarray.fullshow != undefined)? inarray.fullshow:false;
	this.workaround = false;
	if(this.modecode == 1 || this.modecode == 2 || this.modecode == 3){
		this.fullshow = true;
	}
	if(this.modecode == 4 && this.currentvideoid.indexOf('@') != -1){
		this.overridetimes = true;
		this.externalexcerpt = true;
		var splits = this.currentvideoid.substring(this.currentvideoid.indexOf('@') + 1,this.currentvideoid.length)
		var x = splits.split('.');
		this.starttime = parseInt(x[0],16) *1000;
		this.endtime = parseInt(x[1],16) *1000;
		this.currentvideoid = this.currentvideoid.substring(0,this.currentvideoid.indexOf('@'));
	}
	if(this.modecode == 4 && this.currentvideoid.indexOf('*') != -1){
		this.workaround = true;
	}
	this.w = (inarray.w != undefined)? inarray.w:512; // width, only used in embeds
	this.h = (inarray.h != undefined)? inarray.h:288; // height, only used in embeds
	this.isopen = false;
	this.divtarget = (inarray.divtarget != undefined)? inarray.divtarget:'videospace';
	this.stayopen = (inarray.stayopen)? inarray.stayopen:false;
	if(this.modecode != 1){
		this.stayopen = true;
	}
	this.draw=v_fp_draw;
	this.pbsproblems = 0;
	this.embedcode=v_fp_embedcode;
	this.embedcodeclose=v_fp_embedcodeclose;
	this.embedcodechange=v_fp_embedcodechange;
	this.fauxstartmode = false;
	this.ext_chupdate=v_fp_chapterdatupdate;
	this.ext_chdata=v_fp_chdata;
	this.toggle=v_fp_toggle;
	this.outerresize=v_fp_outerresize;
	this.initialise=v_fp_initialise;
	this.social=v_fp_social;
	this.playchapter=v_fp_play;
	this.player = new Object();
	this.ended=v_fp_ended;
	this.covechapterupd=v_fp_covech;
	this.timerstop=v_fp_timerstop;
	this.timerstart=v_fp_timerstart;
	this.legacytimerstart=v_fp_legacytimerstart;
	this.embinfo=v_fp_embinfo;
	this.commentscount=v_fp_commentscount;
	this.timerupd=v_fp_timerupd;
	this.legacychapterchange=v_fp_legacychapterdetect;
	this.relatedrender=v_fp_relatedrender;
	this.chapterupdate=v_fp_chapterupdate;
	this.overlayon=v_fp_overlayshow;
	this.overlayhide=v_fp_overlayhide;
	this.pbsissues=v_fp_issues;
	this.relchangeable=true;
	this.relatedclick=v_fp_relatedclick;
	this.relatedhighlight=v_fp_relatedhighlight;
	this.clipinfo=v_fp_clipinfo;
	this.prepare=v_fp_prepare;
	this.show_when_ready=v_fp_show_when_ready;
	this.show=v_fp_show;
	this.embrelated_up=v_emb_relatedup;
	this.embrelated_down=v_emb_relateddown;
	this.current_video=v_fp_current_video;
	this.cachedinfo = new Object();
	this.loadchecker=v_fp_directloadcheck;
	this.server = Object.beget(flp_comm);
	this.video = Object.beget(flp_video);
	this.videorendered = false;
	this.currentrel = -1;
	this.closedheight = (inarray.closedheight != undefined)? inarray.closedheight:30;
	this.openheight = (inarray.openheight != undefined)? inarray.openheight:435;
	this.restmode = false;
	this.reststart = 0;
	if(!this.related){
		this.openheight = this.openheight - 125;
	}
	if(navigator.userAgent && navigator.userAgent.indexOf('iPad') != -1){
		ipadmode = true;
		mobilemode = true;
		this.openheight -= 32;
	}
	if(!this.stayopen && this.modecode == 1){
		this.autoplay = true;
	}
	if(window.location.href.indexOf('?autoplay') != -1 || window.location.href.indexOf('&autoplay') != -1){
		this.autoplay = true;
		this.stayopen = true;
	}
	if(navigator.userAgent && navigator.userAgent.indexOf('iPhone') != -1){
		mobilemode = true;
		this.openheight -= 32;
	}
	if(this.stayopen){
		this.initialise();
	} else {
		this.draw();	
	}
}

function v_fp_chdata (chapters){
	if(this.chdata != undefined && this.chdata != ''){
		this.chdata.call(this,chapters);
	}
}

function v_fp_chapterdatupdate (chapteridx){
	if(this.chupd != undefined && this.chupd != ''){
		this.chupd.call(this,chapteridx);
	}
}

function v_fp_initialise () {
	this.video.clean();
	this.video.parse_video_id(this.currentvideoid).get_data_from_server(this.server);
	this.loadcheck = new Number();
	this.loadcheck = setInterval(this.loadchecker,500);
}


function v_fp_prepare (vidid,autoplay) {
	this.playlist = new Array();
		this.playlist.push(this.video);
//	this.autoplay = autoplay;
	this.player_module = Object.beget(flp_player);
	this.show_when_ready();
}

function v_fp_outerresize (inar) {
	var targetitem = this.divtarget;
	var newcss = new Array();
	if(inar.height != undefined){
		newcss.height = inar.height + 'px';
	}
	if(inar.width != undefined && this.modecode != 0){
		newcss.width = inar.width + 'px';
	}
	if(iframemode){
		this.iframeupdate.call();
	}
	$("#" + targetitem).css(newcss);
}

function v_fp_social () {
	var promourl = window.location.href;
	if(promourl.indexOf('/wgbh/pages/frontline/') != -1){
		var workstring = promourl.substring(promourl.indexOf('/wgbh/pages/frontline/') + 22, promourl.length);
		var ws = workstring.split("/");
		promourl = 'http://www.pbs.org/wgbh/pages/frontline/' + ws[0];
	}
	outp = '<iframe src="http://www.facebook.com/plugins/like.php?href=' + encodeURIComponent(promourl) + '&amp;layout=button_count&amp;show_faces=false&amp;width=120&amp;action=recommend&amp;font=lucida+grande&amp;colorscheme=light&amp;height=20" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:120px; height:20px;" allowTransparency="true"></iframe>';
	outp += '<span style="margin-top: 8px; display: block"></span><iframe src="http://api.tweetmeme.com/button.js?url=' + encodeURIComponent(promourl) + '&amp;source=frontlinepbs&amp;style=compact&amp;service=bit.ly" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:20px;" allowTransparency="true"></iframe>';
	return outp;
}

function v_fp_embinfo () {
	var v = this.current_video();
	if(this.externalexcerpt || (this.overridetitle && (this.modecode == 2 || this.modecode == 3 || this.modecode == 0))){
		if(this.externalexcerpt){
			if((this.endtime - this.starttime) > 1000000){
				this.overridetitle = v.pkg_title;
			} else {
				this.overridetitle = "From <i>" + v.pkg_title + "</i>";
			}
		}
		if(this.overridetimes){
			$("#v_embinfo").html('<span class="title" style="font-weight: normal">' + this.overridetitle + '</span><span class="length">(' + v_secformat((this.endtime / 1000) - (this.starttime / 1000)) + ')</span>');
		} else {
			if(this.modecode == 2 || this.modecode == 3){
				$("#v_embinfo").html('<span class="title">' + this.overridetitle + '</span>');
			} else {
				$("#v_embinfo").html('<span class="title" style="font-weight: normal">' + this.overridetitle + '</span><span class="length">(' + v_secformat(v.seg_length) + ')</span>');
			}
		}
	} else {
		if(this.overridetimes){
			$("#v_embinfo").html('<span class="title">' + v.seg_title + '</span>' + v.seg_desc + ' <span class="length">(' + v_secformat((this.endtime / 1000) - (this.starttime / 1000)) + ')</span>');
		} else {
			$("#v_embinfo").html('<span class="title">' + v.seg_title + '</span>' + v.seg_desc + ' <span class="length">(' + v_secformat(v.seg_length) + ')</span>');
		}
	}
	if(this.w < 350){
		$("#v_embinfo").css({ 'font-size': '12px', 'line-height': '13px' });
	}
	var subthis = this;
	$("#v_embinfo").fadeIn("slow");
	embinfoup = true;
}

function v_emb_relatedup (idx,tim) {
	if((this.video.related_content[idx].tim + 11) > tim){
		this.currentrel = idx;
		this.video.related_content[idx].fired = true;
		clearTimeout(this.reltimer);
		var subthis = this;
		$("#v_embrel").stop();
		$("#v_embrel").css({ 'opacity': 1, 'width': ($("#v_embp").width() - 8) + 'px' });
		$("#v_embrel").html(this.video.related_content[idx].lbl + ' <span class="ar">&#187;</span>');
		$("#v_embrel").fadeIn("slow");
		$("#v_embrel").click(function () {
			subthis.relatedclick(subthis.currentrel,1);
		});
		$("#v_embrel").mouseenter( function () {
			clearTimeout(subthis.reltimer);
		});
		$("#v_embrel").mouseleave( function () {
				var nt = subthis.player_module.timerupdate();
				var timerleft = ((subthis.video.related_content[subthis.currentrel].tim + 12) - nt) * 1000;
				if(timerleft < 4000){
					timerleft = 4000;
				}
				subthis.reltimer = setTimeout(subthis.embrelated_down, timerleft);
		});
		this.reltimer = setTimeout(subthis.embrelated_down, 12000);
		relup = true;
	}
}

function v_emb_relateddown () {
	relup = false;
	$("#v_embrel").stop();
	$("#v_embrel").unbind("click");
	$("#v_embrel").unbind("mouseenter");
	$("#v_embrel").unbind("mouseleave");
	$("#v_embrel").fadeOut("slow");
	clearTimeout(this.reltimer);
	this.video.related_content[this.currentrel].fired = false;
}


function v_fp_ended () {
	if(mobilemode && this.fullshow && (this.chapteridx < (this.chaptercount - 1))){
		this.chapteridx++;
		this.video.upd_chapter((this.chapteridx + 1));
		this.relatedrendered = false;
		$("#v_relarea").animate({ 'opacity':0 });
		this.clipinfo();	
		chapterupdate(this.chapteridx, true);
	} else {
		if(!this.overylayon){
			if(!(this.player_module.mode == 'npa' && this.modecode != 1)){
				this.overlayon();
			}
			if(this.showingchapter){
				this.hidechapterinfo();
			}
	
			var nt = this.player_module.timerupdate();
			var extlog = (this.modecode == 4)? 1:0;
			this.server.sendlog(this.video,nt,extlog);
			this.timerstop();
			$("#v_replay").show();
			var subthis = this;
			this.firstrun = true;
			
			if(this.modecode == 1){
				if(replayonly){
					$("#v_endrel").hide();
					$("#v_replay").css({ 'float':'none', 'margin-left': (($("#v_fp").width() / 2) - 75) + 'px' });
				} else {
					if(_catmap[_cat] != undefined){
							_catcode = _catmap[_cat];
							// get related shows
							$.ajax({
							type: "GET",
							url:  "/wgbh/pages/frontline/xml/cats/" + _catcode + "_v.xml",
							dataType: "xml",
							success: function(xml) {
								var cnt = Math.floor(($("#v_fp").width() - 220) / 210);
								var embedded = $(xml).find('bod').text();
								$("#v_endrel").html('<span class="v_endreltitle">RELATED FRONTLINE REPORTS</span>' + embedded);
								$("#v_relshows").find('div').each(function () {
									if($(this).attr('ptit') == subthis.video.pkg_title || cnt == 0){
										$(this).remove();
									} else {
										cnt--;
									}
								});
								$("#v_relshows").fadeIn();
							}
						});	
			
					}
	
				}
			} else {
				$("#v_endrel").hide();
				if(this.player_module.mode != 'npa'){
					if(this.modecode == 4){
						$("#v_replay").css({ 'margin-top': (((this.h) / 2) - 45) + 'px' });
						var social = '';
						var promourl = this.video.seg_link;
						if(promourl.substring(promourl.length - 1,promourl.length) == '/'){
							promourl = promourl.substring(0,promourl.length - 1);
						}
						$("#v_embsocial").html('<div class="scl"><iframe src="http://api.tweetmeme.com/button.js?url=' + encodeURIComponent(promourl) + '&amp;style=compact&amp;source=frontlinepbs&amp;service=bit.ly" scrolling="no" frameborder="0" style="border:none; margin: 0; overflow:hidden; width:100px; height:30px;" allowTransparency="true"></iframe><iframe src="http://www.facebook.com/plugins/like.php?href=' + encodeURIComponent(promourl) + '&amp;show_faces=false&amp;width=150&amp;layout=button_count&amp;action=recommend&amp;font=lucida+grande&amp;colorscheme=light&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:150px; height:30px;" allowTransparency="true"></iframe>');
						$("#v_continue").css({ 'text-align':'left' });
						if(this.externalexcerpt){
							var comout = '<a href="' + this.video.seg_link + '?utm_campaign=videoplayer&utm_medium=embplayer&utm_source=continuelink" style="color: #ff0000;" target="_new"><span class="v_contimg"></span></a>';
							$("#v_contmsg").html(comout);
							$("#v_contmsg").css({ "top": ((this.h / 2) - 65) + 'px', 'width': (this.w - 150) + 'px' });
							$("#v_contmsg").fadeIn();
						}
						if(this.commentobj.airdate){
							if(this.commentobj.upcoming){
								$("#v_embend").css({ "margin-top": ((this.h / 2) - 25) + 'px' });
								$("#v_embend").html('Watch on air and online starting ' + this.commentobj.airdate + '. <a href="http://www.pbs.org/wgbh/pages/frontline/programs/pbsv.html" target="links">Check local listings &#187;</a>');
							} else {
								if(this.w > 500){
									$("#v_embend").css({ "margin-top": '25px' });
								} else {
									$("#v_embend").css({ "margin-top": '15px' });
								}
								var comout = new String();
								if(this.commentobj.comments.length > 1 && !this.externalexcerpt){
									comout += '<span class="v_comtitle">COMMENTS (' + this.commentobj.commentcount + ')</span><ul>';
									var maxreached = false;
									for(var x = 0; x < this.commentobj.comments.length && !maxreached; x++){
										if(x > 2){
											maxreached = true;
										}
										if(x > 0 && this.w < 340){
											maxreached = true;
										}
										if((x > 1 || (this.commentobj.comments[x].message.length > 60)) && (this.w < 400 && this.w > 340)){
											maxreached = true;
										}
										comout += (maxreached)? '':'<li>&quot;' + this.commentobj.comments[x].message + '&quot;<span class="v_comperson">' + this.commentobj.comments[x].person + '</span></li>';
									}
									comout += '</ul><a href="' + this.commentobj.commentslink + '" target="links" title="Read more comments" class="v_commore">ADD YOUR COMMENT &#187;</a>';
								}
								$("#v_embend").html(comout);
							}
							$("#v_embend").css({ 'width': (this.w - 150) + 'px' });
							$("#v_embend").show();
						}
						var xfactor = (this.player_module.mode == 'cove')? 0:36;
						$("#v_embsocial").css({ "margin-top": (this.h - xfactor) + 'px', "width": (this.w - 6) + 'px' });
					} else {
						$("#v_replay").css({ 'margin-top': (((this.h) / 2) - 90) + 'px', 'margin-left': (($("#v_embp").width() / 2) - 75) + 'px' });
					}
				} else {
					$("#v_replay").remove();
				}
			}
			
			if($("#v_replay")){
	
				$("#v_replay").unbind("click");
				$("#v_replay").click(function (){
					if(subthis.modecode == 1 || subthis.modecode == 2){
						if(window.location.href.indexOf('autoplay') != -1){
							window.location.reload();
						} else {
							window.location.href = window.location.href + '?autoplay';
						}
					} else {
						$("#v_replay").unbind("click");
						subthis.autoplay = true;
						subthis.initialise();
					}
				});
			}

		}
	}
}

function v_fp_overlayshow (progress,immediate) {
	if(this.modecode == 1){
		$("#v_continue").css({ 'width' : ($("#v_fp").width() - 20) + 'px', 'height' : (this.openheight - 120) + 'px'});
		$("#v_continueback").css({ 'width' : $("#v_fp").width() + 'px', 'height' : this.openheight + 'px'});
	} else {
		var hoh = (this.player_module.mode == "npa")? 32:0;
		if(this.modecode == 0 || this.modecode == 2  || this.modecode == 3){
			if(this.modecode == 0){
				$("#v_continue").css({ 'width' : ($("#v_embp").width() - 20) + 'px', 'height' :( $("#v_embp").height() - hoh) + 'px'});
				$("#v_continueback").css({ 'width' : $("#v_embp").width() + 'px', 'height' : ($("#v_embp").height() ) + 'px'});
			} else {
				if(this.modecode == 3){
					$("#v_continue").css({ 'width' : ($("#v_embp").width() - 20) + 'px', 'height' : $("#v_embp").height() + 'px'});
					$("#v_continueback").css({ 'width' : $("#v_embp").width() + 'px', 'height' : $("#v_embp").height() + 'px'});
				} else {
					hoh += 10;
					$("#v_continue").css({ 'width' : ($("#v_embp").width() - 20) + 'px', 'height' :( $("#v_embp").height() - hoh) + 'px'});
					$("#v_continueback").css({ 'width' : $("#v_embp").width() + 'px', 'height' : ($("#v_embp").height() - 40) + 'px'});
				}
			}
		} else {
			if(this.modecode == 4){
				$("#v_continue").css({ 'width' : $("#v_embp").width() + 'px', 'height' :( $("#v_embp").height() - (hoh + 30)) + 'px', 'margin-top': '30px' });
				$("#v_continueback").css({ 'width' : $("#v_embp").width() + 'px', 'height' : ($("#v_embp").height() - 60) + 'px', 'margin-top': '30px' });
			} else {
				$("#v_continue").css({ 'width' : $("#v_embp").width() + 'px', 'height' :( $("#v_embp").height() - (hoh + 30)) + 'px'});
				$("#v_continueback").css({ 'width' : $("#v_embp").width() + 'px', 'height' : ($("#v_embp").height() - 60) + 'px'});
			}
		}
	}
	if(immediate){
		$("#v_continueback").show();
		$("#v_continue").show();
	} else {
		if(this.modecode == 4){
			$("#v_continue").html('<span id="v_replay" class="v_replay" style="display: none"></span><span id="v_contmsg" style="display: none;"></span><div id="v_embend"></div><div id="v_embsocial"></div>');
		} else {
			$("#v_continue").html('<span id="v_replay" class="v_replaylarge" style="display: none"></span><div id="v_endrel"></div>');
		}
		$("#v_continueback").fadeIn();
		$("#v_continue").fadeIn();
	}
	if(progress){
		$("#v_continue").html('<div style="text-align: center; padding: 160px 0 0 0;"><img src="/wgbh/pages/frontline/art/v1/v_bigload.gif" width="48" alt="48" alt="LOADING" /></div>');
	}
	$("#v_title").hide();
	$("#v_topwrap").unbind('mouseenter');
	this.overylayon = true;
}

function v_fp_issues () {
	$("#v_continue").html('<div style="text-align: center; padding: 100px 0 0 0;"><div style="background-color: #ff0000; text-align: center; color: #ffffff; font-size: 13px; padding: 10px;">PBS.org is experiencing difficulties.  Please try back later and we apologize for any inconvenience</div><br /><img src="/wgbh/pages/frontline/art/v1/v_bigload.gif" width="48" alt="48" alt="LOADING" /></div>');
}

function v_fp_overlayhide () {
	var subthis = this;
	$("#v_replay").unbind('click');
	$("#v_endrel").html('');
	$("#v_replay").hide();
	$("#v_continueback").fadeOut();
	$("#v_continue").fadeOut('fast');
	this.overylayon = false;
	if(!this.stayopen){
		$("#v_title").show();
	}
}

function v_fp_covech (idx) {
	this.chapteridx = idx;
	this.video.upd_chapter((this.chapteridx + 1));
	this.relatedrendered = false;
	$("#v_relarea").animate({ 'opacity':0 });
	this.clipinfo();
	chapterupdate(this.chapteridx, false);
}

function v_fp_relatedrender (alreadyhasit) {
	var subthis = this;
	if(alreadyhasit || this.video.relloaded){
		this.currentrel = -1;
		var outp = '<span id="v_relright"></span><span id="v_relleft"></span><span class="v_relhead">ALSO PART OF THIS REPORT</span><div id="v_relholder">';
		for(var x = 0; x < this.video.related_content.length; x++){
			var rel = this.video.related_content[x];
			if(rel.idcode == null && rel.lsc == null){ // we can't do related video or external listening yet
				outp += '<div idx="' + x + '" class="v_reloff">';
				if(rel.etmb != undefined && rel.etmb != ''){
					outp += '<span class="v_relimg" style="background-image:url(' + rel.etmb + ')"></span>';
				} else {
					outp += '<span class="v_relspc"></span>';
				}
				if(rel.lbl != undefined && rel.lbl != ''){
					outp += '<span class="v_rellbl">' + rel.lbl + '</span>';
				}
				if(rel.dsc != undefined && rel.dsc != ''){
					outp += '<span class="v_reldsc">' + rel.dsc + '</span>';
				}
				if(rel.att != undefined && rel.att != ''){
					outp += '<span class="v_relatt">' + rel.att + '</span>';
				}
				outp += '</div>';
			}
		}
		outp += '</div>';
		$("#v_relarea").html(outp);
		$("#v_relleft").click(function () {
			subthis.relatedhighlight(subthis.currentrel - 1);
			subthis.relchangeable = false;
			setTimeout(function () {
				subthis.relchangeable = true;
			}, 20000);
		});
		$("#v_relright").click(function () {
			subthis.relatedhighlight(subthis.currentrel + 1);
			subthis.relchangeable = false;
			setTimeout(function () {
				subthis.relchangeable = true;
			}, 20000);
		});
		$("#v_relholder").find('div').each(function () {
			$(this).click(function () {
				subthis.relatedclick($(this).attr('idx'),0);
			});
		});
		$("#v_relleft").hide();
		$("#v_relholder").css({ 'left': (($("#v_relarea").width() / 2) - 176) + 'px' });
		$("#v_relarea").animate({ 'opacity':1 });
	} else {
		this.relloader = setTimeout(this.relatedrender,1000);
	}
}


function v_fp_relatedclick (targetidx,typ) {
	var url = this.video.related_content[targetidx].url;
	if(url.indexOf('pbs.org') != -1){
		var ancmode = (url.indexOf('#') != -1)? true:false;
		var anc = new String();
		if(ancmode){
			anc = url.substring(url.indexOf('#'),url.length);
			url = url.substring(0,url.indexOf('#'));
		}
		if(url.indexOf('?') != -1){
			url += '&';
		} else {
			url += '?';
		}
		url += (typ == 0)? 'utm_campaign=videoplayer&utm_medium=fullplayer&utm_source=relatedlink':'utm_campaign=videoplayer&utm_medium=embplayer&utm_source=relatedlink';
		url += (ancmode)? anc:'';
	}
	window.open(url, 'links');
}


function v_fp_relatedhighlight (targetidx) {
		this.currentrel = parseInt(targetidx);
	if(targetidx > 0){
		$("#v_relleft").show();
	} else {
		$("#v_relleft").hide();
	}
	if(targetidx < (this.video.related_content.length - 1)){
		$("#v_relright").show();
	} else {
		$("#v_relright").hide();
	}
	$("#v_relholder").find("div").each(function (){
		$(this).removeClass('v_rel');
		if(targetidx == parseInt($(this).attr('idx'))){
			$(this).addClass('v_rel');
			$(this).removeClass('v_reloff');
		} else {
			$(this).addClass('v_reloff');
		}
	});
	$("#v_relholder").stop();
	$("#v_relholder").animate({ 'left': ((($("#v_relarea").width() / 2) - 176) - (targetidx * 353)) + 'px' });
}

function v_fp_legacytimerstart () {
	if(this.related){
		if(this.video.relloaded){
			if(!this.relatedrendered){
				this.relatedrender(true);
			}
		} else {
			this.video.get_relc_from_server(this.server);
			$("#v_relarea").html('<div style="text-align: center; padding: 50px;"><img src="/wgbh/pages/frontline/art/v1/v_dload.gif" width="24" height="24" alt="loading" /></div>');
			setTimeout(this.relatedrender, 1000);
		}
	}
	this.timerstart();
}

function v_fp_timerstart () {
	//	this.timer.start();
	$("#v_replacementplay").hide();
	$("#v_replacementthumb").hide();
	if($("#v_embinfo")){
		$("#v_embinfo").fadeOut("slow");
	}
	$("#v_replacementplay").unbind('click');
	if((this.modecode == 2 || this.modecode == 3) && !this.startscriptrun){
		// this is callled in mode 2/3 for expansion
		if(this.player_module.mode == 'cove'){
			if(this.modecode == 2){
				if(this.related){
					$("#v_embp").css({ "height": (this.h + 171) + "px" });
					this.outerresize({ height: (this.h + 171) });
				}
			} else {
				$("#v_embp").css({ "height": this.h + "px" });
				this.outerresize({ height: this.h });
			}
			$("#v_main").css({ "height": this.h + "px" });
			if(this.video.relloaded){
				if(!this.relatedrendered){
					this.relatedrender(true);
				}
			} else {
				this.video.get_relc_from_server(this.server);
				$("#v_relarea").html('<div style="text-align: center; padding: 50px;"><img src="/wgbh/pages/frontline/art/v1/v_dload.gif" width="24" height="24" alt="loading" /></div>');
				setTimeout(this.relatedrender, 1000);
			}
		} else {
			$("#v_embp").css({ "height": (this.h + 171) + "px" });
			this.outerresize({ height: (this.h + 171) });
//			$("#v_main").css({ "height": (this.h + 32) + "px" });
		}
		$("#v_relarea").show();
		if(this.startscript != ''){
			this.startscript.call();
		}
		this.startscriptrun = true;
	}
	clearInterval(this.timerinc);
	var subthis = this;
	this.timerinc = setInterval(subthis.timerupd,1000);
	if(this.showingchapter){
		this.hidechapterinfo();
	}
	if(this.overlayon){
		this.overlayhide();
	}
}

function v_fp_timerupd () {
		if(!this.player_module.isad){
		var nt = this.player_module.timerupdate();
		if(this.covemode && nt > 0){
			// run the check to see if we're in the right chapter
			if(!this.player_module.isinseek && !this.player_module.isad){
				var toofar = false;
				var newx = 0;
				for(var x = 0; x < this.video.jsondata.ditems.length && !toofar; x++){
					if(this.video.jsondata.ditems[x].tim <= nt){
						newx = x;
					} else {
						toofar = true;
					}
				}
				if(newx != this.chapteridx){
					this.covechapterupd(newx);
				}
			}
		}
		if(this.related && this.video.related_content.length > 0 && this.relchangeable){
			var reltoofar = false;
			var realtime = nt;
			if(!this.mobilemode){
				realtime -= this.video.jsondata.ditems[this.chapteridx].tim;
			}
			var newy = 0;
			for(var y = 0; y < this.video.related_content.length && !reltoofar; y++){
				var rel = this.video.related_content[y];
				if(rel.idcode == null && rel.lsc == null){ // we can't do related video or external listening yet
					if(rel.tim <= realtime){
						newy = y;
					} else {
						reltoofar = true;
					}
				}
			}
			if((this.modecode == 1 || this.modecode == 2 || this.modecode == 3) && newy != this.currentrel){
				this.relatedhighlight(newy);
			} else {
				if(this.modecode == 0 || this.modecode == 4){
					if(!this.video.related_content[newy].fired && realtime >= this.video.related_content[newy].tim){
						this.embrelated_up(newy,realtime);
					}
				}
			}
		}
		if(this.intcnt == 0){
			if(this.player_module.mode != 'npa'){
				var extlog = (this.modecode == 4)? 1:0;
				this.server.sendlog(this.video,nt,extlog);
				this.intcnt = this.loginterval;
			}
		}
		this.intcnt--;
	}
}

function v_fp_timerstop () {
//	this.timer.pause();
	clearInterval(this.timerinc);
}

function v_fp_chapterupdate (chidx,switchchapters) {
	this.chapteridx = parseInt(chidx);
	this.video.relloaded = false;
	if(switchchapters){
		if(this.player_module.mode == 'html5'){
			this.player_module.chapterswitch(this.video.jsondata.ditems[this.chapteridx].src);
		} else {
			if(player_module.mode == 'cove'){
				if(this.firstrun){
					this.firstrun = false;
				}

				this.player_module.playbutton();

			}
		}
	}
}

function v_fp_show_when_ready () {
	var subthis = this;
	window.show_when_ready = function() {
		if(subthis.video.loaded === true) { 
			subthis.show(); 
		}else {
			$('#v_main').text("loading video player components");
			setTimeout('window.show_when_ready()', 2000);
		}
	}
	window.show_when_ready();
}

function v_fp_show () {
	if(this.chapteridx == undefined){
		this.chapteridx = 0;
	}
	if(this.autoplay == undefined){
		this.autoplay = true;
	}
	var v = this.video; 
	if(mobilemode){
		this.overlayhide();
		if(v.mp4_enabled()){
			var tv;
			var vidfile;
			if(this.fullshow){
				tv = this.video.jsondata.ditems[this.chapteridx];
				vidfile = tv.src;
			} else {
				tv = this.video;
				vidfile = tv.video_file;
			}
			$("#v_main").css({ 'width':this.w + 'px', 'height':this.h + 'px' });
			$('#v_main').html(this.player_module.html5_player(vidfile,this.w,this.h,tv.tmb,this.autoplay));
			if(this.modecode == 0 || this.modecode == 2){
//				$("#v_embp").css({ 'height': this.h + 30 + 'px' });
//				this.outerresize({ height: (this.h + 30) });
//				if(this.modecode == 2){
//					$("#v_embp").css({ 'width': this.w + 100 + 'px' });
//					this.outerresize({ width: (this.w + 100) });
//				}
//				$("#v_mainarea").css({ 'height': this.h + 30 + 'px' });
				$("#v_main").css({ 'margin-left':'1px', 'margin-right':'1px' });
				$("#v_embinfo").css({ 'margin-top': (this.h - 90) + 'px' });
			}
			if(this.modecode == 4){
				$("#v_embp").css({ 'height': this.h + 60 + 'px' });
				this.outerresize({ height: (this.h + 60) });
				$("#v_mainarea").css({ 'height': this.h + 30 + 'px' });
				$("#v_main").css({ 'margin-left':'1px', 'margin-right':'1px' });
				$("#v_embinfo").css({ 'margin-top': (this.h - 90) + 'px' });
			}
			this.player_module.html5_evt();
			this.player_module.register_task('ended',this.ended);
			this.player_module.register_task('playing',this.timerstart);
			this.player_module.register_task('paused',this.timerstop);
		} else {
			$('#v_main').html('<p class="v_apology">This clip does not yet support mobile platforms.  We apologize for the inconvenience</p>');
		}
	} else {
		if(v.player_type() == "cove") {
			this.covemode = true;
			$("#v_main").html(this.player_module.cove_player());
			if(this.modecode == 0 || this.modecode == 2){
				$("#v_embp").css({ 'height': this.h + 30 + 'px' });
				this.outerresize({ height: (this.h + 30) });
			}
			if(this.modecode == 4){
				$("#v_embp").css({ 'height': this.h + 78 + 'px'});
				this.outerresize({ height: (this.h + 78) });
			}
			if(this.modecode != 1){
				if(this.modecode == 3){
					$("#v_mainarea").css({ 'height': this.h + 'px' });
					$("#v_embinfo").css({ 'margin-top': (this.h - 90) + 'px' });
				} else {
					$("#v_mainarea").css({ 'height': this.h + 30 + 'px' });
					$("#v_embinfo").css({ 'margin-top': (this.h - 90) + 'px' });
				}
				$("#v_main").css({ 'width':this.w + 'px', 'height':(this.h) + 'px' });
				$("#v_replacementplay").css({ 'padding-top': (((this.h) / 2) - 73) + 'px','padding-bottom': (((this.h) / 2) - 73) + 'px', 'padding-left': ((this.w / 2) - 73) + 'px','padding-right': ((this.w / 2) - 73) + 'px' });
			}
			var chdatastring = new String();
			if(this.video.jsondata.ditems[1] != undefined){
				for(var x = 0; x < this.video.jsondata.ditems.length; x++){
					chdatastring += (x > 0)? '|':'';
					chdatastring += this.video.jsondata.ditems[x].tim;
				}
			} else {
				chdatastring = '0|0';
			}
			if(this.modecode == 3){
				this.ext_chdata(this.video.jsondata.ditems);
			}
			var platformautoplay = this.autoplay;
			if(this.chapteridx > 1){
				platformautoplay = false;
			}
			
			var extemb = (this.modecode == 4)? true:false;
			var thumb = this.video.jsondata.ditems[this.chapteridx].tmb;			
			if(!this.fullshow){
				thumb = this.video.tmb;
			}
			if(this.thumbnailoverride != '' && this.modecode == 0){
				thumb = this.thumbnailoverride;
			}
			if(this.autoplay){
				this.player_module.cove_player_start(v.tp_media_id,this.w,this.h,true,chdatastring,this.starttime,this.endtime,extemb,this.overridetimes);
				this.firstrun = false;
				var tw = this.w;
				var th = this.h;
				$("#v_replacementthumb").css({ width: tw + 'px', height: th + 'px' });
			} else {
				var subthis = this;
				$("#v_replacementplay").show();
				var tw = this.w;
				var th = this.h;
				var thumbimg = '<img src="' + thumb + '" width="' + tw + '" height="' + th + '" alt="" />';
				$("#v_replacementthumb").css({ width: tw + 'px', height: th + 'px' });
				$("#v_replacementthumb").html(thumbimg);
				$("#v_replacementthumb").fadeIn();
				$("#v_replacementplay").click(function () {
					subthis.player_module.cove_player_start(v.tp_media_id,subthis.w,subthis.h,true,chdatastring,subthis.starttime,subthis.endtime,extemb,subthis.overridetimes);
					$("#v_replacementplay").hide();
					$("#v_replacementthumb").hide();
					subthis.timerstart();
					if(subthis.modecode == 1 || subthis.modecode == 2 || subthis.modecode == 3){
						subthis.chapterupdate(subthis.chapteridx,true);
						if(subthis.modecode == 2 || subthis.modecode == 3){
							subthis.video.upd_chapter(subthis.chapteridx + 1);
							subthis.clipinfo();
						}
					}
					if($("#v_embinfo")){
						$("#v_embinfo").fadeOut("slow");
					}
				});
				if(this.modecode != 1){
					this.embinfo();
				}
			}
			if(this.modecode != 1){
				if($("#v_embtitle")){
					var subthis = this;
					if(this.w > 340){
						if(this.externalexcerpt){
							if((this.endtime - this.starttime) > 1000000){
								$("#v_embtitle").html('<i>' + v.pkg_title + '</i> <span class="ar">&#187;</span>');
							} else {
								$("#v_embtitle").html('From <i>' + v.pkg_title + '</i> <span class="ar">&#187;</span>');
							}
						} else {
							$("#v_embtitle").html(v.seg_title + ' <span class="ar">&#187;</span>');
						}
					} else {
						$("#v_embtitle").html('More Information <span class="ar">&#187;</span>');
					}
					$("#v_embtitle").mouseenter(function () {
						$("#v_embtitle").html('More Information <span class="ar">&#187;</span>');
					});
					$("#v_embtitle").mouseleave(function () {
						if(subthis.w > 340){
							var z = subthis.current_video();
							if(subthis.externalexcerpt){
								if((subthis.endtime - subthis.starttime) > 1000000){
									$("#v_embtitle").html('<i>' + v.pkg_title + '</i> <span class="ar">&#187;</span>');
								} else {
									$("#v_embtitle").html('From <i>' + v.pkg_title + '</i> <span class="ar">&#187;</span>');
								}
							} else {
								$("#v_embtitle").html(v.seg_title + ' <span class="ar">&#187;</span>');
							}
						}
					});
					$("#v_embtitle").click(function () {
						var url = subthis.video.seg_link;
						if(url.indexOf('pbs.org') != -1){
							var ancmode = (url.indexOf('#') != -1)? true:false;
							var anc = new String();
							if(ancmode){
								anc = url.substring(url.indexOf('#'),url.length);
								url = url.substring(0,url.indexOf('#'));
							}
							if(url.indexOf('?') != -1){
								url += '&';
							} else {
								url += '?';
							}
							url += 'utm_campaign=videoplayer&utm_medium=embplayer&utm_source=toplink';
							url += (ancmode)? anc:'';
						}
						window.open(url, 'links');		
					});
				} else {
					$("#v_embtitle").unbind("click");
					$("#v_embtitle").unbind("mouseenter");
					$("#v_embtitle").unbind("mouseleave");
					$("#v_embtitle").hide();
				}
				
			}
			if(this.autoplay){
				this.timerstart();
			}
			this.overlayhide();
			this.player_module.register_task('ended',this.ended);
			this.player_module.register_task('playing',this.timerstart);
			this.player_module.register_task('paused',this.timerstop);
//			this.timer.register_recurring_task(this.logpoint,180);
		} else { 
			this.overlayhide();
			this.covemode = false;
			$("#v_embinfo").hide();
			if(this.modecode == 0 || this.modecode == 2){
				if(this.modecode == 0){
					$("#v_embp").css({ 'height': this.h + 32 + 'px', 'width': this.w + 2 });
					this.outerresize({ height: (this.h + 32), width: (this.w + 2) });
				} else {
					$("#v_embp").css({ 'height': this.h + 32 + 'px' });
					this.outerresize({ height: (this.h + 32) });
				}
				$("#v_mainarea").css({ 'height': this.h + 32 + 'px' });
				$("#v_embbot").remove();
			}
			if(this.modecode == 4){
				$("#v_embp").css({ 'height': this.h + 62 + 'px', 'width': this.w + 2 });
				this.outerresize({ height: (this.h + 62), width: (this.w + 2) });
				$("#v_mainarea").css({ 'height': this.h + 32 + 'px', 'width': this.w + 2 });
				$("#v_embbot").hide();
			}
			$('#v_main').html(this.player_module.legacy_player());
			v.upd_chapter(this.chapteridx + 1);
			if(v.seg_id == undefined){
				v.upd_chapter(1);
			}
			var emb = (this.modecode == 1)? true:false;
			var letter = (this.fullshow)? 'c':'s';
			this.player_module.legacy_player_init(v.rest_id.substring(0,6) + letter + v.seg_id.toString(16) + 'q' + v.pkg_id.toString(16),this.w,this.h,this.autoplay,emb,this.fullshow);
			this.player_module.register_task('ended',this.ended);
			this.player_module.register_task('playing',this.legacytimerstart);
			this.player_module.register_task('paused',this.timerstop);
			this.player_module.register_task('chapterup',this.legacychapterchange);
		}
	}
	if(this.modecode == 0 || this.modecode == 4){
		if(this.player_module.mode != 'npa'){
			this.relatedrendered = false;
			this.currentrel = -1;
			if(!this.workaround){
				this.video.upd_chapter(this.chapteridx);
				this.video.get_relc_from_server(this.server);
			}
		}	
	}
	if(this.video.progid && this.video.progid != '' && this.modecode == 4){
		this.commentscount(this.video.progid);
	}
	this.videorendered = true;
	return this;
}


function v_fp_commentscount (targetfile) {
	var subthis = this;
	if(targetfile.indexOf('frol') != -1){
					$.ajax({
					type: "GET",
					url:  "/wgbh/pages/frontline/xml/comments/" + targetfile + ".xml",
					dataType: "xml",
					success: function(xml) {
						var cnt = $(xml).find('com:first').attr('cnt');
						var pth = $(xml).find('com:first').attr('path');
						var air = $(xml).find('com:first').attr('air');
						subthis.commentobj.upcoming = ($(xml).find('com:first').attr('upc') == '1')? true:false;
						subthis.commentobj.commentcount = cnt;
						subthis.commentobj.airdate = air;
						subthis.commentobj.comments = new Array();
						subthis.commentobj.commentslink = 'http://www.pbs.org' + pth + '?utm_campaign=videoplayer&utm_medium=embplayer&utm_source=comments#comments';
						$(xml).find('cm').each(function () {
							var newobj = new Object();
							newobj.person = $(this).find('per:first').text();
							newobj.message = $(this).find('msg:first').text();
							subthis.commentobj.comments.push(newobj);
						});
						if(subthis.w > 340){
							$("#v_commentbutton").css({ 'width':'100px' });
							$("#v_commentbutton").html(cnt + ' comments');
						} else {
							$("#v_commentbutton").html(cnt);
						}
						$("#v_commentbutton").fadeIn();
						$("#v_commentbutton").click(function () {
							window.open('http://www.pbs.org' + pth + '?utm_campaign=videoplayer&utm_medium=embplayer&utm_source=comments#comments', 'links');	
						});
					}
				});	
	} else {
		$("#v_commentbutton").hide();
	}	
}

function v_fp_legacychapterdetect () {
	this.covechapterupd(this.chapteridx + 1);
}

function v_fp_embedcode () {
	var outp = '<div id="v_embcodeback"></div><div id="v_embcode" style="display: none"><span id="v_embcodeclose">CLOSE</span>Copy and paste this code on to any site.  Make sure all the text is on one line<form><textarea id="v_embcodespace">';
	outp += '</textarea></form><ul id="v_embsizer"><li w="322" h="258" class="unsel s">S</li><li w="386" h="294" class="unsel m">M</li><li w="514" h="366" class="sel l">L</li></ul></div>';
	var subthis = this;
	if(this.modecode == 1){
		$("#v_fp").prepend(outp);
		$("#v_embcodeback").css({ 'width' : $("#v_fp").width() + 'px', 'height' : this.openheight});
		$("#v_embcode").css({ 'margin-left': (($("#v_fp").width() / 2) - 155) });
		$("#v_embcodeback").fadeIn();
		$("#v_embcode").fadeIn();
	} else {
		$("#v_embp").prepend(outp);
		$("#v_embcodeback").css({ 'width' : $("#v_embp").width() + 'px', 'height' : ($("#v_embp").height() - 30) + 'px' });
		$("#v_embcode").css({ 'margin-left': (($("#v_embp").width() / 2) - 155), 'margin-top': (($("#v_embp").height() / 2) - 90) + 'px'  });
		$("#v_embcodeback").fadeIn();
		$("#v_embcode").fadeIn();

	}
	$("#v_embcodeclose").click(function () {
		subthis.embedcodeclose();
	});
	var thiscode = this.video.rest_id.substring(0,6) + 's'+this.video.seg_id.toString(16) + 'q' + this.video.pkg_id.toString(16);
	if(this.overridetimes && (this.modecode == 0 || this.externalexcerpt)){
		var st = this.starttime / 1000;
		var en = this.endtime / 1000;
		thiscode += '@' + st.toString(16) + '.' + en.toString(16);
	}
	this.embedcodechange(514,366,thiscode);
}

function v_fp_embedcodechange (w,h,code) {
	$("#v_embcodespace").val('<iframe frameborder="0" style="overflow: hidden; border: 0; margin: 0; padding: 0" width="' + w + '" height="' + h + '" scrollbars="none" type="text/html" src="http://www.pbs.org/wgbh/pages/frontline/v/?id=' + code + '&w=' + w + '&h=' + h + '"></iframe>');
	var subthis = this;
	$("#v_embsizer").find(".sel").removeClass('sel').addClass('unsel');
	$("#v_embsizer").find('li').each(function () {
		$(this).unbind("click");
		$(this).removeClass('sel');
		if($(this).attr('w') == w){
			$(this).addClass('sel');
			$(this).removeClass('unsel');
		} else {
			$(this).click(function () {
				subthis.embedcodechange($(this).attr('w'),$(this).attr('h'),code);
			});
		}
	});
}

function v_fp_embedcodeclose () {
	$("#v_embcode").remove();
	$("#v_embcodeback").remove();
}

function v_fp_current_video () {
	if(this.chapteridx == null) { 
		return null; 
	} else { 
		this.video.upd_chapter(this.chapteridx);  
		return this.video; 
	}
}


function v_fp_directloadcheck () {
	if(this.video.loaded){
		clearInterval(this.loadcheck);
		if(this.video.isblocked || (this.modecode == 4 && !this.video.embeddable)){
			this.draw(true);
		} else {
			this.chaptercount = this.video.jsondata.ditems.length;
			if(this.modecode == 0 || this.modecode == 4){
				this.fullshow = this.video.fullshow;
				if(!this.fullshow && !this.overridetimes){
					this.starttime = this.video.seg_start * 1000;
					this.endtime = this.video.seg_end * 1000;
				}
			}
			this.draw();
		}
	}
}

function v_fp_play (chidx) {
	this.chapteridx = parseInt(chidx);
	if(!this.isopen){
		toggle(true);
	}
	if(this.overlayon){
		this.overlayhide();
	}
	$("#v_replacementplay").hide();
	$("#v_replacementthumb").hide();
	this.hidechapterinfo();
	$("#" + this.divtarget).unbind('mouseleave');
	if(!this.videorendered){
		this.prepare(this.currentvideoid,true);
		this.chapterupdate(this.chapteridx,false);
	} else {
		this.chapterupdate(this.chapteridx,true);
	}
	this.timerstart();
	this.video.upd_chapter(this.chapteridx + 1);
	this.clipinfo();	
}

function v_fp_draw (isblocked) {
	var subthis = this;
	
	$("#" + this.divtarget).html('');

	var writ = new String();
	
	if(this.modecode == 1){
		if(this.stayopen){
			writ = '<div id="v_fp"><div id="v_continueback" style="display: none"></div><div id="v_continue" style="display: none"></div><div id="v_msg" style="display: none"></div>';
			writ += '<div id="v_mainarea" style="display: none"><span id="v_impatient" style="display: none"></span><span id="v_replacementplay" style="display: none"></span><span id="v_replacementthumb" style="display: none"></span><div id="v_main"></div><div id="v_clipi">';
			writ += '<div id="v_social" class="v_social"></div>';
			writ += '<span id="v_mch"></span><span id="v_mtitle"></span><span id="v_mdesc"></span><span id="v_mlen"></span></div><div id="v_reltitle"></div></div>';
			writ += (this.related)? '<div id="v_relarea" style="background: #333333 url(/wgbh/pages/frontline/art/v1/d_bg.gif) repeat-x; display: none"></div>':'';
			writ += '</div>';
			$("#" + this.divtarget).html(writ);
	
			this.overlayon(true,true);
			if(mobilemode){
				$("#v_mainarea").css({ 'height': '288px' });
				$("#v_main").css({ 'height': '288px' });
			}
			if(isblocked){
				$("#v_fp").css({ 'height':this.openheight + 'px' });
				this.outerresize({ height: this.openheight });
				$("#v_title").hide();
			} else {
				toggle(false);
			}
		} else {
			writ = '<div id="v_videolink"><span class="v_ar"></span>Watch The Program Now</div>';
			$("#" + this.divtarget).html(writ);
			var subthis = this;
			$("#" + this.divtarget).click(function () {
				window.location.href = subthis.fakeurl + 'view/?autoplay';
			});
		}
	} else {
		if(this.modecode == 0 || this.modecode == 2){
			if(this.modecode == 0){			
				writ = '<div id="v_embp" style="width: ' + this.w + 'px; height: ' + this.h + 'px" id="npa_emb"><div id="v_continueback" style="display: none"></div><div id="v_continue" style="display: none"></div><div id="v_mainarea" style="display: none"><div id="v_embinfo" style="display: none; width: ' + (this.w - 20) + 'px; margin-top: ' + (this.h - 60) + 'px"></div><span id="v_impatient" style="display: none"></span><span id="v_replacementplay" style="display: none"></span><span id="v_replacementthumb" style="display: none"></span><div id="v_main"></div>';
			} else {
				writ = '<div id="v_embp" style="height: ' + this.h + 'px" id="npa_emb"><div id="v_continueback" style="display: none"></div><div id="v_continue" style="display: none"></div><div id="v_ch"></div><div id="v_embchapterinfo" style="display: none"></div><div id="v_mainarea" style="display: none"><div id="v_embinfo" style="display: none; width: ' + (this.w - 20) + 'px; margin-top: ' + (this.h - 60) + 'px"></div><span id="v_impatient" style="display: none"></span><span id="v_replacementplay" style="display: none"></span><span id="v_replacementthumb" style="display: none"></span><div id="v_main"></div>';
			}
			writ += (this.related && this.modecode == 2)? '<div id="v_relarea" style="background: #333333 url(/wgbh/pages/frontline/art/v1/d_bg.gif) repeat-x; display: none"></div>':'';
			writ += '<div class="v_embbot" id="v_embbot">';
			if(this.modecode == 2 && this.ituneslink != ''){
				writ += '<a href="' + this.ituneslink + '" class="v_itunes" title="Buy from iTunes">Buy from iTunes &#187;</a>';
			}
			if(this.modecode == 2 && this.dvdlink!= ''){
				writ += '<a href="' + this.dvdlink + '" class="v_dvdlink" title="Buy the DVD">Buy the DVD &#187;</a>';
			}
			writ += '<div id="v_embrel" style="display: none"></div></div>';
			writ += '</div></div>';
			$("#" + this.divtarget).html(writ);
			$("#v_mainarea").show();
			if(mobilemode){
				$("#v_mainarea").css({ 'height': (this.h + 30) + 'px' });
				$("#v_main").css({ 'height': (this.h + 30) + 'px' });
			}
			this.prepare(this.currentvideoid);
		} else {
			if(this.modecode == 3){
				writ = '<div id="v_embp" style="width: ' + this.w + 'px; height: ' + this.h + 'px" id="npa_emb">';
				writ += '<div id="v_continueback" style="display: none"></div><div id="v_continue" style="display: none"></div>';
				writ += '<div id="v_mainarea" style="display: none"><div id="v_embinfo" style="display: none; width: ' + (this.w - 20) + 'px; margin-top: ' + (this.h - 70) + 'px"></div><span id="v_replacementplay" style="display: none"></span><span id="v_replacementthumb" style="display: none"></span><div id="v_main"></div></div>';
				writ += (this.related)? '<div id="v_relarea" style="display: none"></div>':'';
				writ += '</div>';
				$("#" + this.divtarget).html(writ);
				$("#v_mainarea").show();
				this.prepare(this.currentvideoid);
			} else {
				writ = '<div id="v_embp" style="width: ' + this.w + 'px; height: ' + this.h + 'px" id="npa_emb">';
				writ += '<div id="v_continueback" style="display: none"></div><div id="v_continue" style="display: none"></div>';
				writ += '<div id="v_embtop">';
				if(this.w > 340){
					writ += '<span class="v_embtitle" id="v_embtitle" style="width: 220px"></span>';
				} else {
					writ += '<span class="v_embtitle" id="v_embtitle" style="width: 150px"></span>';
				}
				writ += '<a href="http://www.pbs.org/wgbh/pages/frontline/?utm_campaign=videoplayer&utm_medium=external&utm_source=logo" target="_parent" title="FRONTLINE series home"><img src="/wgbh/pages/frontline/art/v1/e_fl.gif" width="114" height="30" alt="FRONTLINE" /></a><a href="http://www.pbs.org/" target="_parent" title="PBS"><img src="/wgbh/pages/frontline/art/v1/e_pbs.gif" width="25" height="25" alt="PBS" style="margin: 2px 5px 3px 5px;" /></a></div>';
				writ += '<div id="v_mainarea" style="display: none"><div id="v_embinfo" style="display: none; width: ' + (this.w - 20) + 'px; margin-top: ' + (this.h - 70) + 'px"></div><span id="v_replacementplay" style="display: none"></span><span id="v_replacementthumb" style="display: none"></span><div id="v_main"></div>';
				writ += '<div class="v_embbot" id="v_embbot"><div id="v_commentbutton" style="display: none"></div><div id="v_embrel" style="display: none"></div></div>';
				writ += '</div></div>';
				$("#" + this.divtarget).html(writ);
				$("#v_mainarea").show();
				if(mobilemode){
					$("#v_mainarea").css({ 'height': (this.h + 60) + 'px' });
					$("#v_main").css({ 'height': (this.h + 60) + 'px' });
				}
				this.prepare(this.currentvideoid);
			}
		}
	}

	
	if(isblocked){
		if(!this.video.embeddable && this.modecode == 4){
			$("#v_msg").html("<a href=\"http://www.pbs.org/wgbh/pages/frontline/\" target=\"_parent\" style=\"color: #ffffff\">Sorry, this program is not available for embedding.  Please visit http://pbs.org/frontline/ to view this video.</a>");
		} else {
			$("#v_msg").html("Sorry, this program is not available in your country due to rights restrictions.  FRONTLINE apologizes for any inconvenience.");
		}
		$("#v_msg").addClass('v_blocked');
		$("#v_msg").show();
	}
}

function v_fp_toggle (avoidloading) {
	var subthis = this;
	if(this.isopen){
		this.isopen = false;
		if(this.videorendered){
			this.player_module.pause(true);
			this.timerstop();
		}
		if(this.overlayon){
			this.overlayhide();
		}
		$("#v_fp").stop();
		$("#v_fp").css({ 'height':this.closedheight + 'px' });
		$("#" + this.divtarget).stop();
		this.outerresize({ height: this.closedheight });
		$("#v_title").html('Watch Now<span class="v_ar"></span>');
		$("#v_topwrap").css({ "cursor":"default" });
		$("#v_topwrap").unbind('mouseenter');
		$("#v_mainarea").hide();
		$("#v_relarea").hide();
	} else {
		this.isopen = true;
		$("#v_social").html(this.social());
		if(!avoidloading){
			this.prepare(this.currentvideoid);
			this.video.upd_chapter(this.chapteridx + 1);
			this.clipinfo();
		}
		if(this.modecode == 1){
			if(this.stayopen){
				$("#v_fp").css({ 'height':this.openheight + 'px' });
				this.outerresize({ height: this.openheight });
				$("#v_title").hide();
			} else {
				$("#v_fp").stop();
				$("#v_fp").css({ 'height':this.openheight + 'px' });
				$("#" + this.divtarget).stop();
				this.outerresize({ height: this.openheight });
				$("#v_title").html('Close Video <span class="v_cl">-</span> &nbsp;');
				$("#v_title").unbind('mouseover');
			}
		}
		$("#v_mainarea").show();
		$("#v_relarea").show();
	}
}

function v_fp_clipinfo () {
	if(!this.admode){
		$("#v_mainarea").show();
		if(this.modecode == 1){
			$("#v_mch").html('Chapter ' + (this.chapteridx + 1));
			var thisch = this.video.jsondata.ditems[this.chapteridx];
			$("#v_mtitle").html(thisch.tit);
			$("#v_mdesc").html(thisch.dsc);
			$("#v_mlen").html(v_secformat(thisch.len));
		}
	}
	if(this.related){
		if(this.video.relloaded){
			if(!this.relatedrendered){
				this.relatedrender(true);
			}
		} else {
			this.video.get_relc_from_server(this.server);
			$("#v_relarea").html('<div style="text-align: center; padding: 50px;"><img src="/wgbh/pages/frontline/art/v1/v_dload.gif" width="24" height="24" alt="loading" /></div>');
			setTimeout(this.relatedrender, 1000);
		}
	}
}

function v_secformat (len) {
	var ret = parseInt(parseInt(len) / 60);
	var sec = parseInt(parseInt(len) % 60);
	if(sec < 10){
		ret += ":0" + sec;
	} else {
		ret += ":" + sec;
	}
	return ret;
}

function genericvideoplayer (stayopen,clipid,baseurl,pkgcode,cachetitle) {
	// legacy routine passing through to the new one
	v_fp({ stayopen:stayopen, videoid:clipid, fakeurl: baseurl, divtarget:"videospace" });
}

// old code for non-full shows

var _papvideourl="http://www.pbs.org/wgbh/pages/frontline/video/flv/v2z.swf";
var _papevideourl="http://www.pbs.org/wgbh/pages/frontline/video/flv/e3z.swf";
var _papdefaulturl="http://www.pbs.org/wgbh/pages/frontline/video/flv/generic.html";
var _papchapsurl="http://www.pbs.org/wgbh/pages/frontline/video/flv/c1b.swf";
var _papsearchurl="http://www.pbs.org/wgbh/pages/frontline/video/flv/search1.swf";
var _papsearchdefurl="http://www.pbs.org/wgbh/pages/frontline/video/flv/searchd1.swf";
var _ipadurl="http://player2.entropymedia.com/ipad/";
var _papbrandidoverride=0;
var _papwidth=750;
var _papheight=640;
var _papspawn=true;
var _papstation='';
var _pap_newshour_funders=0;
var _paplisten='';
var _paponload='';
var _paponrel="";
var _papseglisten='';
var _buttoncolor='';
var _buttonroll='';
var _standalone=false;
var issafari=false;
if(navigator.userAgent.indexOf("Safari")!=-1)
{
issafari=true
}
var isff=false;
if(navigator.userAgent.indexOf("Firefox/3")!=-1)
{
isff=true
}
function _pap_localurl(a)
{
_papdefaulturl=a
}
function _pap_seturl(a)
{
_papdefaulturl=a
}
function _pap_setstandalone(a)
{
_standalone=a
}
function _pap_localbrand(a)
{
_papbrandidoverride=a
}
function _pap_setspawn(a)
{
if(a)
{
_papspawn=true
}
else
{
_papspawn=false
}
}
function _pap_setstation(a)
{
_papstation=a
}
function _pap_setwidth(a)
{
_papwidth=a
}
function _pap_setheight(a)
{
_papheight=a
}
function _pap_setlisten(a)
{
_paplisten=a
}
function _pap_setseglisten(a)
{
_papseglisten=a
}
function _pap_setonrel(a)
{
_paponrel=a
}
function _pap_setonload(a)
{
_paponload=a
}
function _pap_setbuttoncolor(a)
{
_buttoncolor=a
}
function _pap_setbuttonrollcolor(a)
{
_buttonroll=a
}
function _pap_setnewshour(a)
{
if(a)
{
_pap_newshour_funders=1
}
else
{
_pap_newshour_funders=0
}
}
function _pap_seturl(a)
{
_papdefaulturl=a
}
function _pap_spawn(a)
{
var b=_papdefaulturl+'?s='+a;
if(_papdefaulturl.indexOf("?")!=-1)
{
b=_papdefaulturl+'&s='+a
}
if(_papspawn)
{
window.open(b,"papvideo","toolbar=no,location=no,directories=no,menubar=no,width="+_papwidth+",height="+_papheight+",scrollbars=no")
}
else
{
location.href=b
}
}
function _pap_pop(a,c)
{
var b=_papdefaulturl+'?s='+a;
if(c!=undefined)
{
b+='&continuous='+c
}
var d=window.open(b,"papvideo","toolbar=no,location=no,directories=no,menubar=no,width="+_papwidth+",height="+_papheight+",scrollbars=no");
if(d)
{
d.focus()
}
else
{
alert("Sorry, it looks like your browser is blocking this pop-up window.  You may need to specifically authorize pop-ups to watch this video.")
}
}
function _pap_embed(a,b)
{
var c="paplayer_";
var d="paembedplayer";
var e=0;
while(document.getElementById(c+e))
{
e++
}
c=c+e;
d+=e;
document.write('<div id="'+c+'"><p>You\'ll need Flash 9 or better to view this content. <a href="http://www.adobe.com/go/gntray_dl_getflashplayer" target="_new">Download it now</a></p></div>');
var f=
{
};
var g=
{
wmode:"opaque",allowFullScreen:"true",allowScriptAccess:"always"
};
if(e>0)
{
f.pap_multiple=1
}
f.pap_url=window.location.href;
f.pap_hash=a;
if(_buttoncolor!='')
{
f.pap_buttoncolor=_buttoncolor
}
if(_papseglisten !=''){
f.pap_segmentlisten = _papseglisten;
}
if(_paplisten !=''){
f.pap_listen = _paplisten;
}
if(_paponload !=''){
f.pap_onload = _paponload;
}
if(_buttonroll!='')
{
f.pap_buttonroll=_buttonroll
}
if(_papbrandidoverride!=0)
{
f.pap_localbrandid=_papbrandidoverride
}
if(_standalone)
{
f.pap_standalone=1
}
if(b!=undefined&&b!='')
{
f.pap_overridetitle=b
}
if(_paponrel !=''){
f.pap_onrelated = _paponrel;
}
if(issafari)
{
f.pap_safari=1
}
if(isff)
{
f.pap_ffw=514;
f.pap_ffh=320;
}
if(_paplisten!='')
{
f.pap_listen=_paplisten
}
swfobject.embedSWF(_papevideourl,c,"514","320","9",null,f,g,
{
id:d+'id',name:c+'na'
}
)
}
function _pap_embed_43(a,b)
{
var c="paplayer_";
var d="paembedplayer";
var e=0;
while(document.getElementById(c+e))
{
e++
}
c=c+e;
d+=e;
document.write('<div id="'+c+'"><p>You\'ll need Flash 9 or better to view this content. <a href="http://www.adobe.com/go/gntray_dl_getflashplayer" target="_new">Download it now</a></p></div>');
var f=
{
};
var g=
{
wmode:"opaque",allowFullScreen:"true",allowScriptAccess:"always"
};
if(e>0)
{
f.pap_multiple=1
}
f.pap_url=window.location.href;
f.pap_hash=a;
if(_buttoncolor!='')
{
f.pap_buttoncolor=_buttoncolor
}
if(_buttonroll!='')
{
f.pap_buttonroll=_buttonroll
}
if(_papseglisten !=''){
f.pap_segmentlisten = _papseglisten;
}
if(_paplisten !=''){
f.pap_listen = _paplisten;
}
if(_paponload !=''){
f.pap_onload = _paponload;
}
if(_standalone)
{
f.pap_standalone=1
}
if(_papbrandidoverride!=0)
{
f.pap_localbrandid=_papbrandidoverride
}
if(b!=undefined&&b!='')
{
f.pap_overridetitle=b
}
if(issafari)
{
f.pap_safari=1
}
if(isff)
{
f.pap_ffw=482;
f.pap_ffh=392;
}
if(_paponrel !=''){
f.pap_onrelated = _paponrel;
}
if(_paplisten!='')
{
f.pap_listen=_paplisten
}
swfobject.embedSWF(_papevideourl,c,"482","392","9",null,f,g,
{
id:d+'id',name:c+'na'
}
)
}
function _pap_embed_small(a,b)
{
var c="paplayer_";
var d="paembedplayer";
var e=0;
while(document.getElementById(c+e))
{
e++
}
c=c+e;
d+=e;
document.write('<div id="'+c+'"><p>You\'ll need Flash 9 or better to view this content. <a href="http://www.adobe.com/go/gntray_dl_getflashplayer" target="_new">Download it now</a></p></div>');
var f=
{
};
var g=
{
wmode:"opaque",allowFullScreen:"true",allowScriptAccess:"always"
};
if(e>0)
{
f.pap_multiple=1
}
f.pap_url=window.location.href;
f.pap_hash=a;
if(_buttoncolor!='')
{
f.pap_buttoncolor=_buttoncolor
}
if(_buttonroll!='')
{
f.pap_buttonroll=_buttonroll
}
if(_papseglisten !=''){
f.pap_segmentlisten = _papseglisten;
}
if(_paplisten !=''){
f.pap_listen = _paplisten;
}
if(_paponload !=''){
f.pap_onload = _paponload;
}
if(_standalone)
{
f.pap_standalone=1
}
if(_paplisten!='')
{
f.pap_listen=_paplisten
}
if(_papbrandidoverride!=0)
{
f.pap_localbrandid=_papbrandidoverride
}
if(b!=undefined&&b!='')
{
f.pap_overridetitle=b
}
if(isff)
{
f.pap_ffw=322;
f.pap_ffh=212;
}
if(_paponrel !=''){
f.pap_onrelated = _paponrel;
}
if(issafari)
{
f.pap_safari=1
}
swfobject.embedSWF(_papevideourl,c,"322","212","9",null,f,g,
{
id:d+'id',name:c+'na'
}
)
}
function _pap_embed_43_small(a,b)
{
var c="paplayer_";
var d="paembedplayer";
var e=0;
while(document.getElementById(c+e))
{
e++
}
c=c+e;
d+=e;
document.write('<div id="'+c+'"><p>You\'ll need Flash 9 or better to view this content. <a href="http://www.adobe.com/go/gntray_dl_getflashplayer" target="_new">Download it now</a></p></div>');
var f=
{
};
var g=
{
wmode:"opaque",allowFullScreen:"true",allowScriptAccess:"always"
};
if(e>0)
{
f.pap_multiple=1
}
f.pap_url=window.location.href;
f.pap_hash=a;
if(_buttoncolor!='')
{
f.pap_buttoncolor=_buttoncolor
}
if(_papseglisten !=''){
f.pap_segmentlisten = _papseglisten;
}
if(_paplisten !=''){
f.pap_listen = _paplisten;
}
if(_paponload !=''){
f.pap_onload = _paponload;
}
if(_paponrel !=''){
f.pap_onrelated = _paponrel;
}
if(_standalone)
{
f.pap_standalone=1
}
if(_buttonroll!='')
{
f.pap_buttonroll=_buttonroll
}
if(_papbrandidoverride!=0)
{
f.pap_localbrandid=_papbrandidoverride
}
if(b!=undefined&&b!='')
{
f.pap_overridetitle=b
}
if(_paplisten!='')
{
f.pap_listen=_paplisten
}
if(issafari)
{
f.pap_safari=1
}
if(isff)
{
f.pap_ffw=322;
f.pap_ffh=272;
}

swfobject.embedSWF(_papevideourl,c,"322","272","9",null,f,g,
{
id:d+'id',name:c+'na'
}
)
}
function _pap_embed_bypkg(a,b,c,d)
{
var e="paplayer_";
var f="paembedplayer";
var g=0;
while(document.getElementById(e+g))
{
g++
}
e=e+g;
f+=g;
document.write('<div id="'+e+'"><p>You\'ll need Flash 9 or better to view this content. <a href="http://www.adobe.com/go/gntray_dl_getflashplayer" target="_new">Download it now</a></p></div>');
var h=
{
};
var i=
{
wmode:"opaque",allowFullScreen:"true",allowScriptAccess:"always"
};
if(g>0)
{
h.pap_multiple=1
}
h.pap_url=window.location.href;
h.pap_brand=a;
h.pap_brandid=b;
h.pap_pkgcode=c;
h.pap_segidx=d;
if(_papbrandidoverride!=0)
{
h.pap_localbrandid=_papbrandidoverride
}
if(_buttoncolor!='')
{
f.pap_buttoncolor=_buttoncolor
}
if(_papseglisten !=''){
f.pap_segmentlisten = _papseglisten;
}
if(_paplisten !=''){
f.pap_listen = _paplisten;
}
if(_paponload !=''){
f.pap_onload = _paponload;
}
if(_paponrel !=''){
f.pap_onrelated = _paponrel;
}
if(_standalone)
{
f.pap_standalone=1
}
if(_buttonroll!='')
{
f.pap_buttonroll=_buttonroll
}
if(_paplisten!='')
{
f.pap_listen=_paplisten
}
if(newtitle!=undefined&&newtitle!='')
{
h.pap_overridetitle=newtitle
}
if(issafari)
{
h.pap_safari=1
}
if(isff)
{
h.pap_ffw=514;
h.pap_ffh=320;
}
swfobject.embedSWF(_papevideourl,e,"514","320","9",null,h,i,
{
id:f+'id',name:e+'na'
}
)
}
function _pap_embed_43_bypkg(a,b,c,d)
{
var e="paplayer_";
var f="paembedplayer";
var g=0;
while(document.getElementById(e+g))
{
g++
}
e=e+g;
f+=g;
document.write('<div id="'+e+'"><p>You\'ll need Flash 9 or better to view this content. <a href="http://www.adobe.com/go/gntray_dl_getflashplayer" target="_new">Download it now</a></p></div>');
var h=
{
};
var i=
{
wmode:"opaque",allowFullScreen:"true",allowScriptAccess:"always"
};
if(g>0)
{
h.pap_multiple=1
}
h.pap_url=window.location.href;
h.pap_brand=a;
h.pap_brandid=b;
h.pap_pkgcode=c;
h.pap_segidx=d;
if(_papseglisten !=''){
h.pap_segmentlisten = _papseglisten;
}
if(_paplisten !=''){
h.pap_listen = _paplisten;
}
if(_paponload !=''){
h.pap_onload = _paponload;
}
if(_paponrel !=''){
h.pap_onrelated = _paponrel;
}
if(_buttoncolor!='')
{
h.pap_buttoncolor=_buttoncolor
}
if(_buttonroll!='')
{
h.pap_buttonroll=_buttonroll
}
if(_standalone)
{
h.pap_standalone=1
}
if(_papbrandidoverride!=0)
{
h.pap_localbrandid=_papbrandidoverride
}
if(_paplisten!='')
{
f.pap_listen=_paplisten
}
if(newtitle!=undefined&&newtitle!='')
{
h.pap_overridetitle=newtitle
}
if(issafari)
{
h.pap_safari=1
}
if(isff)
{
h.pap_ffw=482;
h.pap_ffh=392;
}
swfobject.embedSWF(_papevideourl,e,"482","392","9",null,h,i,
{
id:f+'id',name:e+'na'
}
)
}
function _pap_sharepage()
{
var a=
{
};
var b=
{
wmode:"opaque",allowFullScreen:"true",allowScriptAccess:"always"
};
a.pap_url=window.location.href;
a.pap_hash=swfobject.getQueryParamValue("s");
swfobject.embedSWF(_papvideourl,'pap_shareplayer',"750","584","9",null,a,b,
{
id:"paembedplayer0",name:"paembedplayer0"
}
)
}
function _pap_page(v,w)
{
document.write('<div id="paplayer"><p>You\'ll need Flash 9 or better to view this content. <a href="http://www.adobe.com/go/gntray_dl_getflashplayer" target="_new">Download it now</a></p></div>');
var a=
{
};
var b=
{
wmode:"opaque",allowFullScreen:"true",allowScriptAccess:"always"
};
a.pap_url=window.location.href;
a.pap_pkgcode=swfobject.getQueryParamValue("pkg");
a.pap_mode=swfobject.getQueryParamValue("mod");
a.pap_brand=(v)?v:swfobject.getQueryParamValue("bra");
a.pap_brandid=(w)?w:swfobject.getQueryParamValue("bri");
a.pap_segidx=swfobject.getQueryParamValue("seg");
a.pap_mode=swfobject.getQueryParamValue("mod");
a.pap_hash=swfobject.getQueryParamValue("s");
a.pap_continuous=swfobject.getQueryParamValue("continuous");
if(_papbrandidoverride!=0)
{
a.pap_localbrandid=_papbrandidoverride
}
if(_pap_newshour_funders==1)
{
a.pap_newshour_funders=1
}
swfobject.embedSWF(_papvideourl,'paplayer',"750","584","9",null,a,b,
{
id:"paembedplayer0",name:"paembedplayer0"
}
)
}
function _pap_inpage(a)
{
document.write('<div id="paplayer"><p>You\'ll need Flash 9 or better to view this content. <a href="http://www.adobe.com/go/gntray_dl_getflashplayer" target="_new">Download it now</a></p></div>');
var b=
{
};
var c=
{
wmode:"opaque",allowFullScreen:"true",allowScriptAccess:"always"
};
b.pap_hash=a;
if(_papbrandidoverride!=0)
{
b.pap_localbrandid=_papbrandidoverride
}
if(_pap_newshour_funders==1)
{
b.pap_newshour_funders=1
}
swfobject.embedSWF(_papvideourl,'paplayer',"750","584","9",null,b,c,
{
id:"paembedplayer0",name:"paembedplayer0"
}
)
}
function _pap_embed_custom(a,b,c,d)
{
var e="paplayer_";
var f="paembedplayer";
var g=0;
while(document.getElementById(e+g))
{
g++
}
e=e+g;
f+=g;
document.write('<div id="'+e+'"><p>You\'ll need Flash 9 or better to view this content. <a href="http://www.adobe.com/go/gntray_dl_getflashplayer" target="_new">Download it now</a></p></div>');
var h=
{
};
var i=
{
wmode:"opaque",allowFullScreen:"true",allowScriptAccess:"always"
};
if(g>0)
{
h.pap_multiple=1
}
h.pap_url=window.location.href;
h.pap_hash=a;
if(_papseglisten !=''){
h.pap_segmentlisten = _papseglisten;
}
if(_paplisten !=''){
h.pap_listen = _paplisten;
}
if(_paponload !=''){
h.pap_onload = _paponload;
}
if(_paponrel !=''){
h.pap_onrelated = _paponrel;
}
if(_paplisten!='')
{
h.pap_listen=_paplisten
}
if(_standalone)
{
h.pap_standalone=1
}
if(_buttoncolor!='')
{
h.pap_buttoncolor=_buttoncolor
}
if(_buttonroll!='')
{
h.pap_buttonroll=_buttonroll
}
if(_papbrandidoverride!=0)
{
h.pap_localbrandid=_papbrandidoverride
}
if(d!=undefined&&d!='')
{
h.pap_overridetitle=d
}
if(issafari)
{
h.pap_safari=1
}
if(isff)
{
h.pap_ffw=b;
hpap_ffh=c;
}
swfobject.embedSWF(_papevideourl,e,b,c,"9",null,h,i,
{
id:f+'id',name:e+'na'
}
)
}
function _pap_embedshare(b)
{
var e="paplayer_";
var f="paembedplayer";
var g=0;
while(document.getElementById(e+g))
{
g++
}
e=e+g;
f+=g;
var h=
{
};
var c=
{
wmode:"opaque",allowFullScreen:"true",allowScriptAccess:"always"
};
document.write('<div id="'+e+'"><p>You\'ll need Flash 9 or better to view this content. <a href="http://www.adobe.com/go/gntray_dl_getflashplayer" target="_new">Download it now</a></p></div>');
if(g>0)
{
h.pap_multiple=1
}
h.pap_url=window.location.href;
if(_papbrandidoverride!=0)
{
h.pap_localbrandid=_papbrandidoverride
}
if(_buttoncolor!='')
{
h.pap_buttoncolor=_buttoncolor
}
if(_buttonroll!='')
{
h.pap_buttonroll=_buttonroll
}
if(_standalone)
{
h.pap_standalone=1
}
if(issafari)
{
h.pap_safari=1
}
if(_papseglisten !=''){
h.pap_segmentlisten = _papseglisten;
}
if(_paplisten !=''){
h.pap_listen = _paplisten;
}
if(_paponload !=''){
h.pap_onload = _paponload;
}
if(_paponrel !=''){
h.pap_onrelated = _paponrel;
}
h.pap_hash=swfobject.getQueryParamValue("s");
var a=514;
var d=320;
if(b==2)
{
a=482;
d=392
}
if(b==3)
{
a=322;
d=212
}
if(b==4)
{
a=322;
d=272
}
if(isff)
{
h.pap_ffw=a;
h.pap_ffh=d;
}
swfobject.embedSWF(_papevideourl,e,a,d,"9",null,h,c,
{
id:f+'id',name:e+'na'
}
)
}
function _pap_chapters(a,b,c,d)
{
var h=
{
};
var i=
{
wmode:"opaque",allowScriptAccess:"always"
};
var e="pap_chapters";
var g=0;
while(document.getElementById(e+g))
{
g++
}
e=e+g;
document.write('<div id="'+e+'"><p>You\'ll need Flash 9 or better to view this content. <a href="http://www.adobe.com/go/gntray_dl_getflashplayer" target="_new">Download it now</a></p></div>');
h.pap_brandcode=a;
h.pap_program=b;
if(c!=undefined)
{
h.pap_continuous=c
}
if(d!=undefined)
{
h.pap_target=d
}
if(issafari)
{
h.pap_safari=1
}
h.pap_target = _papdefaulturl;
swfobject.embedSWF(_papchapsurl,e,"100%","218","9",null,h,i,
{
id:e,name:e+'na'
}
)
}


function _pap_embeddable(a,b,c,d,p){
var rm = false;
var e="paplayer_";
var f="paembedplayer";
var dw = b;
var g=0;
while(document.getElementById(e+g))
{
g++
}
if(typeof(d) == 'undefined'){
var d = {}
} else {
	if(d.pap_resizeable){
		rm = true;
	}
}
if(p){
	d.pap_usecache = true;
}
e=e+g;
f+=g;
document.write('<div id="'+e+'"><p>You\'ll need Flash 9 or better to view this content. <a href="http://www.adobe.com/go/gntray_dl_getflashplayer" target="_new">Download it now</a></p></div>');
	var i=
	{
	wmode:"opaque",allowFullScreen:"true",allowScriptAccess:"always"
	};
	if(g>0 && !e)
	{
	d.pap_multiple=1
	}
	if(issafari){
	d.pap_safari=1;
	}
	if(_papseglisten !=''){
	d.pap_segmentlisten = _papseglisten;
	}
	if(_paplisten !=''){
	d.pap_listen = _paplisten;
	}
	if(_paponload !=''){
	d.pap_onload = _paponload;
	}
	if(_paponrel !=''){
	d.pap_onrelated = _paponrel;
	}
	if(_papbrandidoverride!=0)
	{
	d.pap_localbrandid=_papbrandidoverride
	}
	d.pap_url=window.location.href;
	d.pap_hash=a;
	if(d.pap_captions){
	c +=40;
	}
	if(isff)
	{
	d.pap_ffw=b;
	d.pap_ffh=c;
	}
	swfobject.embedSWF(_papevideourl,e,b,c,"9",null,d,i,{ id:f+'id',name:e+'na' });
}
function _pap_embeddable_resize(x,y){
var a;
if(navigator.appName.indexOf("Microsoft")!=-1)
{
a=window['paembedplayer0id']
}
else
{
a=document['paembedplayer0id']
}
a.style.width=x;
a.style.height=y;
}
function _pap_videoload(a,c)
{
if(c == undefined){
	c = 0;
}
var b;
if(navigator.appName.indexOf("Microsoft")!=-1)
{
b=window['paembedplayer'+c+'id']
}
else
{
b=document['paembedplayer'+c+'id']
}
b.playvideo(a)
}
function _pap_getrelated(c)
{
if(c == undefined){
	c = 0;
}
var a;
if(navigator.appName.indexOf("Microsoft")!=-1)
{
a=window['paembedplayer'+c+'id']
}
else
{
a=document['paembedplayer'+c+'id']
}
var b=a.getrelated();
return b
}
function _pap_getinfo(c)
{
if(c == undefined){
	c = 0;
}
var a;
if(navigator.appName.indexOf("Microsoft")!=-1)
{
a=window['paembedplayer'+c+'id']
}
else
{
a=document['paembedplayer'+c+'id']
}
var b=a.getinfo();
return b
}
function _pap_play(c)
{
if(c == undefined){
	c = 0;
}
var a;
if(navigator.appName.indexOf("Microsoft")!=-1)
{
a=window['paembedplayer'+c+'id']
}
else
{
a=document['paembedplayer'+c+'id']
}
a.pap_play();
}
function _pap_pause(c)
{
if(c == undefined){
	c = 0;
}
var a;
if(navigator.appName.indexOf("Microsoft")!=-1)
{
a=window['paembedplayer'+c+'id']
}
else
{
a=document['paembedplayer'+c+'id']
}
a.pap_pause();
}
function _pap_isplaying(c)
{
if(c == undefined){
	c = 0;
}
var a;
if(navigator.appName.indexOf("Microsoft")!=-1)
{
a=window['paembedplayer'+c+'id']
}
else
{
a=document['paembedplayer'+c+'id']
}
var b = a.pap_isplaying();
return b;
}
function _pap_resize(x,y){
var a;
if(navigator.appName.indexOf("Microsoft")!=-1)
{
a=window['paembedplayer0id']
}
else
{
a=document['paembedplayer0id']
}
a.style.width=x+'px';
a.style.height=y+'px';
}
function _pap_search(d,a,b,c,f){
document.write('<div id="_searchbridge" style="display:none; visibility: hidden;">searching video...</div>');
var e = { callback:d, searchstring:a };
if(b != undefined){
	e.brandid = b;
}
if(c != undefined && c){
	e.bydate = 1;
} else {
	e.bydate = 0;
}
swfobject.embedSWF(_papsearchurl,"_searchbridge","10","10","9",null,e,{allowScriptAccess:"always",wmode:"transparent"},{ id:'_searchbridgeid',name:'_searchbridgena' });
if(f){
	return false;
}
}
function _pap_inplacesearchprep(){
document.write('<div id="_searchbridge" style="display:none; visibility: hidden;">searching video...</div>');
swfobject.embedSWF(_papsearchdefurl,"_searchbridge","10","10","9",null,null,{allowScriptAccess:"always",wmode:"transparent"},{ id:'searchbridgeid',name:'_searchbridgena' });
}
function _pap_inplacesearch(f,b,c,d){
var a;
var bydate = 0;
if(navigator.appName.indexOf("Microsoft")!=-1)
{
a=window['searchbridgeid']
}
else
{
a=document['searchbridgeid']
}
if(d != undefined && d){
	bydate = 1;
} else {
	bydate = 0;
}
a.srh(f,b,c,bydate);
}

