var watchtogglestate = 0;
// watchtogglestate: 0 - normal, 1 - clicked
var divcontents = "";
var currentblurb = 99;
var photos = 1;
var globalnavwidth = 27;
var teasestatus = 0;
var videostatus = '';
if(getcookie('aidsstatus') != "") videostatus = getcookie('aidsstatus');

var minbrowser = false;

chaptertext = new Array();
chaptertext[0] = '<p><span class="title"><span class="chn">Part One - Chapter 1</span> A Deadly New Disease</span>&nbsp;<a href="javascript:playerpop(\'1\',1)" class="viewlink">VIEW</a><br />Summer 1981. Young gay men are dying of serious and rare infections due to damaged immune systems - cause unknown. The mystery deepens: Men and women of Haitian ancestry also have it.</p>';
chaptertext[1] = '<p><span class="title"><span class="chn">Part One - Chapter 2</span> The Spread Escalates</span>&nbsp;<a href="javascript:playerpop(\'2\',1)" class="viewlink">VIEW</a><br />I/V drug users and haemophiliacs now have the mystery disease. The CDC warns it is in the blood supply, it must be a virus, and quick action is needed. No one listens.</p>';
chaptertext[2] = '<p><span class="title"><span class="chn">Part One - Chapter 3</span> Politics & Tracking AIDS\' History</span>&nbsp;<a href="javascript:playerpop(\'3\',1)" class="viewlink">VIEW</a><br />Reagan budget cuts hurt AIDS research. San Francisco battles over closing the bathhouses.In the Congo, scientists find AIDS is in the general population and learn how it got to Haiti.</p>';
chaptertext[3] = '<p><span class="title"><span class="chn">Part One - Chapter 4</span> Scientific Breakthroughs</span>&nbsp;<a href="javascript:playerpop(\'4\',1)" class="viewlink">VIEW</a><br />Scientists discover when HIV first crossed the species barrier from chimpanzee to human. They also isolate the virus and develop a blood test for it. But the new test reveals deep problems.</p>';
chaptertext[4] = '<p><span class="title"><span class="chn">Part One - Chapter 5</span> A Death Gives AIDS a Face</span>&nbsp;<a href="javascript:playerpop(\'5\',1)" class="viewlink">VIEW</a><br />Rock Hudson\'s death wakes up millions to the reality of AIDS. It also brings a backlash of fear and discrimination. President Reagan still distances himself from the epidemic.</p>';
chaptertext[5] = '<p><span class="title"><span class="chn">Part One - Chapter 6</span> The Power of Leadership</span>&nbsp;<a href="javascript:playerpop(\'6\',1)" class="viewlink">VIEW</a><br />Two million have HIV by 1985, most in Africa. Jonathan Mann of W.H.O sounds the alarm. Uganda shows prevention campaigns can work. In Thailand, one man almost single-handedly makes a difference.</p>';
chaptertext[6] = '<p><span class="title"><span class="chn">Part One - Chapter 7</span> Setbacks</span>&nbsp;<a href="javascript:playerpop(\'7\',1)" class="viewlink">VIEW</a><br />Politics and cultural taboos derail needle exchange and sex education programs in the U.S. And AZT, the first effective AIDS drug, is not the cure it first seemed to be.</p>';
chaptertext[7] = '<p><span class="title"><span class="chn">Part One - Chapter 8</span> At the Brink</span>&nbsp;<a href="javascript:playerpop(\'8\',1)" class="viewlink">VIEW</a><br />President Reagan gives his only speech on AIDS. The years of inaction continue. By 1990 one million Americans are infected. Worry grows about a global pandemic, and Jonathan Mann departs W.H.O.</p>';
chaptertext[8] = '<p><span class="title"><span class="chn">Part Two - Chapter 1</span> Political Indifference</span>&nbsp;<a href="javascript:playerpop(\'9\',1)" class="viewlink">VIEW</a><br />In South Africa, HIV infection accelerates. But during his five years in office President Mandela barely mentions AIDS. His country\'s epidemic is on its way to becoming the world\'s largest.</p>';
chaptertext[9] = '<p><span class="title"><span class="chn">Part Two - Chapter 2</span> A Radical New Treatment</span>&nbsp;<a href="javascript:playerpop(\'10\',1)" class="viewlink">VIEW</a><br />In 1996 Dr. David Ho develops the "triple cocktail" of antiretroviral drugs. HIV infection is no longer a death sentence. But 20 million Africans who need the drugs can\'t pay for them.</p>';
chaptertext[10] = '<p><span class="title"><span class="chn">Part Two - Chapter 3</span> The Struggle to Get the Drugs</span>&nbsp;<a href="javascript:playerpop(\'11\',1)" class="viewlink">VIEW</a><br />In the U.S., not everyone will get the new HIV drugs, while in Brazil they\'re provided to all. In South Africa, President Mbeki bans the drugs from government hospitals, claiming they\'re too toxic.</p>';
chaptertext[11] = '<p><span class="title"><span class="chn">Part Two - Chapter 4</span> The Relentless Spread</span>&nbsp;<a href="javascript:playerpop(\'12\',1)" class="viewlink">VIEW</a><br />Twenty million have died of AIDS by the late 1990s. Wherever people inject drugs, HIV follows. President Mbeki repeats the denialists\' claim that AIDS in Africa is caused by poverty, not HIV.</p>';
chaptertext[12] = '<p><span class="title"><span class="chn">Part Two - Chapter 5</span> Financing the Battle</span>&nbsp;<a href="javascript:playerpop(\'13\',1)" class="viewlink">VIEW</a><br />An unlikely alliance of the evangelical community, Bono, and Jesse Helms presses for a U.S. response. President Bush creates the $15 billion PEPFAR fund, sidestepping the U.N. Global Fund.</p>';
chaptertext[13] = '<p><span class="title"><span class="chn">Part Two - Chapter 6</span> New Challenges</span>&nbsp;<a href="javascript:playerpop(\'14\',1)" class="viewlink">VIEW</a><br />China, Ethiopia and Uganda encounter obstacles in treating and preventing HIV. And scientists realize the limitations of HIV drugs: the virus never disappears from the body.</p>';
chaptertext[14] = '<p><span class="title"><span class="chn">Part Two - Chapter 7</span> 40m Infections + 40m To Come</span>&nbsp;<a href="javascript:playerpop(\'15\',1)" class="viewlink">VIEW</a><br />The battle in India, Brazil and South Africa continues; 95% of new infections are in developing countries. Researchers work on new prevention tools, but an AIDS vaccine remains elusive.</p>';


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 watchtoggle(action) {
	// action: 1 - click, 2 - rollover, 3 - rollout, 4 - reload
	var mywidth = getwidth() - globalnavwidth;
	
	switch(watchtogglestate){
		case 0:
			switch(action){
				case 1:
					if (minbrowser) {
						location = '../view/';
					} else {
						if(teasestatus == 1){
							hidediv('viewtease');
						}
						imageswap(document.pn2,'../art/p_n2s.gif');
						watchtogglestate = 1;
						if (videostatus == '' || videostatus == null) {
							location = '../view/';
						} else {
							setupprogbrowser(1);
							changediv('viewdiv',divcontents)
							if(currentblurb < 99) changediv('blurbarea',chaptertext[currentblurb])
							showdiv('viewdiv',mywidth);
							movepage('retract',110);
							movepage('retractphoto',80);
						}
					}
					break;
				case 2:
					imageswap(document.pn2,'../art/p_n2a.gif');
					if (videostatus != '' || videostatus != null) {
						changediv('viewtease','<p>Click to navigate the program</p>');
						showdiv('viewtease',300);
						teasestatus = 1;
					}
					break;
				case 3:
					imageswap(document.pn2,'../art/p_n2.gif');
					if(teasestatus == 1){
						hidediv('viewtease');
					}
					break;
			}
			break;
		case 1:
			switch(action){
				case 1:
					imageswap(document.pn2,'../art/p_n2.gif');
					watchtogglestate = 0;				
					hidediv('viewdiv');
					movepage('retract',40);
					movepage('retractphoto',0);
					break;
				case 4:
					hidediv('viewdiv');
					setupprogbrowser(0);
					changediv('viewdiv',divcontents)
					if(currentblurb < 99) changediv('blurbarea',chaptertext[currentblurb])
					showdiv('viewdiv',mywidth);					
					break;
			}
		break;
	}
}

