// Variables for layer content
var msg1 = "Military Focuses on Financial Literacy";
var msg2 = "India&#039;s Economy Grows Despite Global Recession";
var msg3 = "Calif. Students Protest Tuition Hike";
var msg4 = "Health Reform Showdown in Senate";
var msg5 = "Bosnia Still Fragile After 14 Years";

var image1 = "http://www.pbs.org/newshour/homepage-images/medium/july-dec09/1124_army.jpg";
var image2 = "http://www.pbs.org/newshour/extra/images/medium/july-dec09/india.jpg";
var image3 = "http://www.pbs.org/newshour/extra/images/medium/july-dec09/college.jpg";
var image4 = "http://www.pbs.org/newshour/homepage-images/medium/july-dec09/1119_reid.jpg";
var image5 = "http://www.pbs.org/newshour/homepage-images/medium/july-dec09/herz_tim-cullen-wb.jpg";

var alt1 = "Army";
var alt2 = "India";
var alt3 = "College";
var alt4 = "Senator Harry Reid";
var alt5 = "Herzegovina; courtesy Tim Cullen/World Bank";

var url1 = "http://www.pbs.org/newshour/extra/video/blog/";
var url2 = "http://www.pbs.org/newshour/extra/video/blog/2009/11/indias_economy_grows_despite_g.html";
var url3 = "http://www.pbs.org/newshour/extra/video/blog/2009/11/calif_students_protest_tuition.html";
var url4 = "http://www.pbs.org/newshour/extra/video/blog/2009/11/health_reform_showdown_in_sena.html";
var url5 = "http://www.pbs.org/newshour/extra/video/blog/2009/11/bosnia_still_fragile_after_14.html";

/*****************************************************************************************
	dw_write.js	
	write to positioned div (absolute or relative)
	Designed specifically to provide capability for ns4 to write to a layer in a table 
	For writing to absolute-positioned layer you can also use dw_core.js.
	version date: April 2003
	
	This code is from Dynamic Web Coding 
  at http://www.dyn-web.com/
  Copyright 2001-3 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  Permission granted to use this code 
  as long as this entire notice is included.	
*******************************************************************************************/

// constructor function (x,y optional)
function writeObj(id,wd,ht,x,y) {
	if (!id) return;	// for when writeObj used as prototype
	if (document.getElementById||document.all) {
		this.el = (document.getElementById)? document.getElementById(id): document.all[id];
		this.css = this.el.style;	this.doc = this.el;
		this.css.width=wd+"px"; this.css.height=ht+"px";
  } else if (document.layers) {
		var lyrRef = getLyrRef(id,document);	// in case id nested
		// create layer inside to write to
		// in case id relative positioned
		this.el = new Layer(wd,lyrRef);	
		lyrRef.resizeTo(wd,ht);
		this.el.visibility = "inherit";	// new Layer initially hidden
		this.doc = this.el.document;	// write to inner layer
		// use outer layer for shifting, show/hide
		this.css = this.el.parentLayer; 
	} else return null; // (if not ...byId or ...all or ...layers)
	var px = (document.layers)? "": "px";
	this.x = x || 0;	if (x) this.css.left = this.x+px;
	this.y = y || 0;	if (y) this.css.top = this.y+px;
	this.obj = id+"Object"; eval(this.obj+"=this");	// used by banner
}

//  Methods
writeObj.prototype.writeLyr = function (cntnt) {
	if (typeof this.doc.innerHTML!="undefined") {
      this.doc.innerHTML = cntnt;
  } else if (document.layers) {
			this.doc.write(cntnt);
			this.doc.close();
  }
}

writeObj.prototype.show = function () { this.css.visibility = "visible"; }
writeObj.prototype.hide = function () { this.css.visibility = "hidden"; }

writeObj.prototype.shiftTo = function (x,y) {
	if (x!=null) this.x=x; if (y!=null) this.y=y;	
	if (this.css.moveTo) { 
		this.css.moveTo(Math.round(this.x),Math.round(this.y)); 
	} else { 
		this.css.left=Math.round(this.x)+"px"; 
		this.css.top=Math.round(this.y)+"px"; 
	}
}

writeObj.prototype.shiftBy = function (x,y) {
	this.shiftTo(this.x+x,this.y+y);
}

// credit to http://www.13thparallel.org for the following 2 functions
// returns amount of vertical scroll
function getScrollY() {
	var sy = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		sy = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		sy = document.body.scrollTop; 
	else if (window.pageYOffset)
		sy = window.pageYOffset;
	else if (window.scrollY)
		sy = window.scrollY;
	return sy;
}

