var curtab = -1;
var _gcurtab = -1;
var navon = false;
var navov = false;
var navextov = false;
var ival = new Number();
var ison = false;
var cat_has = new Array();

function spawn (targ,x,y) {
	window.open(targ,'secondary','width=' + x + ',height=' + y + ',scrollbars=yes');
}

function stopclicking(button) {
	button.value = "please wait";
	return true;
}
				  
function preload() { if (document.images) { if (typeof(document.F) == 'undefined'){ document.F = new Object(); } document.F.loadedImages = new Array(); var argLength = preload.arguments.length; for(arg=0;arg<argLength;arg++) { document.F.loadedImages[arg] = new Image(); document.F.loadedImages[arg].src = preload.arguments[arg]; } } }
function imageswap(daImage, daSrc){ var objStr,obj; if(document.images){ if (typeof(daImage) == 'string') { objStr = 'document.' + daImage; obj = eval(objStr); obj.src = daSrc; } else if ((typeof(daImage) == 'object') && daImage && daImage.src) { daImage.src = daSrc; } } }

function videobox(urlprefix,url){
	window.open("http://www.pbs.org/wgbh/pages/frontline/"+urlprefix+url+".html","video","toolbar=no,location=no,directories=no,menubar=no,width=680,height=700,scrollbars=yes");
}

function setcookie(name,value) {
 	var today = new Date();
	 var expire = new Date();
	 var nDays = 180;
 	 expire.setTime(today.getTime() + 3600000*24*nDays);
	 document.cookie = name+"="+escape(value) + ";path=/wgbh/pages/frontline/;expires="+expire.toGMTString();
}

function searchsubmit(){
	document.topnavform.q.value = document.searchform.q.value + '+:site:www.pbs.org/wgbh/pages/frontline';
	document.topnavform.submit();
}

function handleclick (targ) {
	opener.location.href = targ;
	window.close(self);	
}

function subtitle(targetdiv,target){
	if(document.getElementById(targetdiv)){
		document.getElementById(targetdiv).innerHTML = target;
	}
}

var issafari=false;
if(navigator.userAgent.indexOf("Safari")!=-1)
{
issafari=true
}
function toggle(target,onoff){
	if(document.getElementById(target)){
		if(currentdiv != undefined){
			changeclass(currentdiv + 'o','wrapper');	
			document.getElementById(currentdiv).style.display = 'none';
		}

		if(onoff == 1){	
			document.getElementById(target).style.display = 'inline';
			changeclass(target + 'o','wrapper_on');	
		} else {
			document.getElementById(target).style.display = 'none';
			changeclass(target + 'o','wrapper');	
		}
	
		currentdiv = target;
	}
}

function global_toggle (targetdiv){
	if(!topon[targetdiv]){
		topon[targetdiv] = true;
		$('#'+targetdiv).css({display: 'block'});
		$('#'+targetdiv).hide();
		$('#'+targetdiv).fadeIn('fast');
		document.getElementById(targetdiv+'_but').className = 'sel';
		toggleInterval = setInterval(function () { global_toggle(targetdiv,false) }, 60000);
	} else {
		topon[targetdiv] = false;
		clearInterval(toggleInterval);
		document.getElementById(targetdiv+'_but').className = '';
		$('#'+targetdiv).fadeOut('fast', function () { $('#'+targetdiv).css({display: 'none'}) });
	}
}



function legacyvideoplayer(stayopen,clipid,baseurl,pkgcode,cachetitle,nocache) {
	var h = {};
	h.pap_url = location.href;
	h.clipid = clipid;
	h.brandcode = 'frol';
	h.pkgcode = pkgcode;
	h.cachetitle = cachetitle;
	h.mainurl = baseurl;
	h.pap_usecache = (nocache)? false:true;

	if(issafari){
		h.pap_safari = 1;
	}
	var myheight = 30;
	if(stayopen){
		h.loadnow = true;
		myheight = 430;
	} else {
		h.compressedmode = true
		h.compressed = true
	}
	swfobject.embedSWF('http://www.pbs.org/wgbh/pages/frontline/includes/swf/combined_2012.swf','videospace','100%',myheight,'9',null, h,{ wmode:"opaque",allowFullScreen:"true",allowScriptAccess:"always" },{ id:'bigplaya_id', name:'bigplaya_nm' });
}

function videoplayer_open (full) {
	var a;
if(navigator.appName.indexOf("Microsoft")!=-1)
{
a=window['bigplaya_id']
}
else
{
a=document['bigplaya_id']
}
var newheight = (full)? '430px':'90px';
if(full){
	newheight = '430px';
}

a.style.height= newheight;
}

function videoplayer_close (full) {
	var a;
if(navigator.appName.indexOf("Microsoft")!=-1)
{
a=window['bigplaya_id']
}
else
{
a=document['bigplaya_id']
}

a.style.height='30px';

}


$(document).ready(function () {
	if(navigator.userAgent && navigator.userAgent.indexOf('iPad') != -1){
		_isipad = true;
	}	
	$("#_gnav").find("a").each(function () {
		$(this).mouseenter(function () {
			$(".non").removeClass('non');
			$(this).addClass('non');
			nav_tab($(this).attr('tab'));
			if(!navon){
				nav_in_decide();
				ison = true;
			}
		});
	});
	$("#_gnav").mouseenter(function () {
		navov = true;
	});
	$("#_gnav").mouseleave(function () {
		navov = false;
		ison = false;
		nav_out_decide();
	});

});

function nav_in () {
	if(navov){
		navon = true;
		$("#_gnext").stop();
		$("#_gnext").css({ 'opacity':1 });
		$("#_gnext").fadeIn();
		$("#_gnext").mouseenter(function () {
			navextov = true;
		});
		$("#t"+_gcurtab).removeClass('non').addClass('non');
		$("#_gnext").mouseleave(function () {
			navextov = false;
			nav_out_decide();
		});
		$("#extscl").click(function () {
			navov = false;
			navextov = false;
			nav_out();
		});
	}
}

function nav_in_decide () {
	oval = setTimeout("nav_in()",400);
}

function nav_tab (idx){
	_gcurtab = idx;
	$(".tab").hide();
	$("#_gtab"+idx).show();
}

function nav_out_decide () {
	ival = setTimeout("nav_out()",400);
}
		
function nav_out () {
	if(!navov && !navextov){
		$("#extscl").unbind('click');
		$("#_gnext").unbind('mouseenter');
		$("#_gnext").unbind('mouseleave');
		$("#_gnext").stop();
		$("#_gnext").fadeOut();
		$(".non").removeClass('non');
		navon = false;
	}
}