function movepage(div,state) {
	if (document.getElementById && document.getElementById(div) != 'undefined') document.getElementById(div).style.paddingTop = state + 'px';
	else if (document.all && document.all[div] != 'undefined') document.all[div].style.paddingTop = state + 'px';
	else if (document.layers && document.layers[div] != 'undefined') document.layers[div].paddingTop = state + 'px';
}

function divswap(id,classn) {
	id.className = classn;
}

function setup() {
	preload('../art/p_n1a.gif','../art/p_n2a.gif','../art/p_n3a.gif','../art/p_n4a.gif','../art/p_n5a.gif','../art/p_n6a.gif');
	window.name = 'main';
	minbrowser = ((navigator.userAgent.indexOf("MSIE 5")!=-1) && (parseInt(navigator.appVersion)) && (navigator.userAgent.indexOf("Mac")!=-1))? true:false;
}

function donothing() {
	var nothing = 'nothing';
}

function showdiv(div,width) {
	if (document.getElementById){
		document.getElementById(div).style.visibility = "visible";
		document.getElementById(div).style.width = width + 'px';
	}
	else if (document.all) {
		document.all[div].style.visibility = "visible";
		document.all[div].style.width = width + 'px';
	} else if (document.layers) {
		document.layers[div].visibility = "show";
		document.layers[div].width = width + 'px';
	}
}

