/*/ JavaScript file for the Pearson Education 'FRED' project /*/
/*/ Date: Dec 2006 /*/

/*------ what to do onload of document ------*/
	// W3C DOM-standards user agents //
	if(window.addEventListener){
		window.addEventListener("load",init_page,false);
	}
	// IE 6 and lower //
	else if(window.attachEvent){
		window.attachEvent("onload",init_page);
	}
/*-------------------------------------------*/

function init_page(){
	/*------ remove the 'marching ants' from the specified element type ------*/
	stopTheAnts('a');
	/*------ find all the hrefs where type = popup and apply the pop-up javascript function ------*/
	setPopUps();
	/*------ swap the background graphic of a nested line item's parentnode (up 3) -- used for the PDF links ------*/
	phoneHome();
	/*------ highlight the audio table control cells when hovered over ------*/
	highlight();
	/*------ uncheck any checkable elements onload of page ------*/
	unCheck();
}

//-----------------------------------------------------------------------------
// The following scripts are called from the init_page function //
//-----------------------------------------------------------------------------

/*------ uncheck hidden checkbox controls onload of page ------*/
function unCheck(){
	var inputs = document.getElementsByTagName('input');
		for(var i=0; i<inputs.length; i++){
			if(inputs[i].type == 'radio'){
				inputs[i].checked = false;
			}
		}
}
/*------ remove the 'marching ants' from the specified element type ------*/
function stopTheAnts(elTypeOrVar){
	var elements = document.getElementsByTagName(elTypeOrVar);
		for(var i=0; i<elements.length; i++){
			elements[i].onfocus = function(){
				if(this.blur)this.blur();
			}
		}
}
/*------ swap the background graphic to make hover effect work for nested line item elements (like PDF links) ------*/
function phoneHome(){
	var hrefs = document.getElementsByTagName('a');
	for(var i=0; i<hrefs.length; i++){
		if(hrefs[i].className == 'pdf'){
			hrefs[i].onmouseover = function(){
				this.parentNode.parentNode.parentNode.className = 'hover';
			}
			hrefs[i].onmouseout = function(){
				this.parentNode.parentNode.parentNode.className = '';
			}
		}
	}
}
/*------ find all the hrefs and apply the pop-up javascript function using the appropriate parameters ------*/
function setPopUps(){
	var newwindow;
	var a = document.getElementsByTagName('a');
	for(i=0; i<a.length; i++){
		/*/ if it's a catalog-type link /*/
    	if(a[i].getAttribute('target') && a[i].getAttribute('target') == 'catalog'){
      		a[i].onclick = function(){
        		url = this.getAttribute('href');
        		newwindow = window.open(url,'catalog','location=yes,resizable=yes,status=yes,toolbar=yes,scrollbars=yes,width=860,height=500');
					if(window.focus){
						newwindow.focus();
					}
       			return false;
      			}
    		}
		/*/ if it's a pdf-type link /*/
		if(a[i].getAttribute('target') && a[i].getAttribute('target') == 'pdf'){
      		a[i].onclick = function(){
        		url = this.getAttribute('href');
        		newwindow = window.open(url,'pdf','location=yes,resizable=yes,status=yes,toolbar=yes,scrollbars=yes,width=800,height=500');
					if(window.focus){
						newwindow.focus();
					}
       			return false;
      			}
    		}
		/*/ if it's a pearson-type link /*/
		if(a[i].getAttribute('target') && a[i].getAttribute('target') == 'pearson'){
      		a[i].onclick = function(){
        		url = this.getAttribute('href');
        		newwindow = window.open(url,'pearson','location=yes,resizable=yes,status=yes,toolbar=yes,scrollbars=yes,width=860,height=500');
					if(window.focus){
						newwindow.focus();
					}
       			return false;
      			}
    		}
		/*/ if it's a bio-type link /*/
		if(a[i].getAttribute('target') && a[i].getAttribute('target') == 'bio'){
      		a[i].onclick = function(){
        		url = this.getAttribute('href');
        		newwindow = window.open(url,'bio','location=yes,resizable=yes,status=yes,toolbar=yes,scrollbars=yes,width=725,height=385');
					if(window.focus){
						newwindow.focus();
					}
       			return false;
      			}
    		}
		/*/ if it's a flash-type link /*/
		if(a[i].getAttribute('target') && a[i].getAttribute('target') == 'flash'){
      		a[i].onclick = function(){
        		url = this.getAttribute('href');
        		newwindow = window.open(url,'flash','location=yes,resizable=yes,status=yes,toolbar=yes,scrollbars=yes,width=800,height=500');
					if(window.focus){
						newwindow.focus();
					}
       			return false;
      			}
    		}
		/*/ if it's a techSupport-type link /*/
		if(a[i].getAttribute('target') && a[i].getAttribute('target') == 'techSupport'){
      		a[i].onclick = function(){
        		url = this.getAttribute('href');
        		newwindow = window.open(url,'flash','location=yes,resizable=yes,status=yes,toolbar=yes,scrollbars=yes,width=860,height=500');
					if(window.focus){
						newwindow.focus();
					}
       			return false;
      			}
    		}
  		}
}
/*------ this is just to cover our tracks because some user agents will show a lag/gap when using the :hover pseudo for the a tag, so let's give 'em a helping hand ------*/
function highlight(){
	var cells = document.getElementById('audio_controls').getElementsByTagName('td');
	for(var i=0; i<cells.length; i++){
		if(cells[i].className == 'audio'){
			cells[i].onmouseover = function(){
				if(this.childNodes[1].checked == false){
					this.className = 'hov';
				}
			}
			cells[i].onmouseout = function(){
				if(this.childNodes[1].checked == false){
					this.className = 'audio';
				}
			}
		}
	}
}
/*------ this is the script called when a user clicks on of the audio control table cell links ------*/
function setPlaylist(thisCell, playlist, quote){
	var pullquote = document.getElementById('pullquote');
	//var pQuote = document.getElementById('pQuote');
	var player = document.getElementById('player');
	var cells = document.getElementById('audio_controls').getElementsByTagName('td');
	for(var i=0; i<cells.length; i++){
		/*/ first let's un-highlight any other cells /*/
		if(cells[i].className == 'audio' || cells[i].className == 'on'){
			cells[i].childNodes[1].checked = false;
			cells[i].className = 'audio';
		}
	/*/ next, let's highlight this cell only /*/
	thisCell.childNodes[1].checked = true;
	thisCell.className = 'on';
	/*/ now let's set the playlist /*/
	player.innerHTML='<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0 width=267 height=145><param name=movie value=../site/swf_player/audio_player.swf /><param name=quality value=high /><param name=FlashVars value=pl1=xml_playlists/' + playlist + '.xml' + ' /><param name=wmode value=transparent /><embed src=../site/swf_player/audio_player.swf width=267 height=145 quality=high pluginspage=http://www.macromedia.com/go/getflashplayer wmode=transparent type=application/x-shockwave-flash FlashVars=pl1=xml_playlists/' + playlist + '.xml' + ' </embed></object>'
	}
}
