// popup code
function openWindow(url, name) {
  var l = openWindow.arguments.length;
  var w = "";
  var h = "";
  var features = "";

  for (i=2; i<l; i++) {
    var param = openWindow.arguments[i];
    if ( (parseInt(param) == 0) ||
      (isNaN(parseInt(param))) ) {
      features += param + ',';
    } else {
      (w == "") ? w = "width=" + param + "," :
       h = "height=" + param;
    }
  }

  features += w + h;
  var code = "popupWin = window.open(url, name";
  if (l > 2) code += ", '" + features;
  code += "')";
  eval(code);
  }
  
// drop down menu
function gotosite(site) {            
        if (site != "") {                    
                self.location=site; 
        }
}    

// specific drop down menus
function current() {location=document.current.menu.options[document.current.menu.selectedIndex].value;}

function transcripts() {location=document.transcripts.menu.options[document.transcripts.menu.selectedIndex].value;}

function stories() {location=document.stories.menu.options[document.stories.menu.selectedIndex].value;}

function audiodrop() {
	eval("launchPBSAudioPlayer('"+document.audio.menu.value+"','','playertemplate=/wnet/religionandethics/media_player/audio.html')");
}

// write media player javascript
document.write('<script src="/mediaplayer/player.js" language="JavaScript"></script>');

PBSAudioWindow_X=354;
PBSAudioWindow_Y=128;

PBSVideoWindow_X=598;
PBSVideoWindow_Y=348;


// email this page
var fileName = document.URL;
escapedFileName = escape(fileName);
function openemail()
{
var popurl="../email_friend/email.html?"+escapedFileName;
winpops=window.open(popurl,"","width=400,height=365,status,");
}

// feedback

function feedback()
{
var popurl="../feedback_pop/feedback.html?"+escapedFileName;
winpops=window.open(popurl,"","width=400,height=365,status,");
}

// lesson plan feedback

function lp_feedback()
{
var popurl="../feedback_pop/lp_feedback.html?"+escapedFileName;
winpops=window.open(popurl,"","width=400,height=365,status,");
}

// old pic pops
var  remoteWin = null;
parent.name = "main";
function open_wide(path,targ) {
	litwin = window.open(path,targ,"width=410,height=450,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizeable=yes");
	if ((window.navigator.appName.indexOf("Microsoft")==0) & (window.navigator.appVersion.substring(0,1)=="4")) {
 		damnBrowser = 1;
	} else if ((window.navigator.appName.indexOf("Netscape")==0) & (window.navigator.appVersion.substring(0,1)=="4")) {
		damnBrowser = 1;
	} else if (parseFloat(navigator.appVersion.substring(0,navigator.appVersion.indexOf(" ")))>=3.0) {
    	litwin.focus();
	}
}

// old pic pops
var  remoteWin = null;
parent.name = "main";
function open_wide1(path,targ) {
	litwin = window.open(path,targ,"width=410,height=470,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizeable=yes");
	if ((window.navigator.appName.indexOf("Microsoft")==0) & (window.navigator.appVersion.substring(0,1)=="4")) {
 		damnBrowser = 1;
	} else if ((window.navigator.appName.indexOf("Netscape")==0) & (window.navigator.appVersion.substring(0,1)=="4")) {
		damnBrowser = 1;
	} else if (parseFloat(navigator.appVersion.substring(0,navigator.appVersion.indexOf(" ")))>=3.0) {
    	litwin.focus();
	}
}

// calendar date popups
var name = "";
function cal(holiday) {openWindow(name="dates/"+holiday+".html",'date', 359, 350, 'scrollbars', 'status');}


// Sizer Code Below



// Changes the font size of the element and stores the size in a cookie
function changeFontSize(strID, strSize)
{
	// get the element
	document.getElementById(strID).style.fontSize = strSize;
	// set the cookie
	SetCookie("fontSize",strSize,"December,31,2009");
}

// Function to find any cookied font size on the clients machine and set the font to their preference as specified in the cookie
function getFontSize(strID) {
	// check if the object whose id is given exists
	if(document.getElementById(strID)) {
				
		// create regular expression to match pattern 'fontSize=.......' till a semicolon is encountered or the string ends
		var regEx = new RegExp("fontSize=[^;]+");
				
		// if cookie exists
		if(regEx.test(document.cookie)){
			
			// if match found, then extract the part of the string matching the regular expression pattern
			var cookieEntry = document.cookie.toString().match(regEx);
			
			if(cookieEntry != '') {
			
				// from the match, extract the font size
				var fontSize = cookieEntry.toString().substring(9, cookieEntry.toString().length);
				
				// call the function to change the font size accordingly
				changeFontSize(strID, fontSize.toString());
			}
		}		
	}	
}

function SetCookie(name,value,expires)
{
	var exp = new Date(expires);
	document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); + ";path=";
}

/// sizes

function size11() {changeFontSize('text', '11px'); changeFontSize('text2', '11px');}
function size12() {changeFontSize('text', '12px'); changeFontSize('text2', '12px');}
function size14() {changeFontSize('text', '14px'); changeFontSize('text2', '14px');}
function size16() {changeFontSize('text', '16px'); changeFontSize('text2', '16px');}
function size18() {changeFontSize('text', '18px'); changeFontSize('text2', '18px');}

function size11b() {changeFontSize('text', '11px')} 
function size12b() {changeFontSize('text', '12px')}
function size14b() {changeFontSize('text', '14px')}
function size16b() {changeFontSize('text', '16px')}
function size18b() {changeFontSize('text', '18px')}

// dhtml for embeded video

document.WM = new Object();
document.WM.menu = new Object();
document.WM.menu.dropdown = new Array();

function WM_initializeToolbar(){
    var i;
    if (document.all){
	for(i = 0; i < document.all('container').all.length; i++){
	    if ((document.all('container').all[i].className == 'header') ||
(document.all('container').all[i].className == 'links')){
		document.WM.menu.dropdown[document.WM.menu.dropdown.length]
= document.all('container').all[i];
	    }
	}
    } else if (document.getElementsByTagName && document.getElementById){
	var contained =
document.getElementById('container').getElementsByTagName('div');
	for(i = 0; i < contained.length; i++){
	    if ((contained[i].getAttribute('class') == 'header') ||
(contained[i].getAttribute('class') == 'links')){
		document.WM.menu.dropdown[document.WM.menu.dropdown.length]
= contained[i];
	    }
	}
    }
}

function WM_collapse(item){
    if(document.WM.menu.dropdown.length){
	if (document.WM.menu.dropdown[item + 1].style.display == 'none'){
	    document.WM.menu.dropdown[item + 1].style.display = '';} 
	else { document.WM.menu.dropdown[item + 1].style.display = 'none';}
    }
}