var defaultNavText = '';



function setNavText(newText){

	if(document.getElementById('content_title')){

		document.getElementById('content_title').innerHTML = newText;

	}

}



function clearNavText(){

	if(document.getElementById('content_title')){

		document.getElementById('content_title').innerHTML = defaultNavText;

	}

}



function getNavText(elemID){

	var strNavText = '&nbsp;';

	switch(elemID){

		case 'ch_01':

			strNavText = '<b>Introduction</b> (3:38)<br />A biography of the American poet Walt Whitman.';

			break;

		case 'ch_02':

			strNavText = '<b>The Center of Everything</b> (7:22)<br />From a working class Long Island family, 21-year-old Walt Whitman sets out to make his name in New York City.';

			break;

		case 'ch_03':

			strNavText = '<b>Captured by the City</b> (10:55)<br />As a newspaperman, Whitman stakes out radical positions. Wandering New York\'s crowded streets he finds inspiration in the flood of humanity and the city\'s promise.';

			break;

		case 'ch_04':

			strNavText = '<b>Slavery and the Coming Crisis</b> (10:52)<br />In New Orleans, Whitman encounters a racially mixed society -- and the stark fact of human bondage. He searches for a poetic voice to unite the fraying body politic.';

			break;

		case 'ch_05':

			strNavText = '<b><i>Leaves of Grass</i></b> (13:30)<br />With great faith in its power to heal the nation, Whitman publishes <i>Leaves of Grass</i> in 1855.';

			break;

		case 'ch_06':

			strNavText = '<b>Desperate to Connect</b> (11:27)<br />American literary lion Ralph Waldo Emerson writes to encourage Whitman, though <i>Leaves of Grass</i> sells poorly. A second edition includes new poems.';

			break;

		case 'ch_07':

			strNavText = '<b>A Call for Affection</b> (13:24)<br />Whitman\'s romance with a young Irishman ends sadly. He suffers, but translates his experience to poetry, believing affection is the key to national healing.';

			break;

		case 'ch_08':

			strNavText = '<b>The Civil War</b> (8:20)<br />Whitman volunteers to care for wounded Union soldiers in Washington, D.C.';

			break;

		case 'ch_09':

			strNavText = '<b><i>Drum Taps</i></b> (8:40)<br />Whitman is exhausted by his hospital efforts. He writes poetry in memory of the dead.';

			break;

		case 'ch_10':

			strNavText = '<b>His Life\'s Work</b> (12:50)<br />Living in Camden, New Jersey, Whitman reconceives <i>Leaves of Grass</i>. His old age becomes a poetic subject.';

			break;

		case 'ch_11':

			strNavText = '<b>Credits</b> (2:45)<br />Production credits for the television program.';

			break;

		

	}

	return strNavText;

}



function initNavLinks() {

	if (!document.getElementById('content_title')) return;

	defaultNavText = document.getElementById('content_title').innerHTML;



	if (!document.getElementsByTagName || !document.getElementById('chpater_nav')) return;

	var anchors = document.getElementById('chpater_nav').getElementsByTagName('a');

	for (var i = 0; i < anchors.length; i++) {

		var anchor = anchors[i];

		if (anchor.getAttribute('href') && anchor.id != 'auto_play'){  // ignores named anchors

			anchor.onmouseover = function(){ try{ setNavText(getNavText(this.id)); } catch(e) { /* catch exceptions */ } };

			anchor.onmouseout = function(){ try{ clearNavText(); } catch(e) { /* catch exceptions */ } };

		}

	}

}



// for preloading images and rollovers

var aryLoadImg = new Array();

var ncImgOver = '_over';

var ncClsRoll = 'roll';



function loadImg(imgFile, imgType){

	var i = aryLoadImg.length;

	aryLoadImg[i] = new Image();

	aryLoadImg[i].src = imgFile + '.' + imgType;

	return i;

}



function swapImg(imgId, imgSrc){ if(document.images){ document.images[imgId].src = imgSrc; } }



function initImages() {

	if (!document.getElementsByTagName) return;

	var aryImages = document.getElementsByTagName('img');

	var regex_roll = new RegExp('\\b'+ncClsRoll+'\\b');

	for (var i = 0; i < aryImages.length; i++) {

		var thisImg = aryImages[i];

		// this is used for single image roll overs

		if(thisImg.className.match(regex_roll)){

			var imgFile = thisImg.src.substr(0, thisImg.src.length-4);

			var imgType = thisImg.src.substr(thisImg.src.length-3, thisImg.src.length);

			var roll_idx = loadImg(imgFile+ncImgOver, imgType);

			thisImg.roll_idx = roll_idx;

			thisImg.onmouseover = function(){

				try {

					swapImg( this.id, aryLoadImg[this.roll_idx].src );

				} catch(e) { /*alert(e);*/ }

			};

			thisImg.onmouseout = function(){

				try {

					var regex_ncImgOver = new RegExp(ncImgOver+'\.');

					swapImg( this.id, this.src.replace(regex_ncImgOver, '.') );

				} catch(e) { /*alert(e);*/ }

			};

		}

	}

}



function swap(elemID, imgSrc){ if(document.images){ document.images[elemID].src = imgSrc; } }



// utility function for safe class name managment

function manClsNames( action, obj, cls1, cls2 ){

	switch (action){

	case 'swap':

		obj.className = !manClsNames('check', obj, cls1) ? obj.className.replace( cls2, cls1 ) : obj.className.replace( cls1, cls2 );

		break;

	case 'add':

		if( !manClsNames('check', obj, cls1) ){ obj.className += obj.className ? ' '+cls1 : cls1; }

		break;

	case 'remove':

		var rep = obj.className.match(' '+cls1) ? ' '+cls1 : cls1;

		obj.className = obj.className.replace( rep, '' );

		break;

	case 'check':

		return new RegExp('\\b'+cls1+'\\b').test(obj.className)

		break;

	}

}



// function called when DOM is loaded

function initPage() {

	if (arguments.callee.done) return; // quit if this function has already been called

	arguments.callee.done = true; // flag this function so called only oce

	// do stuff

	initNavLinks();

	initImages();

}



// for Mozilla based browsers

if (document.addEventListener) {

   document.addEventListener("DOMContentLoaded", initPage, null);

}



// for Internet Explorer

/*@cc_on @*/

/*@if (@_jscript)

   document.write('<script type="text/javascript" defer src=../js/ie_dom_loaded.js></script>');

/*@end @*/



/* for other browsers */

window.onload = initPage;