// returns amount of horizontal scroll
function getScrollX() {
	var sx = 0;
	if (document.documentElement && document.documentElement.scrollLeft)
		sx = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft) 
		sx = document.body.scrollLeft; 
	else if (window.pageXOffset)
		sx = window.pageXOffset;
	else if (window.scrollX)
		sx = window.scrollX;
	return sx;
}


// get reference to nested layer for ns4
// from dhtmllib.js by Mike Hall of www.brainjar.com
function getLyrRef(lyr,doc) {
	if (document.layers) {
		var theLyr;
		for (var i=0; i<doc.layers.length; i++) {
	  	theLyr = doc.layers[i];
			if (theLyr.name == lyr) return theLyr;
			else if (theLyr.document.layers.length > 0) 
	    	if ((theLyr = getLyrRef(lyr,theLyr.document)) != null)
					return theLyr;
	  }
		return null;
  }
}


function ChangeBuzzGraphics(ImageName, msg1, msg2, msg3, msg4, msg5) { 
	if (ImageName == "1") {
		MM_swapImage('buzz','','image1','1');
		showInfo('1',msg1,image1,alt1,url1);
		buzz1.className = 'rollmenubuzz_over';
		buzz2.className = 'rollmenubuzz';
		buzz3.className = 'rollmenubuzz';
		buzz4.className = 'rollmenubuzz';
		buzz5.className = 'rollmenubuzz';
	}
	if (ImageName == "2") {
		MM_swapImage('buzz','','image2','1');	
		showInfo('2',msg2,image2,alt2,url2);
		buzz1.className = 'rollmenubuzz';
		buzz2.className = 'rollmenubuzz_over';
		buzz3.className = 'rollmenubuzz';
		buzz4.className = 'rollmenubuzz';
		buzz5.className = 'rollmenubuzz';		
	}	
	if (ImageName == "3") {
		MM_swapImage('buzz','','image3','1');
		showInfo('3',msg3,image3,alt3,url3);
		buzz1.className = 'rollmenubuzz';
		buzz2.className = 'rollmenubuzz';
		buzz3.className = 'rollmenubuzz_over';
		buzz4.className = 'rollmenubuzz';
		buzz5.className = 'rollmenubuzz';	
	}	
	if (ImageName == "4") {
		MM_swapImage('buzz','','image4','1');
		showInfo('4',msg4,image4,alt4,url4);
		buzz1.className = 'rollmenubuzz';
		buzz2.className = 'rollmenubuzz';
		buzz3.className = 'rollmenubuzz';
		buzz4.className = 'rollmenubuzz_over';
		buzz5.className = 'rollmenubuzz';	
	}	
	if (ImageName == "5") {
		MM_swapImage('buzz','','image5','1');
		showInfo('5',msg5,image5,alt5,url5);
		buzz1.className = 'rollmenubuzz';
		buzz2.className = 'rollmenubuzz';
		buzz3.className = 'rollmenubuzz';
		buzz4.className = 'rollmenubuzz';
		buzz5.className = 'rollmenubuzz_over';	
	}		
}


// resize fix for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

// put images to preload in this array
var preload_list = new Array("http://www.pbs.org/newshour/homepage-images/medium/july-dec09/1124_army.jpg", "http://www.pbs.org/newshour/extra/images/medium/july-dec09/india.jpg", "http://www.pbs.org/newshour/extra/images/medium/july-dec09/college.jpg", "http://www.pbs.org/newshour/homepage-images/medium/july-dec09/1119_reid.jpg", "http://www.pbs.org/newshour/homepage-images/medium/july-dec09/herz_tim-cullen-wb.jpg");

// preload 
if (document.images) {
	var image_list = new Array();
	for (var preload_counter=0; preload_counter<preload_list.length; preload_counter++) {
	image_list[preload_counter] = new Image(); 
		image_list[preload_counter].src = preload_list[preload_counter];	
  }
}

var infoLyr;
function initInfoLyr() {
	// call constructor to create write layer
	// arguments: id, width, height
	// be sure to set height large enough or ns4 will clip it off
	infoLyr = new writeObj('infoDiv',140,44);
	infoLyr2 = new writeObj('infoDiv2',140,100);
	showInfo('1',msg1,image1,alt1,url1);			
}		

function showInfo(num, txt, image, alttag, curl) {
	if (!infoLyr) return;
	var txt = txt;
	var image = image;
	var curl = curl;
	infoLyr.writeLyr('<a href="' + curl + '">' + txt + '</a>');	 
	infoLyr2.writeLyr('<a href="' + curl + '"><img SRC="' + image + '" WIDTH="140" HEIGHT="100" BORDER="0" ALT="' + alttag + '"></a>');	 
}

//window.onload=initInfoLyr;
