/* GLOBAL AMERICAN DOCUMENTARY JAVASCRIPT */
/* Last modified 2/9/05 */

// CONTENTS:
// - Media Player PBS
// - Rollovers for banner navigation
// - General Popups
// - Local Broadcast
// - Reminders and Others

// Find our location so we can use relative links in our scripts

// var locStart = location.href.lastIndexOf("/amdoc.woo.local/") + 16;
var locStart = location.href.lastIndexOf("amdoc.org/") + 11;
var locEnd = location.href.substring(locStart, location.href.length);
slashes = locEnd.split("/").length - 1;

//  Find out how many levels to climb for the directory prefix
var dirPrefix = "";		
	for (var i=0; i < slashes; i++) {
		dirPrefix += "../";	
	}
	
/* ------------------------------------------------------------ */
/* Media Player PBS */
/* ------------------------------------------------------------ */

// Variables for window dimensions
PBSAudioWindow_X = 595; 
PBSAudioWindow_Y = 380; 
PBSVideoWindow_X = 595; 
PBSVideoWindow_Y = 390; 

// Import the PBS Media Player
// document.write("<script src='\/mediaplayer\/player.js'><\/script>");

/* ------------------------------------------------------------ */
/* Rollovers for banner navigation */
/* ------------------------------------------------------------ */

imageObj = new Image();
// imageObj.src = dirPrefix + "i/banner/background.jpg";
// PLACE PRE-LOADERS FOR HOMEPAGE BANNER

function initializePage(){
// To do when a main site page loads
loadAdditionalNav();
}

function loadAdditionalNav(){
// Preload images for Main Navigation
var i = 0;
imageObj = new Image();
imgs = new Array();
imgs[0]= dirPrefix + "i/banner/nav/about_off.gif";
imgs[1]= dirPrefix + "i/banner/nav/about_over.gif";
imgs[2]= dirPrefix + "i/banner/nav/about_on.gif";
imgs[3]= dirPrefix + "i/banner/nav/producers_off.gif";
imgs[4]= dirPrefix + "i/banner/nav/producers_over.gif";
imgs[5]= dirPrefix + "i/banner/nav/producers_on.gif";
imgs[6]= dirPrefix + "i/banner/nav/partners_off.gif";
imgs[7]= dirPrefix + "i/banner/nav/partners_over.gif";
imgs[8]= dirPrefix + "i/banner/nav/partners_on.gif";
imgs[9]= dirPrefix + "i/banner/nav/outreach_off.gif";
imgs[10]= dirPrefix + "i/banner/nav/outreach_over.gif";
imgs[11]= dirPrefix + "i/banner/nav/outreach_on.gif";
imgs[12]= dirPrefix + "i/banner/nav/pressroom_off.gif";
imgs[13]= dirPrefix + "i/banner/nav/pressroom_on.gif";
imgs[14]= dirPrefix + "i/banner/nav/pressroom_over.gif";
imgs[15]= dirPrefix + "i/banner/nav/portfolio_off.gif";
imgs[16]= dirPrefix + "i/banner/nav/portfolio_on.gif";
imgs[17]= dirPrefix + "i/banner/nav/portfolio_over.gif";
for(i=0; i<=(imgs.length-1); i++) 
{
imageObj.src=imgs[i];
}
}

function swapNav(b){
	if (document.images){
		but=b.getAttribute('name');
		state = ((document[but].src).indexOf('_over.gif'));
		if (state > 1){
		bSrc= (dirPrefix + "i/banner/nav/" + but + "_off.gif");
	} else {
		bSrc= (dirPrefix + "i/banner/nav/" + but + "_over.gif");
	}
	}
	document[but].src = bSrc;
}

function swapSectionNav(b){
	if (document.images){
		but=b.getAttribute('name');
		state = ((document[but].src).indexOf('_over.gif'));
		if (state > 1){
		bSrc= (dirPrefix + "i/sectionnav/" + but + "_off.gif");
	} else {
		bSrc= (dirPrefix + "i/sectionnav/" + but + "_over.gif");
	}
	}
	document[but].src = bSrc;
}

/* ------------------------------------------------------------ */
/* General Popups */
/* ------------------------------------------------------------ */

function isUndefined(v) {
var undef;
return v===undef;
}
var _POPUP_FEATURES = 'location=0, statusbar=0, menubar=0,scrollbars=0,resizeable=0,directores=0,width=595, height=390';

function raw_popup(url, target, features) {
if (isUndefined(features)) {
features = _POPUP_FEATURES;
}
if (isUndefined(target)) {
target = '_blank';
}
var theWindow = window.open(url, target, features);
theWindow.focus();
return theWindow;
}

function link_popup(src, features){
return raw_popup(src.getAttribute('href'), src.getAttribute('target') ||'_blank', features);
}

function popUp(page,w,h) {
// deprecated 
params="width= "+w+",height= "+h+" ,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0";
OpenWin = this.open(page, "popupwindow", params);
}

function POVWindowPopper( url,name,w,h,scroll ) {	
	// default name
	if( !name ){
		name = "POVPopup";
	}	
	// default width
	if( !w ){
		w = 595;
	}	
	// default height
	if( !h ){
		h = 390;
	}	
	// default scroll
	if( !scroll ){
		scroll = "no";
	}
	else{
		scroll = "yes";
	}	
	// set up options string
	var opt = "toolbar=no,location=no,directories=no,menubar=no,width= " + w + ",height= " + h + ",resizable=no,scrollbars= " + scroll + ",scrolling= " + scroll + ",status=yes";
 
	// open the window
	floater=window.open(url,name,opt);
	floater.creator = self;
	
	// focus the window
	if( window.focus ){
		floater.focus();
	}	
}


/* ------------------------------------------------------------ */
/* Local Broadcast */
/* ------------------------------------------------------------ */

function openLocalBroadcast_v4(src) {
var features ='toolbar=no,directories=no,status=yes,menubar=no,scrolling=yes,scrollbars=yes,resizable=no,width=620,height=473,top=100,left=100';
link_popup(src,features);
}

/* ------------------------------------------------------------ */
/* Video Popup */
/* ------------------------------------------------------------ */

function watchVideo(dir,media,title) {
var page = "popup_videoplayer.php?dir="+dir+"&media="+media+"&title="+title;
popUp (page, 404, 386);
}

/* ------------------------------------------------------------ */
/* Reminders and Others */
/* ------------------------------------------------------------ */

function footerRemind(src) {
var features ='toolbar=0,location=0,directories=0,scrollbars=yes,status=0,menubar=0,resizeable=0,width=545,height=355,top=50,left=50';
link_popup(src,features);
} 

function tellAFriend(src) {
var features ='toolbar=no,directories=no,status=no,menubar=no,scrolling=no,scrollbars=no,resizable=no,width=307,height=288';
link_popup(src,features);
}

/* Check for email */
/* Input text field should be named "email" */

function checkForEmail( f ){
	// a reference to the form
	//f = document.askff;
	// store field vars for convenience
	e_val = f.email.value;
	if (e_val.length < 1 ) {
		f.email.focus();
		alert ('Please enter your e-mail address')
		return false;
	}		
	return true;
}

/* Clear and restore default input fields */

function clickclear(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
}
}

function clickrecall(thisfield, defaulttext) {
if (thisfield.value == "") {
thisfield.value = defaulttext;
}
}