function hidediv(div) {
	var width = 710;
	if(div != 'viewdiv') width = 200;
	if (document.getElementById){
		document.getElementById(div).style.visibility = "hidden";
		document.getElementById(div).style.width = width + 'px';
	}
	else if (document.all) {
		document.all[div].style.visibility = "hidden";
		document.all[div].style.width = width + 'px';
	} else if (document.layers) {
		document.layers[div].visibility = "hide";
		document.layers[div].width = width + 'px';
	}
}

function getcookie(name) {
   var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

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


function cdiv(id,state,active) {
		switch(state) {
			case 3:
				id.className = 'navcurrentseen';
				break;
			case 2:
				id.className = 'navrightnow';
				break;
			case 0:
				id.className = 'navunseen';
				break;
			case 1:
				id.className = 'navseen';
				break;	
		}
}

function changediv(id,text) {
	if (document.getElementById) {
		document.getElementById(id).innerHTML = text;
	}
	else if (document.all) {
		document.all(id).innerHTML = text;
	}
	else if (document.layers) {
		eval("document.layers["+id+"].document.open()");
		eval("document.layers["+id+"].document.write('" + text + "')");
		eval("document.layers["+id+"].document.close()");
	}
}

function blurbreturn() {
	if(currentblurb < 99) changediv('blurbarea',chaptertext[currentblurb])
}


function checkviewdiv() {
	if(watchtogglestate == 1) {
		var mywidth = getwidth();
		showdiv('viewdiv',mywidth);
	}
}

function setvideostatus(now) {
	videostatus = videostatus.toLowerCase();
	videostatus += now;
}

function setupprogbrowser(recheck) {
	var loca = document.location.search.substring(1,255);
	var tempdivcontents = '';
	divcontents = '<div id="intviewdiv">';
	
	if(recheck != 'undefined' && recheck == 1) videostatus = getcookie('aidsstatus');
	
	var chapterstatus = [ 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o' ];
	var chaptercurrent = [ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O' ];
	var chapterurls = [ '1','2','3','4','5','6','7','8','9','10','11','12','13','14','15' ];
		
	for (var i=0;i<chapterstatus.length;i++)
	{
		if (videostatus != 'undefined' && videostatus.indexOf(chaptercurrent[i]) != -1) {
			tempdivcontents += '<td class="navrightnow" onclick="playerpop(\''+chapterurls[i]+'\',1); currentblurb='+i+';  setvideostatus(\''+chaptercurrent[i]+'\'); watchtoggle(4)" onmouseover="cdiv(this,3); changediv(\'blurbarea\',chaptertext['+i+']);" onmouseout="cdiv(this,2); blurbreturn();"><p class="nav">&nbsp;</p></td>';
			currentblurb = i;
		} else {
			if (videostatus != 'undefined' && videostatus.indexOf(chapterstatus[i]) != -1) {
				tempdivcontents += '<td class="navseen" onclick="playerpop(\''+chapterurls[i]+'\',1); currentblurb='+i+'; setvideostatus(\''+chaptercurrent[i]+'\'); watchtoggle(4);" onmouseover="cdiv(this,3); changediv(\'blurbarea\',chaptertext['+i+']);" onmouseout="cdiv(this,1); blurbreturn();"><p class="nav">&nbsp;</p></td>';
			} else {
				tempdivcontents += '<td class="navunseen" onclick="playerpop(\''+chapterurls[i]+'\',1); currentblurb='+i+';  setvideostatus(\''+chaptercurrent[i]+'\'); watchtoggle(4)" onmouseover="cdiv(this,3); changediv(\'blurbarea\',chaptertext['+i+']);" onmouseout="cdiv(this,0); blurbreturn();"><p class="nav">&nbsp;</p></td>';
			}
		}
		if (i == 7) tempdivcontents += '<td class="block"><p>&nbsp;&nbsp;</p></td>'
	}
	
	tempdivcontents += '</table>';
	
	if(currentblurb < 14){
		divcontents += '<div class="navnext" onclick="changediv(\'blurbarea\',chaptertext['+ (currentblurb + 1) +']); setvideostatus(\''+ (chaptercurrent[currentblurb+1]) +'\'); watchtoggle(4);"><p>NEXT &#187;</p></div>';
	}

	if(currentblurb > 0){
		divcontents += '<div class="iefix"><div class="navprev" onclick="changediv(\'blurbarea\',chaptertext['+ (currentblurb - 1) +']); setvideostatus(\''+ (chaptercurrent[currentblurb - 1]) +'\'); watchtoggle(4);"><p>&#171; BACK</p></div>';
	}
	
	if(photos == 1 && currentblurb < 99){
		divcontents += '<img src="../art/vnav' + (currentblurb + 1) + '.jpg" width="90" height="60" alt="" class="navp" />';
	}
	
	divcontents += '<table class="boxen">';
	divcontents += tempdivcontents;
	if(currentblurb > 0) divcontents += '</div>';
	
	divcontents += '<div id="blurbarea"></div></div><a href="javascript:watchtoggle(1)"><img src="../art/p_closebox.gif" width="86" height="13" alt="close tab" class="closetab" /></a>';

	if (loca.indexOf("pb=1") != -1) watchtoggle(1);
}


function mailafriend(target) {
	var loc = 'http://www.pbs.org/wgbh/pages/frontline/aids/etc/mailfriend.html?target=' + target;
	window.open(loc,'mailafriend',"width=570,height=435,toolbar=no,location=no,directories=no,menubar=no,resizable=yes,scrollbars=yes");
}

function docimage(target,x,y) {
	window.open(target,'docimage',"width=570,height=535,toolbar=no,location=no,directories=no,menubar=no,resizable=yes,scrollbars=yes");
}

function playerpop(target,showpart) {
	var as = '';
	if(showpart == 1) as = '?as=1';
	var win = window.open('../view/'+target+'.html'+as,'player','width=700,height=600,toolbar=no,location=no,directories=no,menubar=no,resizable=yes,scrollbars=yes');
	win.focus();
}

function getwidth () {
	var mytwidth = 0
	  if( document.documentElement && document.documentElement.clientWidth ) {
   		 mytwidth = document.documentElement.clientWidth;
	  } else if( document.body && document.body.clientWidth ) {
	    mytwidth = document.body.clientWidth;
	  }

	return mytwidth;	
}
