 /**
  * Accent Javascript file.
  *
  * @author Terry Luedtke
  * @author Dale Schalow
  * @author Victor B. Taylor
  * @author Kevin H. Spruill
  * @version $Revision: /main/apps/accent/1.0/88 $
  */
  
 var accentInfo;
 var accentIsMac = (navigator.userAgent.indexOf("Mac") > -1); 
 var accentIsMSIE = (navigator.userAgent.indexOf("MSIE") > -1);
 var accentIsOsX = (navigator.userAgent.indexOf("OS X") > -1);
 var accentIsNS7 = (navigator.userAgent.indexOf("/7.") > -1);  // '/7.' mozilla.org - most common agent pattern Netscape 7 Gecko
 var accentIsNS4 = ((navigator.appName=="Netscape"&&parseFloat(navigator.appVersion) < 5.0));
 var accentIsMozilla = ((navigator.appName=="Netscape"&&parseFloat(navigator.appVersion) >= 5.0)&&(navigator.userAgent.indexOf("rv:1.4") > -1));
 var accentJavaIsEnabled = false; //vbt
 
 /*
  * Font resizing constants
  */
 var accentFontChangeRatio = 1.1;
 var accentMinFontSize = 1.0
 
 
 /**
  * Initializes the accent application. Intended to be called
  * immediately after loading this file.
  */
 function accentInit()
 {
   accentInfo = accentGetCookie();
     
   // Set defaults
   if(!accentInfo) {
 
 
     //window.alert("setting defaults");
     accentInfo = new Object;
     accentInfo.fontSize = accentMinFontSize;
     accentInfo.contrast = 'normal';
     accentInfo.speaking = 'f';
 
     //vbt alert('init 1');
 
     accentInfo.player = accentSelectPlayer(); 
 
 
 
     //vbt if ( (!accentJavaIsEnabled) ) {
 
     //vbt        alert('init3: Java is required for this website to speak its content.  Please enable the "Java Enabled" option in your Preferences menu.');
         //window.open("/java_enabled.html","javaEnabledWindow");
 
     //vbt}
 
 
 
     //window.alert(accentInfo.player);
     // Don't set the cookie here. We set a cookie only
     // if the user wants something other than the defaults.
   }
   //vbt alert('init 2');
   accentInsertPlayerScript();
 } 
 
 
 /**
  * Accent hook into the page load event. 
  *
  * @param titleID Audio file basename to play on page load
  */
 function accentOnLoad(titleID)
 {
   if (! (accentIsMac && accentIsMSIE) )
   {
     accentSpeakTitle(titleID);
   }
   else
   {
     accentSpeakingTitle = false;
   }
   
   // Check if window focus/blur handlers are in place.
   if(   window.onFocus
      && window.onFocus.indexOf("accentWindowFocusHandler") < 0
      ) {
     window.onFocus = "accentWindowFocusHandler();" + window.onFocus;
   }
   if(   window.onBlur
      && window.onBlur.indexOf("accentWindowBlurHandler") < 0
      ) {
     window.onBlur = "accentWindowBlurHandler();" + window.onBlur;
   }
 
   //vbt alert('init 4');
 }
 
 
 /**
  * Acent hook into the page unload event.
  */
 function accentOnUnload()
 {
   accentClearAllTimers();
   //accentInterrupt();
   //accentDOMInterrupt();
 }
 
 
 /**
  * Writes the HTML required to load the appropriate 
  * style sheet into the document. Should be called within
  * the head section of the page.
  */
 function accentInsertStyleSheet() 
 {
 	var cssQuery = 'size=' + String(accentInfo.fontSize).substr(0, 5) 
 		+ '&amp;inverted=' + (accentIsHighContrast() ? 'yes' : 'no')
 		;
 	//alert("cssQuery is " + cssQuery);
 
   /* Each link tag to be it's own write statement to make Netscape 4 happy */
   // DS - Added link tag attribute title "dynstyle" to allow for DOM updates on-demand.
   document.write('<link title="dynstyle" rel="stylesheet" type="text/css" href="' + location.protocol + '//apps.nlm.nih.gov/accent/apps/seniorhealth_css.cfm?' + cssQuery + '" > ');
   document.write('<link rel="stylesheet" type="text/css"  href="' + accentFILES + '/accentControls.css" > ');
 	document.write('<link rel="stylesheet"  href="' + accentFILES + '/accentControls_nonNN.css" type="text/css" media="all" > ');
 }
 
 function accentIncreaseFontSize()
 {
     accentInfo.fontSize = accentInfo.fontSize * accentFontChangeRatio;
 		//alert("Increased font to " + accentInfo.fontSize);
 	// DS - Disabled accentReload() to use new accentRefreshFontSize() function with DOM async updates.
     //accentReload();
     // Set the font size data
     if(accentSetCookie(accentInfo)) {
 		//window.location.reload(false);
 	} else {
 		alert("Per-session cookies (not stored) must be enabled to change from default state");
 	}
 	// Refresh font size
     accentRefreshFontSize();
 }
 
 // DS - Added function to automatically refersh page's font size without using accentReload().
 function accentRefreshFontSize()
 {
 	var cssQuery = 'size=' + String(accentInfo.fontSize).substr(0, 5) 
 		+ '&inverted=' + (accentIsHighContrast() ? 'yes' : 'no')
 		;
 	var url, title;
 	url = location.protocol + "//apps.nlm.nih.gov/accent/apps/seniorhealth_css.cfm?" + cssQuery;
 	title = "dynstyle";
 	
 	var i, cacheobj
 	for(i=0; (cacheobj=document.getElementsByTagName("link")[i]); i++) {
 		if(cacheobj.getAttribute("rel").indexOf("style") != -1 && cacheobj.getAttribute("title")) {
 			//cacheobj.disabled = true;
 			if(cacheobj.getAttribute("title") == title) {
 				cacheobj.setAttribute("href", url);
 				cacheobj.disabled = false; //enable chosen style sheet
 			}
 		}
 	}
 	// Refersh enabled decrease font size button per min value
 	var cachebtn = document.getElementsByTagName('input');
     for (var x = 0; x < cachebtn.length; x++) {
 			if(cachebtn[x].getAttribute("title") == "Decrease text size (Alt+3)") {
 				//alert('set button');
 				//var html = '<input type="Button"  name="decreaseSize" title="Decrease text size (Alt+3)" value=" - " accesskey="3" class="impact" ' +
 				//			'   onClick="accentDecreaseFontSize()" ' + (accentInfo.fontSize > accentMinFontSize ? '' : ' disabled')  + ' >'
 				//cachebtn.innerHTML = html;
 				if (accentInfo.fontSize > accentMinFontSize)
 					cachebtn[x].disabled = false;
 				else 
 					cachebtn[x].disabled = true;
 			}
 		
 	}
 }
 
 function accentDecreaseFontSize()
 {
     accentInfo.fontSize = accentInfo.fontSize / accentFontChangeRatio;
 		if(accentInfo.fontSize < accentMinFontSize) {
 			accentInfo.fontSize = accentMinFontSize;
 		}
 		//alert("Decreased font to " + accentInfo.fontSize);
     // DS - Disabled accentReload() to use new accentRefreshFontSize() function with DOM async updates.
     //accentReload();
     // Set the font size data
     if(accentSetCookie(accentInfo)) {
 		//window.location.reload(false);
 	} else {
 		alert("Per-session cookies (not stored) must be enabled to change from default state");
 	}
 	// Refresh font size
     accentRefreshFontSize();
 }
 
 
 function accentEnableContrast()
 {
     accentChangeContrast('high');
 }
 
 
 function accentDisableContrast()
 {
     accentChangeContrast('normal');
 }
 
 
 function accentChangeContrast(newContrast)
 {
     accentInfo.contrast = newContrast;
     // DS - Disabled accentReload() to use new accentRefreshFontSize() function with DOM async updates.
     //accentReload();
     // Set the font size data
     if(accentSetCookie(accentInfo)) {
 		//window.location.reload(false);
 	} else {
 		alert("Per-session cookies (not stored) must be enabled to change from default state");
 	}
 	// Refresh font size
     accentRefreshFontSize();
     //alert(accentInfo.contrast);
 }
 
 
 function accentChangeSpeechState(newState)
 {
 	var cachebody=document.getElementsByTagName("body").item(0);
 	var cacheswf=document.getElementById("speechplayer");  // DS - Use DOM update on-demand.
     accentInfo.speaking = newState;
 		if(newState == 't') {
 			//accentPreLoadPlayer()
 			
 			
 			//
 			// DS - Create html to load flash player
 			//
 			var html;
 			var titleid=cachebody.getAttribute("onload");
 			titleid=titleid.toString();
 			titleid=titleid.substring((titleid.indexOf("('")+2),(titleid.indexOf("')")));
 			titleid=accentBaseToFullPath(titleid);
 			titleid=titleid.replace(".gsm",".mp3");
 			//alert(titleid);
 			if (accentIsMSIE) {
 				//alert(titleid);
 				html = ""
 					+ "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'"
 					+ " codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0'"
 					+ " width=\"0\" height=\"0\" id='accentplayer' align='middle' >"
 					+ "<param name='FlashVars' value=\"streamurl=" + titleid + "\" />"
 					+ "<param name=\"allowScriptAccess\" value=\"sameDomain\" />"
 					+ "<param name=\"movie\" value=\"/accent/codebase/accent_player.swf?r=" + Math.round(Math.random() * 99999) + "\" />"
 					+ "<param name=\"quality\" value=\"high\" />"
 					+ "<param name=\"bgcolor\" value=\"#ffffff\" />"
 					+ "<embed src=\"/accent/codebase/accent_player.swf?r=" + Math.round(Math.random() * 99999) + "\" "
 					+ "FlashVars=\"streamurl=" + titleid + "\""
 					+ " quality=\"high\" bgcolor=\"#ffffff\" width=\"0\""
 					+ " height=\"0\" name=\"xspf_player\" align=\"middle\" allowScriptAccess=\"sameDomain\""
 					+ " type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed>"
 					+ "</object>"
 					;
 			}
 			else {
 				html = ""
 					+ "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'"
 					+ " codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0'"
 					+ " width=\"0\" height=\"0\" id='accentplayer' align='middle' >"
 					+ "<param name='FlashVars' value=\"streamurl=" + titleid + "\" />"
 					+ "<param name=\"allowScriptAccess\" value=\"sameDomain\" />"
 					+ "<param name=\"movie\" value=\"/accent/codebase/accent_player.swf?r=" + Math.round(Math.random() * 99999) + "\" />"
 					+ "<param name=\"quality\" value=\"high\" />"
 					+ "<param name=\"bgcolor\" value=\"#ffffff\" />"
 					+ "<embed src=\"/accent/codebase/accent_player.swf?r=" + Math.round(Math.random() * 99999) + "\" "
 					+ "FlashVars=\"streamurl=" + titleid + "\""
 					+ " quality=\"high\" bgcolor=\"#ffffff\" width=\"0\""
 					+ " height=\"0\" name=\"xspf_player\" align=\"middle\" allowScriptAccess=\"sameDomain\""
 					+ " type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed>"
 					+ "</object>"
 					;
 			}
 		}
 		else {
 			//accentInterrupt();
 			//accentDOMInterrupt();
 			html = ""
 				+ "<embed src=\"/accent/codebase/accent_player.swf?r=" + Math.round(Math.random() * 99999) + "\" "
 				+ "FlashVars=\"streamurl=" + accentBaseToFullPath('silence') + "\""
 				+ " quality=\"high\" bgcolor=\"#ffffff\" width=\"0\""
 				+ " height=\"0\" name=\"xspf_player\" align=\"middle\" allowScriptAccess=\"sameDomain\""
 				+ " type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed>"
 			
 		}
 	
 	cacheswf.innerHTML=html;  // Set the div speechplayer with html based on newState
 
     //accentReload();
     if(accentSetCookie(accentInfo)) {
 		//window.location.reload(false);
 	} else {
 		alert("Per-session cookies (not stored) must be enabled to change from default state");
 	}
 }
 
 function accentDOMInterrupt()
 {
 	var cachebody=document.getElementsByTagName("body").item(0);
 	var cacheswf=document.getElementById("speechplayer");  // DS - Use DOM update on-demand.
 	var html = "";
 	cacheswf.innerHTML = html;
 }
 
 function accentDOMSpeak(fullPath)
 {
 	var cacheswf=document.getElementById("speechplayer");  // DS - Use DOM update on-demand.
 	if(accentIsSpeechOn()) {
 		//
 		// DS - Create html to load flash player
 		//
 		var titleid = accentBaseToFullPath(fullPath).replace(".gsm",".mp3");
 		var html;
 		html = ""
 			+ "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'"
 			+ " codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0'"
 			+ " width=\"0\" height=\"0\" id='accentplayer' align='middle' >"
 			+ "<param name='FlashVars' value=\"streamurl=" + titleid + "\" />"
 			+ "<param name=\"allowScriptAccess\" value=\"sameDomain\" />"
 			+ "<param name=\"movie\" value=\"/accent/codebase/accent_player.swf?r=" + Math.round(Math.random() * 99999) + "\" />"
 			+ "<param name=\"quality\" value=\"high\" />"
 			+ "<param name=\"bgcolor\" value=\"#ffffff\" />"
 			+ "<embed src=\"/accent/codebase/accent_player.swf?r=" + Math.round(Math.random() * 99999) + "\" "
 			+ "FlashVars=\"streamurl=" + titleid + "\""
 			+ " quality=\"high\" bgcolor=\"#ffffff\" width=\"0\""
 			+ " height=\"0\" name=\"xspf_player\" align=\"middle\" allowScriptAccess=\"sameDomain\""
 			+ " type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed>"
 			+ "</object>"
 			;
 		//alert(html);
 	}
 	else {
 		//accentInterrupt();
 		//accentDOMInterrupt();
 		html = ""
 			+ "<embed src=\"/accent/codebase/accent_player.swf?r=" + Math.round(Math.random() * 99999) + "\" "
 			+ "FlashVars=\"streamurl=" + accentBaseToFullPath('silence') + "\""
 			+ " quality=\"high\" bgcolor=\"#ffffff\" width=\"0\""
 			+ " height=\"0\" name=\"xspf_player\" align=\"middle\" allowScriptAccess=\"sameDomain\""
 			+ " type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed>"
 
 	}
 	cacheswf.innerHTML=html;  // Set the div speechplayer with html based on newState
 	
 	var i;
 	var cacheobj = document.getElementsByTagName("a");
 	for(i=0; i < cacheobj.length; i++) {
 		if(cacheobj[i].childNodes.length > 0) {
 			if(cacheobj[i].childNodes[0].tagName == "IMG") {
 				if (cacheobj[i].getAttribute("href").indexOf("javascript:") != -1 )
 				{
 					if (!(cacheobj[i].getAttribute("href").indexOf("accent") > -1))
 					{
 						var href = cacheobj[i].getAttribute("href");
 						href = "javascript:accentDOMSpeak('silence');"+href.substring(href.indexOf(":")+1,href.length);
 						
 						cacheobj[i].setAttribute("href",href);
 					}
 				}	
 			}
 		}
 	}
 	
 }
 
 /**
  * "External API" for site to determine if accent is
  * using high contrast.
  */
 function accentIsHighContrast()
 {
   return (accentInfo.contrast == 'high');
 }
 
 /**
  * "External API" for site to determine if accent is
  * using speech.
  */
 function accentIsSpeechOn()
 {
   return (accentInfo.speaking == 't');
 }
 
 
 
 /**
  * Changes the object's style sheet. Used for roll-overs.
  *
  * param obj       The object to affect.
  * parma new_style The new style sheet.
  */
 function accentPviiClassNew(obj, new_style) { //v2.6 by PVII
   obj.className=new_style;
 }
 
 
 /**
  * Writes the HTML for the Accent feature control buttons
  * into the document. Should be called within the body section
  * of the page.
  */
 function accentInsertControls()
 {
   document.write('<table width="100%"><tr>');
   
   /* Start of buttons cell */
   document.write('<td class="accentControls" align="center">');
   
   /* Text size buttons */  
   document.write(''
 	  + ' <div align="center"><span title="Increase or decrease text size" class="fieldset">Text Size: '
 		+ '  <input type="Button" name="increaseSize" title="Increase text size (Alt+2)" value=" + " accesskey="2"  class="impact" '
 		+ '    onClick="accentIncreaseFontSize()" >'
 		+ '	 <input type="Button"  name="decreaseSize" title="Decrease text size (Alt+3)" value=" - " accesskey="3" class="impact" '
 		+ '    onClick="accentDecreaseFontSize()" ' + (accentInfo.fontSize > accentMinFontSize ? '' : ' disabled')  + ' >'
 		+ '	</span>'
     //+ 'onMouseOver="accentSpeakOnFocus(\'' + accentInfo.style + '\');'
     //+ 'onFocus="accentSpeakOnFocus(\'' + accentInfo.style + '\');'
     //+ 'onMouseOut="accentCancelSpeakOnFocus(\'' + accentInfo.style + '\');'
     //+ 'onBlur="accentCancelSpeakOnFocus(\'' + accentInfo.style + '\');'
     );
     
   /* Contrast button */
   document.write(''
 		+ ' <span class="fieldset" title="Change background color scheme (Alt+4)">Contrast: '
 		+ '  <label title="Dark background with light text" for="contrastOn" >'
 		+ '  <input id="contrastOn" name="contrast" value="on" type="radio"   onClick="accentEnableContrast()" '
 		+     (accentIsHighContrast() ? ' checked ' : ' accesskey="4" ') + '/>on</label>'
 		+ '  <label title="Standard color scheme"  for="contrastOff" >'
 		+ '  <input id="contrastOff" name="contrast" value="off" type="radio" onClick="accentDisableContrast()" '
 		+     (accentIsHighContrast() ? ' accesskey="4" ' : ' checked ') + '  />off</label>'
 		+ ' </span>'
     //+ 'onMouseOver="accentSpeakOnFocus(\'' + accentInfo.contrast + '\');'
     //+ 'onFocus="accentSpeakOnFocus(\'' + accentInfo.contrast + '\');'
     //+ 'onMouseOut="accentCancelSpeakOnFocus(\'' + accentInfo.contrast + '\');'
     //+ 'onBlur="accentCancelSpeakOnFocus(\'' + accentInfo.contrast + '\');'
     //+ 'onClick="accentToggleContrast();accentPviiClassNew(this,\'buttondown\');" '
     );
 
   /* Speech button */
   if(accentInfo.player == 'Disabled') {
     //document.write('&nbsp;Speech not available');
     // Added by VBt 09_11_2003
     var speechName = "Speech Disabled";
     document.write(''
       + ' <span class="fieldset" title="Speech not supported on this sytem">Speech Disabled</span>'
       );    
   } else {
     document.write(''
 			+ '	<span class="fieldset" title="Turn on/off speech (Alt+5)">Speech: '
 			+ '  <label title="Turn ON speech (Alt+5)"  for="speechOn" >'
 			+ '  <input id="speechOn" name="speech" value="on" type="radio" onClick="accentChangeSpeechState(\'t\')"  '
 			+     (accentIsSpeechOn() ? ' checked' : ' accesskey="5"') + '>on</label> '
 			+ '  <label title="Turn OFF speech (Alt+5)"  for="speechOff" >'
 			+ '  <input id="speechOff" name="speech" value="off" type="radio" onClick="accentChangeSpeechState(\'f\')" '
 		  +     (accentIsSpeechOn() ? ' accesskey="5"' : ' checked') + '>off</label>'
 			+ ' </span>'
       //+ 'onMouseOver="accentSpeakOnFocus(\'speech' + speechName + '\');'
       //+ 'onFocus="accentSpeakOnFocus(\'speech' + speechName + '\');'
       //+ 'onMouseOut="accentCancelSpeakOnFocus(\'' + speechName + '\');'
       //+ 'onBlur="accentCancelSpeakOnFocus(\'' + speechName + '\');'
       );
     /* invisible speech "player" */
     document.write(""
 	  + ' </div><div id="speechplayer"></div>'
 	  );
     /* invisible cancel speech "button" */ 
     document.write(''
       + ' <a title="cancel current narration" accesskey="8" href="javascript:void(0);" onfocus="accentSpeakOnFocus(\'silence\');"> ' 
       + '<img src="/images/spacer.gif" border="0" alt="" width="1" height="1"></a>'
       );
   }
   
   /* End of buttons cell */
   document.write('</td>');
 
   /* Help link */
   document.write('<td align="right">'
     + '<a href="/accentHelp.html" class="helplink" title="Help" '
     + 'onMouseOver="accentSpeakOnFocus(\'help\');" '
     + 'onFocus="accentSpeakOnFocus(\'help\');" '
     + 'onMouseOut="accentCancelSpeakOnFocus(\'help\');" '
     + 'onBlur="accentCancelSpeakOnFocus(\'help\');" '
     + '>Help</a>'
     + '</td>'
     );
   
   document.write('</tr></table>\n');
 }
 
 
 /**
  * Sets the accent configuration cookie and reloads
  * the current page to force new settings.
  */
 function accentReload()
 {
 	//alert('reload page');
   if(accentSetCookie(accentInfo)) {
     window.location.reload(false);
   } else {
     alert("Per-session cookies (not stored) must be enabled to change from default state");
   }
 }
 
 
 //************************************
 //********* Player code **************
 //************************************
 var accentURL_HOST;        // accentGeturlHost() cache
 var accentPLAYER_WIN_NAME; // accentGetPlayerWinName() cache
 var accentPlayerWin;       // accentGetPlayerWin() cache
 
 var accentPLAYER_WIN_FEATURES = "resizable=yes,height=400,width=300,"
   + "titlebar='AccEnt Player'";
 
 
 var accentCALL_JAVA_DIRECT = true;
 
 var accentSpeakingTitle = true;
 var accentSpeakingTitleTimer;
 var accentFocusTimer;
 var accentWindowLostFocus = false;
 var accentWindowFocusTimer;
 
 // Various delays in milliseconds
 var accentSpeakTitleDelay  = 2000  // Time that onFocus is blocked while playing title
 var accentFocusSpeakDelay  = 500   // Delay before firing onFocus (link) audio
 var accentWindowFocusDelay = 100   // Delay to block focus events when switching windows
 
   
 var accentAUDIO_EXTENSION;
 
 var accentPLAYERS = new Object;
 // 'Disabled'  Doesn't even open a window. For browsers that we can't support
 accentPLAYERS['Disabled'] = [ null, null ]; 
 // 'No Sound'  Doesn't load an applet. For debugging
 accentPLAYERS['No Sound'] = [ 'noSoundPlayer.js', null ]; 
 // 'Generic'  loads audio into a frame and lets the browser decide what to do.
 accentPLAYERS['Generic'] = [  'genericPlayer.js', 'gsm' ]; 
 // 'AudioClip' Loads simple Java 1.1 AudioClip player (.au, ULAW files)
 accentPLAYERS['AudioClip'] = [ 'audioClipPlayer.js', 'au' ]; 
 // 'AudioCentric' Loads Audio Centric's player (.wav GSM/MS files)
 accentPLAYERS['AudioCentric'] = [ 'audioCentricPlayer.js', 'wav' ];
 // 'Flash' Loads accent_player.swf (.mp3 MPEG-2 LayerIII files)
 accentPLAYERS['Flash'] = [ 'flashAccentPlayer.js', 'mp3' ];  
 // 'FreedomAudio' Loads Freedom Audio's player (.gsm GSM files)
 accentPLAYERS['FreedomAudio'] = [ 'freedomAudioPlayer.js', 'gsm' ]; 
 // 'FreedomAudioNoLiveConnect' Loads FreedomAudioPlayer (.gsm GSM files)
 accentPLAYERS['FreedomAudioNoLiveConnect'] = [ 'freedomAudioPlayerNoLiveConnect.js', 'gsm' ]; 
 
 function accentSelectPlayer()
 {
 
   // AOL 4 has problems with named windows, so 
   // it won't work with our pop-up player.
   pos = navigator.appVersion.indexOf('AOL');
   if (parseInt(navigator.appVersion.charAt(pos+5)) < 5)
   {
     return 'Disabled';
   }
 
   // default player
   //return 'No Sound';
 
   //accentJavaIsEnabled = accentCheckIsJavaEnabled();
   accentJavaIsEnabled = true;
   
   if (accentJavaIsEnabled) {
 
     //alert('Java is Enabled');
 
 
   } 
   else {
 
    //vbt alert('in selectPlayer');
    if ( ( accentCheckMozillaAndMac() ) || ( accentCheckNetscape7_1AndMac() )  ) {
 	//alert('MozMac Condition');
 
    } else {
 	//alert('NO MozMac / No Netscape7_1AndMac Condition');
 
       return 'Disabled';
 
    }
 
   }
   
   //return 'Flash';
 
   if ( accentIsMac && ( accentIsMSIE || accentIsNS7 || accentIsMozilla ) ) 
   {  
     //return 'FreedomAudioNoLiveConnect';
     return 'Flash';
   }
   else
   {
     //return 'FreedomAudio';
     return 'Flash';
   }
   
 }
 
 
 /**
  * Imports the selected player's javascript file, by writing
  * a script source tag into the document.
  */
 function accentInsertPlayerScript()
 {
   if(accentInfo.player == 'Disabled') {
     return;
   }
 
   var player = accentPLAYERS[accentInfo.player];
   var playerUrl = accentFILES + "/players/" + player[0];
   accentAUDIO_EXTENSION = player[1];
   
   var code = '<script src="' + playerUrl + '"></script>';
   //alert(code);
   document.write(code);
 }
 
 
 /**
  * Determines the host part of the URL for the current document.
  * I.e. http://nihseniorhealth.gov/
  *
  * @return String The host portion of the URL
  */
 function accentGetUrlHost()
 {
   if(!accentURL_HOST) {
     var docUrl = document.URL
     var endOfHost = docUrl.indexOf('/', 8);
     accentURL_HOST = docUrl.substring(0, endOfHost);
   }
   return accentURL_HOST;
 }
 
 
 /** 
  * Create a window name unique for a particular site.
  * This protects us from running into security issues
  * trying to access a window created and loaded from 
  * another site.
  *
  * @return String The unique name for the player window.
  */
 function accentGetPlayerWinName()
 {
   if(!accentPLAYER_WIN_NAME) {
     var urlHost = accentGetUrlHost();
     var name = urlHost.substring(7, urlHost.length)
     name = name.replace(/\./g, "_").replace(":", "__");
     accentPLAYER_WIN_NAME = "accentPlayer__" + name;
   }
   return accentPLAYER_WIN_NAME;
 }
 
 /**
  * Converts a file basename (i.e. Speech ID) into a full
  * URL path.
  *
  * @param filebase The file basename
  *
  * @return String The full URL path to the audio file.
  */
 function accentBaseToFullPath(filebase)
 {
   if(filebase.charAt(0) == '/') {
     return filebase;
 
   } else {
     return accentREPOSITORY + '/' + filebase + "." + accentAUDIO_EXTENSION;
   }
 }
 
 
 /**
  * Clears all timers. Useful to prevent timers firing after we've 
  * unloaded a page, by calling it in the page unLoad event handler.
  */
 function accentClearAllTimers()
 {
   if(accentFocusTimer != null) {
     clearTimeout(accentFocusTimer);
   }
   if(accentFocusTimer != null) {
     clearTimeout(accentFocusTimer);
   }
   if(accentWindowFocusTimer != null) {
     clearTimeout(accentWindowFocusTimer);
   }
 }
 
 
 /*
  * Empty function placeholders. They are here to pass compilation,
  * but the player Javascript files will override these.
  */
 /**
 * Instructs the applet to speak a file from a URL constructed
 * from the filebase. If speakAlways is true, it will speak the
 * file even if the personal preference for speaking is off.
 * Overwritten by individual players.
 */
 function accentSpeak(filebase, speakAlways) 
 {
   if(accentInfo.player != 'Disabled') {
     alert('accentSpeak placeholder not overwritten');
   }
 }
 /**
  * Stops the audio file playback.
  * Overwritten by individual players.
  */
 function accentInterrupt()
 {
   if(accentInfo.player != 'Disabled') {
     alert('accentInterrupt placeholder not overwritten');
   }
 }
 /**
  * Any pre-speak processing required by the player. For example,
  * writing the applet HTML into a pop-up window could occur here.
  * Overwritten by individual players.
  *
  * param fullPath The full URL path to an audio file to be played
  *       immediately on load.
  */
 function accentLoadPlayer(fullPath) 
 {
   if(accentInfo.player != 'Disabled') {
     alert('accentLoadPlayer placeholder not overwritten');
   }
 }
 
 
 /**
  * Any pre-speak processing required by the player before a page is reloaded.
  * Specifically, allows player to open a window when speech-on is clicked
  * to avoid pop-up blockers killing the player window that would otherwise
  * open on page load.
  * Overwritten by individual players, if necessary.
  *
  */
 function accentPreLoadPlayer() 
 {
   if(accentInfo.player != 'Disabled') {
     //alert('accentLoadPlayer placeholder not overwritten');
   }
 }
 
 
 /**
  * Speaks an object after a short delay. The delay is 
  * to make sure we really have the focus, rather than
  * just getting triggered on the way to another object.
  * This is a "soft" selection.
  *
  * @param filebase    The audio file basename.
  * @param speakAlways True if this should speak even when
  *                    sound is turned off.
  */
 function accentSpeakOnFocus(filebase, speakAlways) 
 {
   if(accentWindowLostFocus || accentSpeakingTitle) {
     return;
   }
   
   if(accentFocusTimer != null) {
     clearTimeout(accentFocusTimer);
   }
   //accentFocusTimer 
   //  = setTimeout("accentSpeak('" + filebase + "', " 
   //  + (speakAlways ? "true" : "false") + ")", accentFocusSpeakDelay);
   accentFocusTimer 
     = setTimeout("accentDOMSpeak('" + filebase + "')", accentFocusSpeakDelay);
 }
 
 
 /**
  * Cancels timer from speak on focus request. This
  * prevents a link from interrupting speech when the pointer
  * is draged past the link without pausing.
  *
  * @param filebase    The audio file basename.
  */
 function accentCancelSpeakOnFocus(filebase)
 {
   if(accentFocusTimer != null) {
     clearTimeout(accentFocusTimer);
   }
   accentFocusTimer = null;
 }
 
 
 /**
  * Speaks an object without delay. This is a "hard" selection.
  *
  * @param filebase    The audio file basename.
  * @param speakAlways True if this should speak even when
  *                    sound is turned off.
  */
 function accentSpeakOnSelect(filebase, speakAlways) 
 {
   if(accentSpeakingTitle) {
     accentSpeakingTitle = false;
   }
   if(accentFocusTimer != null) {
     clearTimeout(accentFocusTimer);
   }
   //accentSpeak(filebase, speakAlways);
   accentDOMSpeak(filebase);
 }
 
 /**
  * Controls the continuation of speaking an object without delay if wrapped within the HTML.
  *
  * @param filebase    The audio file basename.
  * @param speakAlways True if this should speak even when
  *                    sound is turned off.
  */
 function accentSpeakOnSelectWrap(filebase, speakAlways) 
 {
   // Fire the event only for the browsers that
   // don't support onclick on all HTML elements (like <p>)
   if( ! accentIsNS4 ) {
 	  //alert('No double-wrap support');
     return;
   }
   accentSpeakOnSelect(filebase);
 }
 
 /**
  * Speaks an object, specifically, the title. This function
  * also fires a timer to clear the speaking title flag that
  * prevents early focus events from cancelling the title audio.
  *
  * @param filebase    The audio file basename.
  */
 function accentSpeakTitle(filebase)
 {
   //accentSpeak(filebase);
   accentDOMSpeak(filebase);
   accentSpeakingTitleTimer
     = setTimeout("accentSpeakingTitle = false", accentSpeakTitleDelay);
 }
 
 
 /**
 * Short timer when window regains focus so that whatever
 * object that had focus before the window blurred (i.e. 
 * thumbnail or video link) won't play again when the
 * pop-up window closes.
 */
 function accentWindowFocusHandler()
 {
   accentWindowLostFocus = true;
   if(accentWindowFocusTimer != null) {
     clearTimeout(accentWindowFocusTimer);
   }
   accentWindowFocusTimer
     = setTimeout("accentWindowLostFocus = false", accentWindowFocusDelay);
 }
 
 
 /**
  * Sets the window lost focus flag. Intended to set state
  * for the accentWindowFocusHandler function.
  */
 function accentWindowBlurHandler()
 {
   accentWindowLostFocus = true;
   if(accentWindowFocusTimer != null) {
     clearTimeout(accentWindowFocusTimer);
   }
 }
 
 
 /**
 * Checks if the player window is open. If not, it opens
 * it and sets the global widow handle
 *
 * @param dontUseCache Forces call to window.open, even if
 *                     we already have a handle.
 *
 * @return Object Handle to the player window
 */
 function accentOpenPlayerWin(dontUseCache)
 { 
   //window.alert( dontUseCache );
   if (typeof(dontUseCache) == "undefined") {
 	dontUseCache = false;
   }
   if(dontUseCache || !accentPlayerWin || accentPlayerWin.closed) {
     accentPlayerWin = window.open("", 
       accentGetPlayerWinName(), accentPLAYER_WIN_FEATURES);
     // Detect pop-up blocker
     if (accentPlayerWin==null) 
     {
       accentInfo.speaking = 'f';  // since we couldn't open the player force off speaking feature
       accentReload();             // refreshes the state for the accent speech control
     }
   }
   return accentPlayerWin;
 }
 
 
 
 //************************************
 //********* Cookie code **************
 //************************************
 // 
 // Based on code from cookie.js
 // by Bill Dortch, hIdaho Design <bdortch@hidaho.com>
 //
 var accentDELIM = " | ";
 
 /**
  * Converts a Javascript object into a string. This handles
  * only first level values. It doesn't recursively convert
  * objects contained within objects.
  *
  * @param obj The object to convert
  *
  * @return String The textual representation.
  */
 function accentObj2string(obj)
 {
   var text = "";
   var key;
 
   for( key in obj )
   {
     if(text)
     {
       text = text + accentDELIM + key + "=" + obj[key];
     }
     else
     {
       text = key + "=" + obj[key];
     }
   }
 
   return text;
 
 } // accentObj2string()
 
 
 /**
  * Converts a string, as created by accentObj2String, into
  * an object.
  *
  * @param text String to convert to an object.
  *
  * @return Object The represented object
  */
 function accentString2obj(text)
 {
   var obj = new Object;
 
   if(text)
   {
     var item;
     var items = text.split(accentDELIM);
 
     for(var i = 0; i < items.length; i++)
     {
       item = items[i].split('=');
       obj[item[0]] = item[1];
     }
   }
 
   return obj;
 
 } // accentString2obj()
 
 
 /**
  * Sets a cookie containing a string representation of an object
  * as converted by accentObj2String.
  *
  * @param obj The object to store in the cookie.
  */
 function accentSetCookie(obj)
 {	
    // Set the expiration value in days and set it in a new Date
    expiredays = 1000;
    var ExpireDate = new Date ();
    ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
    
    //
    // does this overwrite all cookies, or just accent???
    //
    // set the cookie, the date is converted to Greenwich Mean time using "toGMTstring()"
    //
    document.cookie = "accent=" + escape(accentObj2string(obj)) + ";path=/" +
 					((expiredays == null) ? "" : ";expires=" + ExpireDate.toGMTString());
    //window.alert("setting accent=" + escape(accentObj2string(obj)));
    
    if(document.cookie.length == 0)
      return false;
    else
      return true;
 
 } // setAccentCookie()
 
 
 /**
  * Creates an object from the cookie stored by setAccentCookie.
  *
  * @return Object The object retrieved from the cookie string.
  */
 function accentGetCookie()
 {
    var arg = "accent=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) 
    {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
      {
        //window.alert("found accent=" + getCookieVal(j));
        return accentString2obj(accentGetCookieVal(j));
      }
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break; 
    }
 
    return null; // or {}
 
 } // accentGetCookie()
 
 
 /**
  * Retrieves text at a given offset, to the next cookie delimiter.
  *
  * @param offset The offset to start the string.
  *
  * @return String The extracted text.
  */
 function accentGetCookieVal (offset) 
 {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
      endstr = document.cookie.length;
 
    return unescape(document.cookie.substring(offset, endstr));
 
 } // accentGetCookieVal()
 
 
 
 function accentCheckIsJavaEnabled ()
 
 {
 
    var testResult;
 
     // java
     var is_java = (navigator.javaEnabled());
 
     
     //alert("accentCheckIsJavaEnabled, is_java: " + is_java);
     //alert("accentCheckIsJavaEnabled, mozmac: " + accentCheckMozillaAndMac());
 
     return is_java;    
 
   
 
 }
 
 
 function accentCheckMozillaAndMac ()
 
 
 {
 
     var output;
 
     var agt=navigator.userAgent.toLowerCase();
     var appVer = navigator.appVersion.toLowerCase();
 
 
     var is_konq = false;
     var kqPos   = agt.indexOf('konqueror');
     if (kqPos !=-1) {                 
        var is_konq  = true;
        //var is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
        //var is_major = parseInt(is_minor);
     }                                 
 
 
     var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
     var is_khtml  = (is_safari || is_konq);
 
 
     var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
 
 
     var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                     (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                     (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                     (is_gecko) && 
                     ((navigator.vendor=="")||(navigator.vendor=="Mozilla")));
 
     if (is_moz) {
        var is_moz_ver = (navigator.vendorSub)?navigator.vendorSub:0;
        if(!(is_moz_ver)) {
            is_moz_ver = agt.indexOf('rv:');
            is_moz_ver = agt.substring(is_moz_ver+3);
            is_paren   = is_moz_ver.indexOf(')');
            is_moz_ver = is_moz_ver.substring(0,is_paren);
        }
        is_minor = is_moz_ver;
        is_major = parseInt(is_moz_ver);
     }
 
     var is_mac    = (agt.indexOf("mac")!=-1);
     var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) ||
                                (agt.indexOf("68000")!=-1)));
     var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) ||
                                 (agt.indexOf("powerpc")!=-1)));
 
 
     //alert("accentCheckMozillaAndMac, is_mac is: " + is_mac);
     //alert("accentCheckMozillaAndMac, is_mac68k is: " + is_mac68k);
     //alert("accentCheckMozillaAndMac, is_macppc is: " + is_macppc);
 
 
 
     if ( ( (is_mac) || (is_mac68k) || (is_macppc) ) && (is_moz) ) {
 
          return true;
 
     } else {
 
 
          return false;
     
     }
 
 
 
 }
 
 
 
 function accentCheckNetscape7_1AndMac() 
 
 {
 
     //alert('Checking if Netscape7.1 and Mac');
 
 
     // convert all characters to lowercase to simplify testing
     var agt=navigator.userAgent.toLowerCase();
     var appVer = navigator.appVersion.toLowerCase();
 
 
     var is_minor = parseFloat(appVer);
     var is_major = parseInt(is_minor);
 
 
 
 // ***********************
 
     var is_konq = false;
     var kqPos   = agt.indexOf('konqueror');
     if (kqPos !=-1) {                 
        var is_konq  = true;
        //var is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
        //var is_major = parseInt(is_minor);
     }                                 
 
 
     var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
     var is_khtml  = (is_safari || is_konq);
 
 
     var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
 
 
     var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                     (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                     (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                     (is_gecko) && 
                     ((navigator.vendor=="")||(navigator.vendor=="Mozilla")));
 
 
 
 
 //  ********************************
 
 
 
 
 
 
 
     var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                 && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                 && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
                 && (!is_khtml) && (!(is_moz)));
 
     // Netscape6 is mozilla/5 + Netscape6/6.0!!!
     // Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0
     // Changed this to use navigator.vendor/vendorSub - dmr 060502   
     // var nav6Pos = agt.indexOf('netscape6');
     // if (nav6Pos !=-1) {
     if ((navigator.vendor)&&
         ((navigator.vendor=="Netscape6")||(navigator.vendor=="Netscape"))&&
         (is_nav)) {
        is_major = parseInt(navigator.vendorSub);
        // here we need is_minor as a valid float for testing. We'll
        // revert to the actual content before printing the result. 
        is_minor = parseFloat(navigator.vendorSub);
     }
 
 
 
     var is_mac    = (agt.indexOf("mac")!=-1);
     var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) ||
                                (agt.indexOf("68000")!=-1)));
     var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) ||
                                 (agt.indexOf("powerpc")!=-1)));
 
 
 
     if ( (is_nav) && (is_minor == 7.1) && ( (is_mac) || (is_mac68k) || (is_macppc) ) ) {
 
 
 	return true;
 
     } else {
 
    	return false;
 
     }
 
 
 }
 
 
 function accentIsSpeechAvailable() {
 
 
 
   accentJavaIsEnabled = accentCheckIsJavaEnabled();
 
   if (accentJavaIsEnabled) {
 
     //alert('Java is Enabled');
     return true;
 
   } 
   else {
 
    //vbt alert('in selectPlayer');
    if (accentCheckMozillaAndMac()) {
 	//alert('MozMac Condition');
         return true;
 
    } else if (accentCheckNetscape7_1AndMac()) {
 
 	//alert('Netscape7.1 and Mac');
 	return true;
 
    } else {
 	//alert('NO MozMac Condition');
 
       return false;
 
    }
 
   }
 
 
 
 }
 
 
