
function SoundManager(smURL,smID){var self=this;this.version='V2.0b.20070415';this.url=(smURL||'soundmanager2.swf');this.debugMode=false;this.useConsole=false;this.consoleOnly=false;this.nullURL='sounds/null.mp3';this.defaultOptions={'autoLoad':false,'stream':true,'autoPlay':false,'onid3':null,'onload':null,'whileloading':null,'onplay':null,'whileplaying':null,'onstop':null,'onfinish':null,'onbeforefinish':null,'onbeforefinishtime':5000,'onbeforefinishcomplete':null,'onjustbeforefinish':null,'onjustbeforefinishtime':200,'multiShot':true,'pan':0,'volume':100}
this.allowPolling=true;this.enabled=false;this.o=null;this.id=(smID||'sm2movie');this.oMC=null;this.sounds=[];this.soundIDs=[];this.isIE=(navigator.userAgent.match(/MSIE/));this.isSafari=(navigator.userAgent.match(/safari/i));this.debugID='soundmanager-debug';this._debugOpen=true;this._didAppend=false;this._appendSuccess=false;this._didInit=false;this._disabled=false;this._hasConsole=false;this._debugLevels=!self.isSafari?['debug','info','warn','error']:['log','log','log','log'];this.getMovie=function(smID){return self.isIE?window[smID]:(self.isSafari?document[smID+'-embed']:document.getElementById(smID+'-embed'));}
this.loadFromXML=function(sXmlUrl){try{self.o._loadFromXML(sXmlUrl);}catch(e){self._failSafely();return true;}}
this.createSound=function(oOptions){if(!self._didInit)throw new Error('soundManager.createSound(): Not loaded yet - wait for soundManager.onload() before calling sound-related methods');if(arguments.length==2){oOptions={'id':arguments[0],'url':arguments[1]}}
var thisOptions=self._mergeObjects(oOptions);self._writeDebug('soundManager.createSound(): "<a href="#" onclick="soundManager.play(\''+thisOptions.id+'\');return false" title="play this sound">'+thisOptions.id+'</a>" ('+thisOptions.url+')',1);if(self._idCheck(thisOptions.id,true)){self._writeDebug('sound '+thisOptions.id+' already defined - exiting',2);return false;}
self.sounds[thisOptions.id]=new SMSound(self,thisOptions);self.soundIDs[self.soundIDs.length]=thisOptions.id;try{self.o._createSound(thisOptions.id,thisOptions.onjustbeforefinishtime);}catch(e){self._failSafely();return true;}
if(thisOptions.autoLoad||thisOptions.autoPlay)self.sounds[thisOptions.id].load(thisOptions);if(thisOptions.autoPlay)self.sounds[thisOptions.id].playState=1;}
this.destroySound=function(sID){if(!self._idCheck(sID))return false;for(var i=self.soundIDs.length;i--;){if(self.soundIDs[i]==sID){delete self.soundIDs[i];continue;}}
self.sounds[sID].unload();delete self.sounds[sID];}
this.load=function(sID,oOptions){if(!self._idCheck(sID))return false;self.sounds[sID].load(oOptions);}
this.unload=function(sID){if(!self._idCheck(sID))return false;self.sounds[sID].unload();}
this.play=function(sID,oOptions){if(!self._idCheck(sID)){if(typeof oOptions!='Object')oOptions={url:oOptions};if(oOptions&&oOptions.url){self._writeDebug('soundController.play(): attempting to create "'+sID+'"',1);oOptions.id=sID;self.createSound(oOptions);}else{return false;}}
self.sounds[sID].play(oOptions);}
this.start=this.play;this.setPosition=function(sID,nMsecOffset){if(!self._idCheck(sID))return false;self.sounds[sID].setPosition(nMsecOffset);}
this.stop=function(sID){if(!self._idCheck(sID))return false;self._writeDebug('soundManager.stop('+sID+')',1);self.sounds[sID].stop();}
this.stopAll=function(){self._writeDebug('soundManager.stopAll()',1);for(var oSound in self.sounds){if(self.sounds[oSound]instanceof SMSound)self.sounds[oSound].stop();}}
this.pause=function(sID){if(!self._idCheck(sID))return false;self.sounds[sID].pause();}
this.resume=function(sID){if(!self._idCheck(sID))return false;self.sounds[sID].resume();}
this.togglePause=function(sID){if(!self._idCheck(sID))return false;self.sounds[sID].togglePause();}
this.setPan=function(sID,nPan){if(!self._idCheck(sID))return false;self.sounds[sID].setPan(nPan);}
this.setVolume=function(sID,nVol){if(!self._idCheck(sID))return false;self.sounds[sID].setVolume(nVol);}
this.setPolling=function(bPolling){if(!self.o||!self.allowPolling)return false;self._writeDebug('soundManager.setPolling('+bPolling+')');self.o._setPolling(bPolling);}
this.disable=function(){if(self._disabled)return false;self._disabled=true;self._writeDebug('soundManager.disable(): Disabling all functions - future calls will return false.',1);for(var i=self.soundIDs.length;i--;){self._disableObject(self.sounds[self.soundIDs[i]]);}
self.initComplete();self._disableObject(self);}
this.getSoundById=function(sID,suppressDebug){if(!sID)throw new Error('SoundManager.getSoundById(): sID is null/undefined');var result=self.sounds[sID];if(!result&&!suppressDebug){self._writeDebug('"'+sID+'" is an invalid sound ID.',2);}
return result;}
this.onload=function(){soundManager._writeDebug('<em>Warning</em>: soundManager.onload() is undefined.',2);}
this.onerror=function(){}
this._idCheck=this.getSoundById;this._disableObject=function(o){for(var oProp in o){if(typeof o[oProp]=='function'&&typeof o[oProp]._protected=='undefined')o[oProp]=function(){return false;}}
oProp=null;}
this._failSafely=function(){var flashCPLink='http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html';var fpgssTitle='You may need to whitelist this location/domain eg. file:///C:/ or C:/ or mysite.com, or set ALWAYS ALLOW under the Flash Player Global Security Settings page. Note that this seems to apply only to file system viewing.';var flashCPL='<a href="'+flashCPLink+'" title="'+fpgssTitle+'">view/edit</a>';var FPGSS='<a href="'+flashCPLink+'" title="Flash Player Global Security Settings">FPGSS</a>';if(!self._disabled){self._writeDebug('soundManager: JS-&gt;Flash communication failed. Possible causes: flash/browser security restrictions ('+flashCPL+'), insufficient browser/plugin support, or .swf not found',2);self._writeDebug('Verify that the movie path of <em>'+self.url+'</em> is correct (<a href="'+self.url+'" title="If you get a 404/not found, fix it!">test link</a>)',1);if(self._didAppend){if(!document.domain){self._writeDebug('Loading from local file system? (document.domain appears to be null, this URL path may need to be added to \'trusted locations\' in '+FPGSS+')',1);self._writeDebug('Possible security/domain restrictions ('+flashCPL+'), should work when served by http on same domain',1);}}
self.disable();}}
this._createMovie=function(smID,smURL){if(self._didAppend&&self._appendSuccess)return false;if(window.location.href.indexOf('debug=1')+1)self.debugMode=true;self._didAppend=true;var html=['<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="16" height="16" id="'+smID+'"><param name="movie" value="'+smURL+'"><param name="quality" value="high"><param name="allowScriptAccess" value="always" /></object>','<embed name="'+smID+'-embed" id="'+smID+'-embed" src="'+smURL+'" width="1" height="1" quality="high" allowScriptAccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>'];var toggleElement='<div id="'+self.debugID+'-toggle" style="position:fixed;_position:absolute;right:0px;bottom:0px;_top:0px;width:1.2em;height:1.2em;line-height:1.2em;margin:2px;padding:0px;text-align:center;border:1px solid #999;cursor:pointer;background:#fff;color:#333;z-index:706" title="Toggle SM2 debug console" onclick="soundManager._toggleDebug()">-</div>';var debugHTML='<div id="'+self.debugID+'" style="display:'+(self.debugMode&&((!self._hasConsole||!self.useConsole)||(self.useConsole&&self._hasConsole&&!self.consoleOnly))?'block':'none')+';opacity:0.85"></div>';var appXHTML='soundManager._createMovie(): appendChild/innerHTML set failed. Serving application/xhtml+xml MIME type? Browser may be enforcing strict rules, not allowing write to innerHTML. (PS: If so, this means your commitment to XML validation is going to break stuff now, because this part isn\'t finished yet. ;))';var sHTML='<div style="position:absolute;left:-256px;top:-256px;width:1px;height:1px" class="movieContainer">'+html[self.isIE?0:1]+'</div>'+(self.debugMode&&((!self._hasConsole||!self.useConsole)||(self.useConsole&&self._hasConsole&&!self.consoleOnly))&&!document.getElementById(self.debugID)?'x'+debugHTML+toggleElement:'');var oTarget=(document.body?document.body:document.getElementsByTagName('div')[0]);if(oTarget){self.oMC=document.createElement('div');self.oMC.className='movieContainer';self.oMC.style.position='absolute';self.oMC.style.left='-256px';self.oMC.style.width='1px';self.oMC.style.height='1px';try{oTarget.appendChild(self.oMC);self.oMC.innerHTML=html[self.isIE?0:1];self._appendSuccess=true;}catch(e){throw new Error(appXHTML);}
if(!document.getElementById(self.debugID)&&((!self._hasConsole||!self.useConsole)||(self.useConsole&&self._hasConsole&&!self.consoleOnly))){var oDebug=document.createElement('div');oDebug.id=self.debugID;oDebug.style.display=(self.debugMode?'block':'none');if(self.debugMode){try{var oD=document.createElement('div');oTarget.appendChild(oD);oD.innerHTML=toggleElement;}catch(e){throw new Error(appXHTML);}}
oTarget.appendChild(oDebug);}
oTarget=null;}
self._writeDebug('-- SoundManager 2 Version '+self.version.substr(1)+' --',1);self._writeDebug('soundManager._createMovie(): trying to load <a href="'+smURL+'" title="Test this link (404=bad)">'+smURL+'</a>',1);}
this._writeDebug=function(sText,sType){if(!self.debugMode)return false;if(self._hasConsole&&self.useConsole){console[self._debugLevels[sType]||'log'](sText);if(self.useConsoleOnly)return true;}
var sDID='soundmanager-debug';try{var o=document.getElementById(sDID);if(!o)return false;var p=document.createElement('div');p.innerHTML=sText;o.insertBefore(p,o.firstChild);}catch(e){}
o=null;}
this._writeDebug._protected=true;this._writeDebugAlert=function(sText){alert(sText);}
if(window.location.href.indexOf('debug=alert')+1){self.debugMode=true;self._writeDebug=self._writeDebugAlert;}
this._toggleDebug=function(){var o=document.getElementById(self.debugID);var oT=document.getElementById(self.debugID+'-toggle');if(!o)return false;if(self._debugOpen){oT.innerHTML='+';o.style.display='none';}else{oT.innerHTML='-';o.style.display='block';}
self._debugOpen=!self._debugOpen;}
this._toggleDebug._protected=true;this._debug=function(){self._writeDebug('soundManager._debug(): sounds by id/url:',0);for(var i=0,j=self.soundIDs.length;i<j;i++){self._writeDebug(self.sounds[self.soundIDs[i]].sID+' | '+self.sounds[self.soundIDs[i]].url,0);}}
this._mergeObjects=function(oMain,oAdd){var o1=oMain;var o2=(typeof oAdd=='undefined'?self.defaultOptions:oAdd);for(var o in o2){if(typeof o1[o]=='undefined')o1[o]=o2[o];}
return o1;}
this.createMovie=function(sURL){if(sURL)self.url=sURL;self._initMovie();}
this._initMovie=function(){if(self.o)return false;self.o=self.getMovie(self.id);if(!self.o){self._createMovie(self.id,self.url);self.o=self.getMovie(self.id);}
if(self.o){self._writeDebug('soundManager._initMovie(): Got '+self.o.nodeName+' element ('+(self._didAppend?'created via JS':'static HTML')+')',1);}}
this.initComplete=function(){if(self._didInit)return false;self._didInit=true;self._writeDebug('-- SoundManager 2 '+(self._disabled?'failed to load':'loaded')+' ('+(self._disabled?'security/load error':'OK')+') --',1);if(self._disabled){self._writeDebug('soundManager.initComplete(): calling soundManager.onerror()',1);self.onerror.apply(window);return false;}
self._writeDebug('soundManager.initComplete(): calling soundManager.onload()',1);try{self.onload.apply(window);}catch(e){self._writeDebug('soundManager.onload() threw an exception: '+e.message,2);throw e;}
self._writeDebug('soundManager.onload() complete',1);}
this.init=function(){if(window.removeEventListener){window.removeEventListener('load',self.beginInit,false);}else if(window.detachEvent){window.detachEvent('onload',self.beginInit);}
try{self.o._externalInterfaceTest();self._writeDebug('Flash ExternalInterface call (JS -&gt; Flash) succeeded.',1);if(!self.allowPolling)self._writeDebug('Polling (whileloading/whileplaying support) is disabled.',1);self.setPolling(true);self.enabled=true;}catch(e){self._failSafely();self.initComplete();return false;}
self.initComplete();}
this.beginDelayedInit=function(){setTimeout(self.beginInit,200);}
this.beginInit=function(){self.createMovie();self._initMovie();setTimeout(self.init,1000);}
this.destruct=function(){if(self.isSafari){for(var i=self.soundIDs.length;i--;){if(self.sounds[self.soundIDs[i]].readyState==1)self.sounds[self.soundIDs[i]].unload();}}
self.disable();}}
function SMSound(oSM,oOptions){var self=this;var sm=oSM;this.sID=oOptions.id;this.url=oOptions.url;this.options=sm._mergeObjects(oOptions);this.id3={}
self.resetProperties=function(bLoaded){self.bytesLoaded=null;self.bytesTotal=null;self.position=null;self.duration=null;self.durationEstimate=null;self.loaded=false;self.loadSuccess=null;self.playState=0;self.paused=false;self.readyState=0;self.didBeforeFinish=false;self.didJustBeforeFinish=false;}
self.resetProperties();this.load=function(oOptions){self.loaded=false;self.loadSuccess=null;self.readyState=1;self.playState=(oOptions.autoPlay||false);var thisOptions=sm._mergeObjects(oOptions);if(typeof thisOptions.url=='undefined')thisOptions.url=self.url;try{sm._writeDebug('loading '+thisOptions.url,1);sm.o._load(self.sID,thisOptions.url,thisOptions.stream,thisOptions.autoPlay,thisOptions.whileloading?1:0);}catch(e){sm._writeDebug('SMSound().load(): JS-&gt;Flash communication failed.',2);}}
this.unload=function(){sm._writeDebug('SMSound().unload(): "'+self.sID+'"');self.setPosition(0);sm.o._unload(self.sID,sm.nullURL);self.resetProperties();}
this.play=function(oOptions){if(!oOptions)oOptions={};if(oOptions.onfinish)self.options.onfinish=oOptions.onfinish;if(oOptions.onbeforefinish)self.options.onbeforefinish=oOptions.onbeforefinish;if(oOptions.onjustbeforefinish)self.options.onjustbeforefinish=oOptions.onjustbeforefinish;var thisOptions=sm._mergeObjects(oOptions);if(self.playState==1){var allowMulti=thisOptions.multiShot;if(!allowMulti){sm._writeDebug('SMSound.play(): "'+self.sID+'" already playing? (one-shot)',1);return false;}else{sm._writeDebug('SMSound.play(): "'+self.sID+'" already playing (multi-shot)',1);}}
if(!self.loaded){if(self.readyState==0){sm._writeDebug('SMSound.play(): .play() before load request. Attempting to load "'+self.sID+'"',1);thisOptions.stream=true;thisOptions.autoPlay=true;self.load(thisOptions);}else if(self.readyState==2){sm._writeDebug('SMSound.play(): Could not load "'+self.sID+'" - exiting',2);return false;}else{sm._writeDebug('SMSound.play(): "'+self.sID+'" is loading - attempting to play..',1);}}else{sm._writeDebug('SMSound.play(): "'+self.sID+'"');}
if(self.paused){self.resume();}else{self.playState=1;self.position=(thisOptions.offset||0);if(thisOptions.onplay)thisOptions.onplay.apply(self);self.setVolume(thisOptions.volume);self.setPan(thisOptions.pan);if(!thisOptions.autoPlay){sm.o._start(self.sID,thisOptions.loop||1,self.position);}}}
this.start=this.play;this.stop=function(bAll){if(self.playState==1){self.playState=0;self.paused=false;if(sm.defaultOptions.onstop)sm.defaultOptions.onstop.apply(self);sm.o._stop(self.sID);}}
this.setPosition=function(nMsecOffset){sm.o._setPosition(self.sID,nMsecOffset/1000,self.paused||!self.playState);}
this.pause=function(){if(self.paused)return false;sm._writeDebug('SMSound.pause()');self.paused=true;sm.o._pause(self.sID);}
this.resume=function(){if(!self.paused)return false;sm._writeDebug('SMSound.resume()');self.paused=false;sm.o._pause(self.sID);}
this.togglePause=function(){sm._writeDebug('SMSound.togglePause()');if(!self.playState){self.play({offset:self.position/1000});return false;}
if(self.paused){sm._writeDebug('SMSound.togglePause(): resuming..');self.resume();}else{sm._writeDebug('SMSound.togglePause(): pausing..');self.pause();}}
this.setPan=function(nPan){if(typeof nPan=='undefined')nPan=0;sm.o._setPan(self.sID,nPan);self.options.pan=nPan;}
this.setVolume=function(nVol){if(typeof nVol=='undefined')nVol=100;sm.o._setVolume(self.sID,nVol);self.options.volume=nVol;}
this._whileloading=function(nBytesLoaded,nBytesTotal,nDuration){self.bytesLoaded=nBytesLoaded;self.bytesTotal=nBytesTotal;self.duration=nDuration;self.durationEstimate=parseInt((self.bytesTotal/self.bytesLoaded)*self.duration);if(self.readyState!=3&&self.options.whileloading)self.options.whileloading.apply(self);}
this._onid3=function(oID3PropNames,oID3Data){sm._writeDebug('SMSound()._onid3(): "'+this.sID+'" ID3 data received.');var oData=[];for(var i=0,j=oID3PropNames.length;i<j;i++){oData[oID3PropNames[i]]=oID3Data[i];}
self.id3=sm._mergeObjects(self.id3,oData);if(self.options.onid3)self.options.onid3.apply(self);}
this._whileplaying=function(nPosition){if(isNaN(nPosition)||nPosition==null)return false;self.position=nPosition;if(self.playState==1){if(self.options.whileplaying)self.options.whileplaying.apply(self);if(self.loaded&&self.options.onbeforefinish&&self.options.onbeforefinishtime&&!self.didBeforeFinish&&self.duration-self.position<=self.options.onbeforefinishtime){sm._writeDebug('duration-position &lt;= onbeforefinishtime: '+self.duration+' - '+self.position+' &lt= '+self.options.onbeforefinishtime+' ('+(self.duration-self.position)+')');self._onbeforefinish();}}}
this._onload=function(bSuccess){bSuccess=(bSuccess==1?true:false);sm._writeDebug('SMSound._onload(): "'+self.sID+'"'+(bSuccess?' loaded.':' failed to load (or loaded from cache - weird bug) - [<a href="'+self.url+'">test URL</a>]'));self.loaded=bSuccess;self.loadSuccess=bSuccess;self.readyState=bSuccess?3:2;if(self.options.onload)self.options.onload.apply(self);}
this._onbeforefinish=function(){if(!self.didBeforeFinish){self.didBeforeFinish=true;if(self.options.onbeforefinish)self.options.onbeforefinish.apply(self);}}
this._onjustbeforefinish=function(msOffset){if(!self.didJustBeforeFinish){self.didJustBeforeFinish=true;if(self.options.onjustbeforefinish)self.options.onjustbeforefinish.apply(self);;}}
this._onfinish=function(){sm._writeDebug('SMSound._onfinish(): "'+self.sID+'"');self.playState=0;self.paused=false;if(self.options.onfinish)self.options.onfinish.apply(self);if(self.options.onbeforefinishcomplete)self.options.onbeforefinishcomplete.apply(self);self.setPosition(0);self.didBeforeFinish=false;self.didJustBeforeFinish=false;}}
var soundManager=new SoundManager();if(window.addEventListener){window.addEventListener('load',soundManager.beginDelayedInit,false);window.addEventListener('beforeunload',soundManager.destruct,false);}else if(window.attachEvent){window.attachEvent('onload',soundManager.beginInit);window.attachEvent('beforeunload',soundManager.destruct);}else{soundManager.onerror();soundManager.disable();}
soundManager.createMovie();var WA={Initialize:null,Keyboard:null,Navigation:null,Nodes:null,PageLoad:null,Prefetcher:null,Utils:null,Sound:null,READ:1,KEYBOARD:2,PAUSED:3,PLAY_ONE:4,PLAY_ONE_BACKWARD:5,PLAY_TWO_BACKWARD:6,PREV_CHAR:7,PREV_CHAR_BACKONE:8,browseMode:this.READ,sitespecific:false,spotlighting:false,prefetchStrategy:1,timesLoaded:0};WA.Utils={trim:function(stringToTrim){return stringToTrim.replace(/^\s+|\s+$/g,"");},getRecordingTextarea:function(){var doc=getNavigationDocument();var rta=doc.getElementById('recording');return rta;},getTime:function(){var d=new Date();return d.valueOf();},recordLine:function(line){if(recordActions){var rta=this.getRecordingTextarea();rta.value+=this.getTime()+" "+line+"\n";}},callForEachDoc:function(win,func){for(var i=0;i<win.frames.length;i++){func(win.frames[i].document);}},postURL:function(url,params,cb){var prefetch_req=null;if(window.XMLHttpRequest){prefetch_req=new XMLHttpRequest();}else if(window.ActiveXObject){prefetch_req=new ActiveXObject("Microsoft.XMLHTTP");}
prefetch_req.onreadystatechange=cb;prefetch_req.open("POST",url,true);prefetch_req.setRequestHeader("Content-type","application/x-www-form-urlencoded");prefetch_req.setRequestHeader("Content-length",params.length);prefetch_req.setRequestHeader("Connection","close");prefetch_req.send(params);},getXPath:function(node){if(!node){return"(none)";}
var xpath="";var namespace=node.ownerDocument.documentElement.namespaceURI;var prefix=namespace?"x:":"";var node2=node;var doc=node.ownerDocument;var node_id=null;if(node.getAttribute){node_id=node.getAttribute('id');}
for(var i=0;node2&&node2!=doc;i++){if(!node2.tagName||!node2.parentNode){return"";}
var tag=node2.tagName.toLowerCase();var id=node2.id;var className=node2.className;var segment=prefix+tag;if(tag.length>0){var cl=node2.getAttribute('class');if(id&&id!=""&&false){xpath="//"+segment+'[@id="'+id+'"]'+xpath;break;}else{var par_childs=node2.parentNode.childNodes;var node_num=1;for(var j=0,pcl=par_childs.length;j<pcl;j++){var child_tag=par_childs[j].tagName;if(!child_tag){continue;}
child_tag=par_childs[j].tagName.toLowerCase();if(par_childs[j]==node2){break;}
if(child_tag==tag){node_num++;}}
segment+='['+node_num+']';}}else if(tag=="tr"){var rowCount=node2.parentNode.rows.length;if(rowCount>1&&rowCount<5){segment+='['+(node2.rowIndex+1)+']';}}else if(tag=="td"){var cellCount=node2.parentNode.cells.length;if(cellCount>1&&cellCount<5){segment+='['+(node2.cellIndex+1)+']';}}
xpath="/"+segment+xpath;node2=node2.parentNode;}
if(node_id){xpath+='#'+node_id;}
return xpath;},isIE:function(){return(navigator.appName=="Microsoft Internet Explorer");},simpleHash:function(str){if(str==null){return'nullhash';}
var type=String(typeof str);if(type=='undefined'){return'undefinedhash';}
if(type!='string'){str=String(str);}
if(str.length<=0){return'emptystring';}
var bin=Array(16);var str_len=str.length;for(var i=0;i<16;i++){bin[i]=str_len+i;}
for(var i=0;i<str_len;i++){var update_val=str.charCodeAt(i)*(i&0xFF)
bin[(i&0xF)]+=update_val;bin[((i<<2)&0xF)]+=update_val;}
var hex_tab="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#*@!";var str2="";for(var i=0,bl=bin.length;i<bl;i++){str2+=hex_tab.charAt(bin[i]&0x3F);}
var val=str.substring(0,15)+str2;val=val.replace(/&#(\d)+;/g,"p$1");val=val.replace(/[^a-zA-Z0-9]+/g,'');return val;},log:function(str){if(typeof console!='undefined'&&typeof console.log!='undefined'){console.log(str);}}};WA.Utils.Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode64:function(input){var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;do{chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3=input.charCodeAt(i++);enc1=chr1>>2;enc2=((chr1&3)<<4)|(chr2>>4);enc3=((chr2&15)<<2)|(chr3>>6);enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64;}else if(isNaN(chr3)){enc4=64;}
output=output+this._keyStr.charAt(enc1)+this._keyStr.charAt(enc2)+
this._keyStr.charAt(enc3)+this._keyStr.charAt(enc4);}while(i<input.length);return output;},decode64:function(input){var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");var fcc=String.fromCharCode;do{enc1=this._keyStr.indexOf(input.charAt(i++));enc2=this._keyStr.indexOf(input.charAt(i++));enc3=this._keyStr.indexOf(input.charAt(i++));enc4=this._keyStr.indexOf(input.charAt(i++));chr1=(enc1<<2)|(enc2>>4);chr2=((enc2&15)<<4)|(enc3>>2);chr3=((enc3&3)<<6)|enc4;output=output+fcc(chr1);if(enc3!=64){output=output+fcc(chr2);}
if(enc4!=64){output=output+fcc(chr3);}}while(i<input.length);return output;}}
WA.Nodes={_breakUpSound:false,_breakUpSoundDelimiter:" || ",nodeTypeBreaker:(this._breakUpSound?this._breakUpSoundDelimiter:""),recursion_limit:1000-20,leafNode:function(node){if(node&&node.nodeType&&node.nodeType==3){return true;}else{return this.leafElement(node);}},hasAttribute:function(node,attrib){if(node.hasAttribute){return node.hasAttribute(attrib);}else{var attr=node.attributes[attrib];return(attr!=undefined)&&attr&&attr.specified;}},leafElement:function(elem){switch(elem.tagName){case'A':if(this.hasAttribute(elem,'name')){return false;}else{return true;}
case'AREA':case'BUTTON':case'IMG':case'SCRIPT':case'HEAD':case'IFRAME':case'SELECT':case'NOSCRIPT':case'LABEL':return isVisible(elem);}
return!elem.hasChildNodes();},handleNode:function(node,goingDown){if(!goingDown){return null;}
switch(node.nodeType){case 1:if(node.offsetWidth<=0){return"";}else{return this.handleElement(node);}
case 2:return"";case 3:var ret_val=node.data;if(ret_val.length>0&&ret_val.match(/\w/)){ret_val=ret_val.replace(/&#\d+;/,"");return ret_val;}
return"";case 8:case 9:case 10:default:return"";}
return"";},handleChildNodes:function(node){var result="";for(var i=0,ncl=node.childNodes.length;i<ncl;i++){result+=this.handleNode(node.childNodes[i],true)+" ";if(!this.leafNode(node.childNodes[i]))
result+=this.handleChildNodes(node.childNodes[i]);}
return result;},handleAreaNode:function(elem){if(elem.getAttribute('alt'))
return elem.getAttribute('alt');else if(elem.getAttribute('href'))
return elem.getAttribute('href');else
return"";},handleImageNode:function(elem){if(elem.getAttribute('alt')){return elem.getAttribute('alt');}else{return"";}},handleListNode:function(elem){var result="";var parent=elem.parentNode;while(parent&&parent.tagName!="BODY"){if(parent.tagName=="OL"){var elems=parent.getElementsByTagName("LI");for(var i=0,el=elems.length;i<el;i++){if(elems[i]==elem){result+=(i+1)+". ";break;}}
break;}
parent=parent.parentNode;}
return result;},handleInputNode:function(elem){var result="";if(this.hasAttribute(elem,'type')){switch(elem.getAttribute('type')){case'button':result+="Button: "+this.nodeTypeBreaker+elem.value;break;case'checkbox':result+="Checkbox "+this.nodeTypeBreaker+this.getLabelName(elem);result+=": "+((elem.checked==true)?"checked":"unchecked");break;case'file':result+="File Input "+this.nodeTypeBreaker+this.getLabelName(elem);result+=": "+elem.value;break;case'hidden':break;case'image':result+="Image Input "+this.nodeTypeBreaker+this.getLabelName(elem)+": ";result+=elem.value;break;case'password':result+="Password Textarea "+this.nodeTypeBreaker+this.getLabelName(elem);break;case'radio':result+="Radio Button "+this.nodeTypeBreaker+this.getLabelName(elem)+": "+elem.value;break;case'reset':result+="Reset Button: "+this.nodeTypeBreaker+elem.value;break;case'submit':result+="Submit Button: "+this.nodeTypeBreaker+elem.value;break;default:result+="Text Area "+this.nodeTypeBreaker+this.getLabelName(elem)+": "+elem.value;}}
return result;},handleElement:function(elem){var result="";switch(elem.tagName){case'A':if(this.hasAttribute(elem,'href'))
result+="link "+this.nodeTypeBreaker+this.handleChildNodes(elem);break;case'AREA':result+="link "+this.nodeTypeBreaker+this.handleAreaNode(elem);break;case'BUTTON':result+=this.handleChildNodes(elem)+" button";break;case'H1':result+="Heading 1";break;case'H2':result+="Heading 2";break;case'H3':result+="Heading 3";break;case'H4':result+="Heading 4";break;case'H5':result+="Heading 5";break;case'H6':result+="Heading 6";break;case'IMG':var image_text=this.handleImageNode(elem);if(image_text&&image_text.length>0){result+="Image "+this.nodeTypeBreaker+image_text;}
break;case'INPUT':result+=this.handleInputNode(elem);break;case'LI':result+=this.handleListNode(elem);break;case'SELECT':result+="Selection "+this.getLabelName(elem)+": "+this.nodeTypeBreaker+elem.value;break;case'TABLE':var rows=elem.rows.length;var cols=this.getLargestRowLength(elem.rows);if(rows>2&&cols>2){result+="Table "+this.getTableNum(elem)+" "+this.getTableName(elem)+" start "+
rows+" rows "+
cols+" columns";}
break;case'TEXTAREA':result+="Text Area "+this.getLabelName(elem)+": "+this.nodeTypeBreaker+elem.value;break;case'UL':case'OL':var numitems=this.getNumberOfListElements(elem);if(numitems>0){result+="List with "+numitems+" items";}}
if(elem.getAttribute('title')){result=result+" "+elem.getAttribute('title');}
return result;},getLabelName:function(elem){if(this.hasAttribute(elem,'my_label'))
return elem.getAttribute('my_label');else if(this.hasAttribute(elem,'name'))
return elem.getAttribute('name');return"";},getNumberOfListElements:function(elem){var num=0;if(typeof elem=='undefined'||typeof elem.childNodes=='undefined'){return 0;}
for(var i=0,ecl=elem.childNodes.length;i<ecl;i++){if(elem.childNodes.nodeName=="LI"){num++;}}
return num;},getTableName:function(elem){if(elem.caption){return this.handleChildNodes(elem.caption);}else if(elem.summary){return elem.summary;}else{return"";}},getTableNum:function(elem){var tables=elem.ownerDocument.getElementsByTagName('TABLE');for(var i=0,tl=tables.length;i<tl;i++){if(tables[i]==elem)return i;}
return 0;},getLargestRowLength:function(rows){var longest=0;for(var i=0,rl=rows.length;i<rl;i++)
if(rows[i].cells.length>longest)
longest=rows[i].cells.length;return longest;},treeTraverseRecursion:function(node,visitor,isleaf){this._treeTraverseRecursion(node,visitor,isleaf,0);},_treeTraverseRecursion:function(node,visitor,isleaf,depth){if(depth>this.recursion_limit){return;}
if(depth!=this.recursion_limit&&node){visitor(node);}
if((typeof isleaf!='function')||!isleaf(node)){if(node.firstChild){this._treeTraverseRecursion(node.firstChild,visitor,isleaf,depth+1);}}
if(node.nextSibling){this._treeTraverseRecursion(node.nextSibling,visitor,isleaf,depth+1);}},getStyle:function(elem,prop){var prop_value=null;if(elem.currentStyle){prop_value=elem.currentStyle[prop];}else if(window.getComputedStyle){prop_value=document.defaultView.getComputedStyle(elem,null).getPropertyValue(prop);}
return prop_value;}};WA.Sound={FLASH_SOUND_METHOD:1,EMBED_SOUND_METHOD:2,soundsPlayed:0,totalLatency:0,soundMethod:-1,soundsLoaded:new Array(),free_threads:25,soundPlayerLoaded:false,soundQ:new Array(),playing:null,playWaitingInterval:50,inPlayWaiting:false,lastPath:-1,soundState:-1,readyState:-1,startedSoundInit:false,setSoundMethod:function(){if(/embed=true/.test(document.location+"")){return this.EMBED_SOUND_METHOD;}else{return this.FLASH_SOUND_METHOD;}},initSounds:function(){startPriority=30000;this.free_threads=5;this.soundPlayerLoaded=false;this.soundQ=new Array();this.playing=null;this.soundMethod=1;this.soundsLoaded=new Array();WA.browseMode=WA.READ;},prepareSound:function(sid){if(sid&&sid.length>1){sid=sid.toLowerCase();sid=sid.replace(/(^\s*[\.\?!,\-:]*\s*)|(\s*[\.\?!,:]+\s*$)/g,"");}
return sid;},getSoundID:function(text){return WA.Utils.simpleHash(text);},splitSoundsByBoundaries:true,boundarySplitterRegExp:/[\.!\?:;\s]*(\s+\(|\s+\-\s+|[\.!\?:;\)]\s+)+[\.!\?:;\s]*/,splitSoundsByBoundary:function(sid){return(sid+"").split(this.boundarySplitterRegExp);},addSound:function(sid){if(this.splitSoundsByBoundaries){var matches=this.splitSoundsByBoundary(sid);if(matches&&matches.length>0){for(var match_i=0,ml=matches.length;match_i<ml;match_i++){if(!this.boundarySplitterRegExp.test(matches[match_i])){this._addIndividualSound(matches[match_i]);}}}}else{this._addIndividualSound(sid);}},_addIndividualSound:function(sid){sid=this.prepareSound(sid);this.soundQ.unshift(sid);},getSound:function(){var sid=this.soundQ.pop();return sid;},prefetchFromSoundQ:function(){if(this.soundQ.length>0){var remaining=this.soundQ.slice();WA.Utils.log('pf from q: '+remaining.length);remaining.reverse();this.Prefetch.addArrayToPrefetchQ(remaining);}},stopAllSounds:function(){if(this.soundMethod==this.FLASH_SOUND_METHOD){soundManager.stopAll();}else{Embed.stopSounds();}},resetSounds:function(){this.stopAllSounds();this.soundQ=null;this.soundQ=new Array();this.playing=null;},startPlayWaiting:function(){var self=this;if(!top.soundPlayerLoaded){setTimeout(function(){self.startPlayWaiting();},50);}else{setInterval(function(){self.playWaiting()},this.playWaitingInterval);}},playWaiting:function(){if(this.inPlayWaiting){return;}
this.inPlayWaiting=true;if(!this.soundPlayerLoaded){this.lastPath=0;this.inPlayWaiting=false;return;}else if(!this.playing&&this.soundQ.length>0){this.lastPath=1;var sid=this.getSound();this.lastPath=3;this.playing=sid;this.playSound(sid,false);if(WA.prefetchStrategy>1){this.prefetchFromSoundQ();}}else if(!this.playing&&(WA.browseMode==WA.READ||WA.browseMode==WA.PLAY_ONE||WA.browseMode==WA.PLAY_ONE_BACKWARD||WA.browseMode==WA.PLAY_TWO_BACKWARD||WA.browseMode==WA.PREV_CHAR||WA.browseMode==WA.PREV_CHAR_BACKONE)){this.lastPath=2;if(WA.browseMode==WA.PLAY_ONE_BACKWARD||WA.browseMode==WA.PLAY_TWO_BACKWARD||WA.browseMode==WA.PREV_CHAR||WA.browseMode==WA.PREV_CHAR_BACKONE){this.lastPath=99;prevNode(true);}else{nextNode(true);}}else if(this.playing){var is_playing=this.isPlaying(this.playing);WA.Utils.log('playing '+this.playing+' '+is_playing);if(!is_playing){this.playing=null;}}
this.inPlayWaiting=false;},urlForString:function(string){var url=top.sound_url_base.replace(/\$text\$/,escape(string));url=proxifyURL(url,"");return url;},playSound:function(string,bm){var playdone=true;string=this.prepareSound(string);url=this.urlForString(string);switch(this.soundMethod){case this.FLASH_SOUND_METHOD:this._prefetchFlash(string,url,playdone,bm);break;case this.EMBED_SOUND_METHOD:Embed._prefetchEmbed(string,url,playdone,bm);break;}},prefetchKeycode:function(keycode){var speak="";switch(keycode){case 8:speak="back space";break;default:speak=String.fromCharCode(keycode);}
var url='/cgi-bin/getsound.pl?text='+escape(speak);url=proxifyURL(url,"");switch(this.soundMethod){case this.FLASH_SOUND_METHOD:this._prefetchFlash("keycode_"+keycode,url,false,false);break;case this.EMBED_SOUND_METHOD:Embed._prefetchEmbed("keycode_"+keycode,url,false,false);break;}},setupBaseSounds:function(){if(this.startedSoundInit){return;}
this.startedSoundInit=true;for(var i=32;i<97;i++){this.prefetchKeycode(i);}
for(var j=123;j<127;j++){this.prefetchKeycode(i);}
init=1;},_fetchFromQueue:function(){for(var i=0;i<5&&i<N&&this.free_threads>0;i++){var p=this.Prefetch.popQ();switch(this.soundMethod){case 1:this._prefetchFlash(p.text,p.url,p.playdone,p.bm);break;case 2:Embed._prefetchEmbed(p.text,p.url,p.playdone,p.bm);break;default:break;}}},isPlaying:function(sid){sid=this.prepareSound(sid);switch(this.soundMethod){case 1:return this._isPlayingFlash(sid);case 2:return this._isPlayingEmbed(sid);default:break;}
return false;},_isPlayingEmbed:function(string){return true;},_isPlayingFlash:function(string){string=this.getSoundID(string);var sound=soundManager.getSoundById(string);if(!sound)this.soundState=8;if(sound&&sound.readyState>=2&&sound.playState==0){return false;}else{return true;}},timingArray:new Object(),getTimingList:function(){var timing_list="";var total_latency=0;var total_sounds=0;var total_length=0;for(i in this.timingArray){if(this.timingArray[i].playStart){var latency=(this.timingArray[i].end-this.timingArray[i].playStart);if(latency>0){timing_list+=latency+'\n';total_latency+=latency;}
total_length+=this.timingArray[i].length;}else{alert('no playStart');}
total_sounds++;}
var mean=(total_latency/total_sounds);var sd=0;for(i in this.timingArray){if(this.timingArray[i].playStart){var latency=(this.timingArray[i].end-this.timingArray[i].playStart);if(latency<60000)
sd+=(latency-mean)*(latency-mean);}}
sd=Math.sqrt((sd/total_sounds));return mean+' '+sd+' '+total_latency+' '+total_sounds+' '+total_length+'||';},tInfo:function(string){this.start=null;this.end=null;this.playStart=null;this.finished=false;this.length=null;},_prefetchFlash:function(string,url,playdone,bm){if(!this.soundPlayerLoaded){return;}
var orig_string=string;string=this.getSoundID(string);var sound=soundManager.getSoundById(string);var old_length=0;if(this.timingArray[string]&&!this.timingArray[string].playStart){old_length=this.timingArray[string].length;this.timingArray[string+Math.random()]=this.timingArray[string];}
this.timingArray[string]=new this.tInfo(string);this.timingArray[string].orig_string=orig_string;if(playdone){this.timingArray[string].playStart=new Date();WA.Utils.log('starting sound: '+this.timingArray[string].playStart.getTime()+' '+orig_string);}
this.timingArray[string].length=old_length;if(!sound||sound.readyState==2){if(this.free_threads<=0){WA.Utils.log(this);this.Prefetch.addToPrefetchDOMQ(string,url,playdone,bm);}else{this.free_threads--;soundManager.createSound({id:string,url:url,autoLoad:true,stream:playdone,autoPlay:playdone,onload:function(){WA.Sound._onSoundLoad(this)},onplay:function(){valPath+=this.sID;WA.Sound.soundsPlayed++;},whileplaying:function(){if(this.timingArray[this.sID].end==null){WA.Sound.soundsPlayed++;this.timingArray[this.sID].end=new Date();this.whileplaying=null;}},onfinish:function(){WA.Sound._onSoundFinish()},volume:75});}}else if(sound.readyState==3){WA.Utils.log('sound exists: '+sound);this.lastPath=15;sound.onjustbeforefinish=function(){WA.Sound._onSoundFinish()};var duration=(WA.Sound.Prefetch.prefetchRecords[string]&&WA.Sound.Prefetch.prefetchRecords[string].soundlength)?WA.Sound.Prefetch.prefetchRecords[string].soundlength:this.timingArray[string].length;WA.Utils.log('finished sound: '+this.timingArray[string].playStart.getTime()+' '+duration+' '+this.timingArray[string].orig_string);sound.play();WA.Utils.log('playing sound: '+sound.play);}else if(sound.readyState==0||sound.readyState==1){sound.autoPlay=playdone;}},_onSoundLoad:function(sound){this.timingArray[sound.sID].end=new Date();this.timingArray[sound.sID].length=sound.durationEstimate;WA.Utils.log('finished sound: '+this.timingArray[sound.sID].end.getTime()+' '+sound.durationEstimate+' '+this.timingArray[sound.sID].orig_string);this.free_threads++;this.lastPath=10;sound.didalmostfinish=false;},playLoadingSound:function(){return;soundManager.createSound({id:'::webanywhere-sound-effects::load',url:url,autoLoad:true,stream:playdone,autoPlay:playdone,onload:function(){WA.Sound._onSoundLoad(this)},onplay:function(){valPath+=this.sID;WA.Sound.soundsPlayed++;},whileplaying:function(){if(this.timingArray[this.sID].end==null){WA.Sound.soundsPlayed++;this.timingArray[this.sID].end=new Date();this.whileplaying=null;}},onfinish:function(){WA.Sound._onsoundfinish(this)},volume:75});},_onSoundFinish:function(sound){if(sound&&sound.duration){this.timingArray[sound.sID].length=sound.duration;WA.Utils.log('finished sound: '+this.timingArray[string].playStart.getTime()+' '+sound.duration+' '+this.timingArray[string].orig_string);}else{WA.Utils.log('finished sound: '+this.timingArray[string].end.getTime()+' '+sound.durationEstimate+' '+this.timingArray[string].orig_string);}
if(WA.Sound.playing!=null){var is_playing=WA.Sound.isPlaying(WA.Sound.playing);if(is_playing){setTimeout(function(){_onsoundfinish()},100);}else{this.playing=null;if(WA.browseMode==WA.READ||this.soundQ.length>0){WA.Sound.playWaiting();}}}},_donePlayingEmbedSound:function(){WA.Utils.log('done playing: '+this.playing);this.playing=null;},initSound:function(){this.soundMethod=this.setSoundMethod();if(this.soundMethod==this.FLASH_SOUND_METHOD){soundManager.defaultOptions={'autoLoad':false,'stream':true,'autoPlay':false,'onid3':null,'onload':null,'whileloading':null,'onplay':null,'whileplaying':null,'onstop':null,'onfinish':null,'onbeforefinish':null,'onbeforefinishtime':5000,'onbeforefinishcomplete':null,'onjustbeforefinish':null,'onjustbeforefinishtime':200,'multiShot':true,'pan':0,'volume':100}
soundManager.onload=function(){WA.Utils.log("soundManager loaded");WA.Sound.soundPlayerLoaded=true;top.soundPlayerLoaded=true;if(top.pageLoaded){newPage();}}
soundManager.onerror=function(){this.soundPlayerLoaded=false;this.soundMethod=this.EMBED_SOUND_METHOD;}}
this.addSound("Welcome to Web Anywhere");}};WA.Sound.initSound();WA.Sound.Prefetch={Sound:WA.Sound,qLock:false,domQ:new Array(),N:0,startPriority:30000,basePriority:this.startPriority,initPrefetch:function(){this.startPriority=30000;this.basePriority=this.startPriority;this.setPrefetchType();this.prefetch_array[0]=new Array();},setPrefetchType:function(){var top_location=top.location+'';if(/prefetch=\d+/.test(top_location)){top_location=top_location.replace(/^.*prefetch=(\d+).*$/,"$1");WA.prefetchStrategy=parseInt(top_location);}},domQueue:function(text,url,playdone,bm,val){this.text=text;this.sid=WA.Sound.getSoundID(text);this.val=val;this.url=url;this.playdone=playdone;this.bm=bm;this.alertMe=function(){alert(text+' '+url+' '+playdone+' '+bm+' '+val)};},addToPrefetchDOMQ:function(string,url,playdone,bm){var p=new this.domQueue(string,url,playdone,bm,this.basePriority);this.basePriority++;this.pushQ(p);},upHeap:function(child){var newElt=this.domQ[child];var parenti=Math.floor(child/2);while(parenti>=1){if(this.domQ[parenti].val<newElt.val){this.domQ[child]=this.domQ[parenti];child=parenti;parenti=Math.floor(child/2);}else break;}
this.domQ[child]=newElt;},pushQ:function(elem){qLock=true;this.N++;this.domQ[this.N]=elem;this.upHeap(this.N);qLock=false;},downHeap:function(parent){var newElt=this.domQ[parent];var child=2*parent;while(child<=this.N){if(child<this.N)
if(this.domQ[child+1].val>this.domQ[child].val)
child++;if(newElt.val<this.domQ[child].val){this.domQ[parent]=this.domQ[child];parent=child;child=2*parent;}else break;}
this.domQ[parent]=newElt;},popQ:function(){qLock=true;var highest=this.domQ[1];this.domQ[1]=this.domQ[this.N];this.N--;this.downHeap(1);return highest;qLock=false;},peakQ:function(){return this.domQ[1];},prefetchNext:function(){switch(WA.prefetchStrategy){case-1:if(this.N>0){var p=this.peakQ();this.prefetchSound(p.url,p.text,p.playdone);}else{}
break;case 0:break;case 1:case 2:case 3:var text_to_fetch=this.getFromPrefetchQ();if(text_to_fetch){if(WA.playing!=null&&WA.browseMode==WA.READ&&Math.random()>0.5){setTimeout("WA.Sound.Prefetch.prefetchNext();",550);}else if(/\S/.test(text_to_fetch)){var pred=this.prefetchText(text_to_fetch);if(!pred)setTimeout("WA.Sound.Prefetch.prefetchNext();",200);}else{setTimeout("WA.Sound.Prefetch.prefetchNext();",200);}}else{setTimeout("WA.Sound.Prefetch.prefetchNext();",200);}
break;default:}},prefetch_array:new Array(),prefetch_curr_index:0,resetPrefetchArray:function(){if(this.prefetch_curr_index<=this.prefetch_array.length){for(var i=this.prefetch_curr_index-1;i>0;i--){this.prefetch_array[i]=new Array();}}},prefetchTimeout:null,restartPrefetchTimeout:function(){clearTimeout(this.prefetchTimeout);this.prefetchTimeout=setTimeout("WA.Sound.Prefetch.prefetchNext()",0);},prefetchRecords:new Object(),addArrayToPrefetchQ:function(sarray){this.prefetch_array[this.prefetch_curr_index+1]=new Array();for(var i=0,sl=sarray.length;i<sl;i++){var sid=sarray[i];if(true){this.prefetch_array[this.prefetch_curr_index+1].push(sid);}else{}}
this.prefetch_curr_index++;},incPrefetchIndex:function(){this.prefetch_curr_index++;this.prefetch_array[this.prefetch_curr_index]=new Array();},addToPrefetchQ:function(sid){if(this.Sound.splitSoundsByBoundaries){var matches=this.Sound.splitSoundsByBoundary(sid);if(matches&&matches.length>0){for(var match_i=0,ml=matches.length;match_i<ml;match_i++){if(!WA.Sound.boundarySplitterRegExp.test(matches[match_i])){this._addIndividualToPrefetchQ(matches[match_i]);}}}}else{this._addIndividualToPrefetchQ(sid);}},_addIndividualToPrefetchQ:function(sid){sid=this.Sound.prepareSound(sid);this.prefetch_array[this.prefetch_curr_index].push(sid);},getFromPrefetchQ:function(){var sid=null;if(this.prefetch_array&&this.prefetch_array[this.prefetch_curr_index].length<1&&this.prefetch_curr_index>0){WA.Utils.log('moving from queue: '+this.prefetch_curr_index+' to '+(this.prefetch_curr_index-1));this.prefetch_curr_index--;sid=this.getFromPrefetchQ();}else{WA.Utils.log('fetching from: '+this.prefetch_curr_index);sid=this.prefetch_array[this.prefetch_curr_index].shift();}
return sid;},prefetch_req:null,prefetchSound:function(url,text,playdone){if(true){if(window.XMLHttpRequest){WA.Sound.Prefetch.prefetch_req=new XMLHttpRequest();}else if(window.ActiveXObject){WA.Sound.Prefetch.prefetch_req=new ActiveXObject("Microsoft.XMLHTTP");}}
var sid=WA.Sound.getSoundID(text);WA.Sound.Prefetch.prefetch_req.onreadystatechange=function(){WA.Sound.Prefetch.processReqChangePrefetchSound(text,sid,playdone);}
WA.Sound.Prefetch.prefetch_req.open("GET",url,true);WA.Sound.Prefetch.prefetch_req.send(null);},processReqChangePrefetchSound:function(text,sid,playdone){if(WA.Sound.Prefetch.prefetch_req.readyState==4){if(WA.Sound.Prefetch.prefetch_req.status==200){var soundLength=WA.Sound.Prefetch.prefetch_req.getResponseHeader('sound-length');if(soundLength){WA.Utils.log('got sound '+text+' '+soundLength);WA.Sound.Prefetch.prefetchRecords[sid].soundlength=soundLength;}else{}
var contentLength=WA.Sound.Prefetch.prefetch_req.getResponseHeader('content-length');if(contentLength){WA.Utils.log('got sound '+text+' '+contentLength);WA.Sound.Prefetch.prefetchRecords[sid].contentlength=contentLength;}else{}
if(playdone){WA.Utils.log("playing after supposed fetching");this.Sound.playSound(text,false);}}else{}
setTimeout(function(){WA.Sound.Prefetch.prefetchNext();},0);}},prefetchTypes:{NEXTNODE:1,PREVNODE:2,NEXTFOCUS:3,PREVFOCUS:4,NEXTINPUT:5,PREVINPUT:6,NEXTHEADING:7,PREVHEADING:8,OTHER:9},keyToAction:function(key_string){var action;switch(key_string){case"arrowdown":action=this.prefetchTypes.NEXTNODE;break;case"arrowup":action=this.prefetchTypes.PREVNODE;break;case"tab":action=this.prefetchTypes.NEXTFOCUS;break;case"shift tab":action=this.prefetchTypes.PREVFOCUS;break;case"ctrl i":action=this.prefetchTypes.NEXTINPUT;break;case"ctrl shift i":action=this.prefetchTypes.PREVINPUT;break;case"ctrl h":action=this.prefetchTypes.NEXTHEADING;break;case"ctrl shift h":action=this.prefetchTypes.PREVHEADING;break;default:action=this.prefetchTypes.OTHER;break;}},prefetchObservations:new Object(),addObservation:function(currAction,currNode,prevAction){var obs_string=String(prevAction)+" "+String(this.nodeToString(currNode));if(this.prefetchObservations[obs_string]==null){this.prefetchObservations[obs_string]=new Array(this.prefetchTypes.OTHER+1);for(var i=0;i<this.prefetchTypes.OTHER+1;i++){this.prefetchObservations[obs_string][i]=0;}}
this.prefetchObservations[obs_string][currAction]++;this.prefetchObservations[obs_string][0]++;},nodeToString:function(currNode){if(currNode){return currNode.nodeName;}else{return null;}},predictNext:function(currNode,prevAction){var possActions=new Array(this.prefetchTypes.OTHER+1);var obs_string=String(prevAction)+" "+String(this.nodeToString(currNode));WA.Utils.log('pfetch for '+obs_string);if(this.prefetchObservations[obs_string]!=null){var totalObs=this.prefetchObservations[obs_string][0]+
this.prefetchObservations[obs_string].length;for(var i=0,pal=possActions.length;i<pal;i++){possActions[i]=(prefetchObservations[obs_string][i]+1)/(totalObs);}}else{this.uniformArray(possActions);}
return possActions;},uniformArray:function(array){var val=1.0/(array.length);for(var i=0;i<array.length;i++){array[i]=val;}},alertPrefetching:function(){var string="";for(obs in this.prefetchObservations){string+=obs+": "+this.prefetchObservations[obs].join(", ")+" \n";}
var predictN=this.predictNext(lastNode,WA.Keyboard.last_action);string+="\n"+lastNode+"  "+WA.Keyboard.last_action;string+="\n\n"+predictN.join(", ");alert(string);return;},numPrefetched:0,prefetchText:function(text){var string=this.Sound.prepareSound(text);var url=this.Sound.urlForString(string);var sid=WA.Sound.getSoundID(text);if(typeof this.prefetchRecords[sid]=='undefined'){this.prefetchRecords[sid]=new Object();this.prefetchRecords[sid].soundlength=-1;this.numPrefetched++;this.prefetchSound(url,text,false);return true;}else{return false;}
return false;},prefetchNode:function(node){if(node){var text=WA.Nodes.handleNode(node,true);addToPrefetchQ(text);}},prefetchNextOnes:function(node,num){for(i=0;i<num;i++){node=firstNodeNoSound(node);node=nextBySpeaks(node);this.prefetchNode(node);}},prefetchPrediction:function(){var predictions=this.predictNext(lastNode,WA.Keyboard.last_action);var impl=[1,3,5,7];var highest=1;var high_val=0.0;for(var i=0,il=impl.length;i<il;i++){var pred=predictions[impl[i]];if(pred>high_val){high_val=pred;highest=impl[i];}}
WA.Utils.log('highest is '+highest);var next_node=null;this.incPrefetchIndex();switch(highest){case this.prefetchTypes.NEXTFOCUS:next_node=nextByFocus(currentNode);this.prefetchNode(next_node);var best_node=next_node;this.prefetchNextOnes(currentNode,2);best_node=firstNodeNoSound(best_node);next_node=nextByFocus(best_node);this.prefetchNode(next_node);this.prefetchNextOnes(best_node,1);break;case this.prefetchTypes.NEXTHEADING:next_node=nextByTag(currentNode,"H");this.prefetchNode(next_node);var best_node=next_node;this.prefetchNextOnes(currentNode,2);best_node=firstNodeNoSound(best_node);next_node=nextByTag(best_node,"H");this.prefetchNode(next_node);this.prefetchNextOnes(best_node,1);break;case this.prefetchTypes.NEXTINPUT:next_node=nextByTag(currentNode,"INPUT|SELECT|TEXTAREA");this.prefetchNode(next_node);var best_node=next_node;this.prefetchNextOnes(currentNode,2);best_node=firstNodeNoSound(best_node);next_node=nextByTag(best_node,"INPUT|SELECT|TEXTAREA");this.prefetchNode(next_node);this.prefetchNextOnes(best_node,1);break;case this.prefetchTypes.NEXTNODE:default:this.prefetchNextOnes(currentNode,3);break;}},lettersNotFetched:['w','.','h','t','p','/','g','o','e','l','b','f','c','i','j','k','m','n','d','q','r','s','u','v','a','x','y','z','go','star','end of page','submit button'],prefetchLetters:function(){if(this.prefetch_array&&this.prefetch_array[0]){for(i=0,lnfl=this.lettersNotFetched.length;i<lnfl;i++){this.prefetch_array[0].push(this.lettersNotFetched[i]);}}}};WA.Sound.Prefetch.initPrefetch();WA.Keyboard={wa_ctrl_pressed:false,wa_alt_pressed:false,wa_shift_pressed:false,wa_ctrl_speaks:false,wa_alt_speaks:false,wa_shift_speaks:false,wa_up_tracker:false,formsModeOn:false,last_action:null,doKeyPress:function(e,target,key_string,source){if(!browserInit){this.suppressKeys(e);return false;}
var target_id=null;var target_type=null;if(target){target_id=target.getAttribute('id');target_type=target.tagName;}
WA.Utils.recordLine('keypress: '+key_string+' '+source+' '+WA.Utils.getXPath(target)+' '+WA.Utils.getXPath(currentNode));var return_val=false;var default_case=false;if(this.alwaysAllowed(key_string)){return true;}
var new_node=null;var last_node=currentNode;switch(key_string){case'ctrl':silenceAll();this.wa_up_tracker=false;break;case'tab':this.suppressKeys(e);if(target_id=="location"){focusBrowserElement('location_go');}else if(target_id=='location_go'){WA.browseMode=WA.KEYBOARD;focusContentElement('always_first_node');WA.Sound.resetSounds();WA.browseMode=WA.PLAY_ONE;}else if(target_id=='always_last_node'){WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();WA.browseMode=WA.PLAY_ONE;}else{WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();nextNodeFocus();WA.browseMode=WA.PLAY_ONE;}break;case'shift tab':this.suppressKeys(e);if(target_id=="location_go"||target_id=="location"){focusBrowserElement('location');}else if(target_id=='always_first_node'){focusBrowserElement('location_go');}else{WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();prevNodeFocus();WA.browseMode=WA.PLAY_ONE;}
break;case'alt leftarrow':goBack();break;case'alt rightarrow':goForward();break;case'ctrl l':this.suppressKeys(e);focusBrowserElement('location');break;case'ctrl tab':case'ctrl shift tab':break;case'ctrl r':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();new_node=nextTableRow(lastNodePlayed);if(new_node){setCurrentNode(new_node);WA.browseMode=WA.PLAY_ONE;}else{broseMode=WA.KEYBOARD;}
break;case'ctrl f':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();focusBrowserElement('finder_field');finderBarFocus();break;case'ctrl d':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();new_node=nextTableCol(lastNodePlayed);if(new_node){setCurrentNode(new_node);WA.browseMode=WA.PLAY_ONE;}else{broseMode=WA.KEYBOARD;}
break;case'ctrl t':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();new_node=nextNodeTagAttrib("TABLE",null);if(new_node){WA.browseMode=WA.READ;}else{broseMode=WA.KEYBOARD;}
break;case'ctrl shift t':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();new_node=prevNodeTagAttrib("TABLE",null);if(new_node){WA.browseMode=WA.READ;}else{WA.browseMode=WA.KEYBOARD;}
break;case'ctrl h':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();new_node=nextNodeTagAttrib("H",null);if(new_node){WA.browseMode=WA.READ;}else{broseMode=WA.KEYBOARD;}
break;case'ctrl shift h':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();new_node=prevNodeTagAttrib("H",null);if(new_node){WA.browseMode=WA.READ;}else{WA.browseMode=WA.KEYBOARD;}
break;case'ctrl shift f5':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();WA.Utils.log(WA.Sound.getTimingList()+'\n\n'+WA.Sound.totalLatency+' '+WA.Sound.soundsPlayed+' '+totalDuration+' '+(WA.Sound.totalLatency/totalDuration));break;case'ctrl shift f6':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();WA.Sound.Prefetch.alertPrefetching();break;case'ctrl shift f7':WA.Sound.timingArray=new Object();WA.Utils.log('reset timing array');break;case'ctrl shift r':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();new_node=prevTableRow(lastNodePlayed);if(new_node){setCurrentNode(new_node);WA.browseMode=WA.PLAY_ONE;}else{broseMode=WA.KEYBOARD;}
break;case'ctrl shift d':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();new_node=prevTableCol(lastNodePlayed);if(new_node){setCurrentNode(new_node);WA.browseMode=WA.PLAY_ONE;}else{broseMode=WA.KEYBOARD;}
break;case'ctrl p':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();new_node=nextNodeTagAttrib("P",null);WA.browseMode=WA.READ;break;case'ctrl shift p':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();new_node=prevNodeTagAttrib("P",null);WA.browseMode=WA.READ;break;case'ctrl i':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();new_node=nextNodeTagAttrib("INPUT|SELECT|BUTTON",null);WA.browseMode=WA.PLAY_ONE;break;case'ctrl shift i':this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();new_node=prevNodeTagAttrib("INPUT|SELECT|BUTTON",null);WA.browseMode=WA.PLAY_ONE;break;case'ctrl 6':WA.Sound.Prefetch.prefetchPrediction();WA.Utils.log('done');break;case'pagedown':this.suppressKeys(e);WA.Sound.resetSounds();nextNode(true);WA.browseMode=WA.READ;break;case'home':this.suppressKeys(e);WA.Sound.resetSounds();setCurrentNode(currentDoc.body);WA.browseMode=WA.READ;break;case'ctrl shift r':case'ctrl shift tab':case'ctrl tab':break;default:default_case=true;break;}
var select_chosen=false;if(target_type=="SELECT"){select_chosen=true;if(key_string.match(/ctrl arrow(up|down)/)){return_val=false;default_case=false;selectChange(key_string,target);}else if(key_string.match(/arrow/)){this.suppressSelect(e,target,true);}else{this.suppressSelect(e,target,false);}
WA.Utils.recordLine('return from select: '+default_case);}
if(default_case){if(key_string=="arrowup"&&!select_chosen){this.suppressKeys(e);WA.Sound.resetSounds();prevNode();WA.browseMode=WA.PLAY_ONE_BACKWARD;}else if(key_string=="arrowdown"&&!select_chosen){this.suppressKeys(e);WA.Sound.resetSounds();WA.browseMode=WA.PLAY_ONE;nextNode(true);}else if(target_type=="INPUT"||target_type=="TEXTAREA"){return_val=true;var target_type=target.getAttribute('type');if(target_type&&(/password/i.test(target_type))){_playkey("star",target);}else{_playkey(key_string,target);}}else if(key_string=="backspace"){this.suppressKeys(e);goBack();}else if(key_string=="spacebar"){this.suppressKeys(e);WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();}else if(key_string=="enter"){return_val=true;}else if(!select_chosen){key_string=String(key_string);if(source=='key up'){if(/^ctrl|alt|shift|insert$/.test(key_string)){}}else if(source=='key press'){}else if(source=='key down'){}
WA.Sound.addSound("Invalid key press");this.resetKeyboardModifiers();this.suppressKeys(e);}}
this.recordObservation(key_string,new_node,lastNode);if(new_node!=null){lastNode=new_node;}
setTimeout("WA.Sound.playWaiting();",0);return return_val;},recordObservation:function(key_string,new_node,old_node){var action=WA.Sound.Prefetch.keyToAction(key_string)
WA.Sound.Prefetch.addObservation(action,old_node,this.last_action);this.last_action=action;},getKeyString:function(e){var key_id=e.which?e.which:e.keyCode;var key="";if(key_id>=48&&key_id<=90){key=String.fromCharCode(key_id);}else{switch(key_id){case 8:key="backspace";break;case 9:key="tab";break;case 13:key="enter";break;case 16:key="shift";break;case 17:key="ctrl";break;case 18:key="alt";break;case 19:key="pause";break;case 20:key="capslock";break;case 27:key="esc";break;case 32:key="spacebar";break;case 33:key="pageup";break;case 34:key="pagedown";break;case 35:key="end";break;case 36:key="home";break;case 37:key="arrowleft";break;case 38:key="arrowup";break;case 39:key="arrowright";break;case 40:key="arrowdown";break;case 45:key="insert";break;case 46:key="del";break;case 59:key="semi-colon";break;case 91:key="left windows";break;case 92:key="right windows";break;case 93:key="select";break;case 96:key="numpad 0";break;case 97:key="numpad 1";break;case 98:key="numpad 2";break;case 99:key="numpad 3";break;case 100:key="numpad 4";break;case 101:key="numpad 5";break;case 102:key="numpad 6";break;case 103:key="numpad 7";break;case 104:key="numpad 8";break;case 105:key="numpad 9";break;case 106:key="multiply";break;case 107:key="add";break;case 109:key="subtract";break;case 110:key="decimal point";break;case 111:key="divide";break;case 112:key="f1";break;case 113:key="f2";break;case 114:key="f3";break;case 115:key="f4";break;case 116:key="f5";break;case 117:key="f6";break;case 118:key="f7";break;case 119:key="f8";break;case 120:key="f9";break;case 121:key="f10";break;case 122:key="f11";break;case 123:key="f12";break;case 144:key="num lock";break;case 145:key="scroll lock";break;case 186:key="semi-colon";break;case 187:key="equal sign";break;case 188:key="comma";break;case 189:key="dash";break;case 190:key="dot";break;case 191:key="forward slash";break;case 192:key="grave accent";break;case 219:key="open bracket";break;case 220:key="back slash";break;case 221:key="close bracket";break;case 222:key="single quote";break;}}
return key;},getTarget:function(e){var target;if(e.target)target=e.target;else if(e.srcElement)target=e.srcElement;else return null;if(target.nodeType==3)
target=target.parentNode;return target;},handleKeyDown:function(e){if(!e)e=window.event;var return_val=true;var key=this.getKeyString(e);var target=this.getTarget(e);var ctrlPressed=false;var altPressed=false;var shiftPressed=false;var appv=parseInt(navigator.appVersion);if(appv>3){if(appv!=4||navigator.appName!="Netscape"){shiftPressed=e.shiftKey;altPressed=e.altKey;ctrlPressed=e.ctrlKey;}else{var mString=(e.modifiers+32).toString(2).substring(3,6);shiftPressed=(mString.charAt(0)=="1");ctrlPressed=(mString.charAt(1)=="1");altPressed=(mString.charAt(2)=="1");}}
var string="";if((ctrlPressed||this.wa_ctrl_pressed)&&key!="ctrl"){string+="ctrl ";}
if((altPressed||this.wa_alt_pressed)&&key!="alt"){string+="alt ";}
if((shiftPressed||this.wa_shift_pressed)&&key!="shift"){string+="shift ";}
if(!shiftPressed)this.wa_shift_pressed=false;if(!altPressed)this.wa_alt_pressed=false;if(!ctrlPressed)this.wa_shift_presssed=false;if(key=="ctrl"){this.wa_ctrl_pressed=true;this.wa_ctrl_speaks=true;}else if(key=="alt"){this.wa_alt_pressed=true;this.wa_alt_speaks=true;}else if(key=="shift"){this.wa_shift_pressed=true;this.wa_shift_speaks=true;}
if(key&&key!=""){string+=key;}
key=string.toLowerCase();if(!key.match(/^((ctrl|alt|shift)\s*)*$/)){if(this.wa_ctrl_pressed){this.wa_ctrl_speaks=false;}
if(this.wa_alt_pressed){this.wa_alt_speaks=false;}
if(this.wa_shift_pressed){this.wa_shift_speaks=false;}
return_val=this.doKeyPress(e,target,key,"key down");}
return return_val;},alwaysAllowed:function(key){return/enter/i.test(key);},handleKeyUp:function(e){if(!e)e=window.event;var return_val=false;var target=this.getTarget(e);if(target.nodeName=="INPUT"){var target_type=target.getAttribute('type');if(/^password/i.test(target_type)){return true;}}
var key=this.getKeyString(e);if(this.alwaysAllowed(key)){return true;}
var orig_key=key;var string="";if(this.wa_ctrl_pressed&&key!="ctrl"){string+="ctrl ";}
if(this.wa_alt_pressed&&key!="alt"){string+="alt ";}
if(this.wa_shift_pressed&&key!="shift"){string+="shift ";}
if(key&&key!=""){string+=key;}
key=string.toLowerCase();if((this.wa_ctrl_speaks||this.wa_alt_speaks||this.wa_shift_speaks)&&key.match(/^((alt|ctrl|shift)\s*)*$/)){var full_key="";if(this.wa_ctrl_pressed){this.wa_ctrl_speaks=false;full_key+="ctrl ";}
if(this.wa_alt_pressed){this.wa_alt_speaks=false;full_key+="alt ";}
if(this.wa_shift_pressed){this.wa_shift_speaks=false;full_key+="shift ";}
key=full_key.substring(0,full_key.length-1);switch(orig_key){case"ctrl":this.wa_ctrl_pressed=false;break;case"alt":this.wa_alt_pressed=false;break;case"shift":this.wa_shift_pressed=false;break;}
return_val=this.doKeyPress(e,target,key,"key up");}else{switch(orig_key){case"ctrl":this.wa_ctrl_pressed=false;break;case"alt":this.wa_alt_pressed=false;break;case"shift":this.wa_shift_pressed=false;break;}
this.suppressKeys(e);}
if(!return_val){this.suppressKeys(e);}
return return_val;},handleKeyPress:function(e){var target=this.getTarget(e);if(target.nodeName=="INPUT"){var target_type=target.getAttribute('type');if(/^password/i.test(target_type)){return true;}}
var key=this.getKeyString(e);if(key!="enter"&&!this.playByType(target)){this.suppressKeys(e);return false;}else{return true;}},playByType:function(target){var target_id=null;var target_name=null;if(target){target_id=target.getAttribute('id');target_name=target.tagName;}
if(target_name=="INPUT"){var target_type=target.getAttribute('type');if(!target_type||/text/i.test(target_type)){return true;}}else if(target_name=="TEXTAREA"){return true;}
return false;},suppressKeys:function(e){if(e.stopPropagation){e.stopPropagation();e.preventDefault();}else{e.cancelBubble=true;e.returnValue=false;e.keyCode=0;}
return false;},suppressSelect:function(e,target,refocus){if(!e.which){e.cancelBubble=true;e.returnValue=false;}else{if(refocus){target.blur();refocusedSelect=target;setTimeout("refocusSelect()",0);}}
return false;},resetKeyboardModifiers:function(){this.wa_ctrl_pressed=false;this.wa_alt_pressed=false;this.wa_shift_pressed=false;this.wa_ctrl_speaks=false;this.wa_alt_speaks=false;this.wa_shift_speaks=false;this.wa_up_tracker=false;this.formsModeOn=false;}};var READING_PAGE=0;var LOADING_PAGE=1;var IN_BROWSER=2;var operating_state=IN_BROWSER;var currentLoc=null;var currentDoc=null;var currentNode=null;var currentWord=0;var currentChar=0;var lastNodePlayed=null;var programmaticFocus=false;var textBoxFocused=false;var browserInit=false;var init=0;var waiting_on_page="";var focusedNode=null;var recordActions=false;var emulationType=0;var updatePlayingCount=0;if(window.addEventListener){window.addEventListener('load',init_browser,false);}else if(window.attachEvent){window.attachEvent('onload',init_browser);}
function debug(str){var debug_div=document.getElementById('debug_div');if(debug_div){debug_div.appendChild(document.createTextNode(str));}}
function updatePlaying(){var play_div=document.getElementById('playing_div');if(play_div){play_div.innerHTML=(WA.Sound.playing!=null)?WA.Sound.playing:"(null)";}
var sound_div=document.getElementById('sound_div');if(currentNode&&currentNode.nodeType==1){sound_div.innerHTML="curr: "+(currentNode?(currentNode.nodeName+' '+(((currentNode.parentNode)?currentNode.parentNode.nodeName:""))):"nully")+" q: "+WA.Sound.soundQ.length+" b: "+WA.browseMode+' focus: '+focusedNode+' las: '+this.lastPath+' threads: '+this.free_threads+' '+(updatePlayingCount++)+' '+WA.Sound.soundQ+' val: '+valPath+' bMode:'+WA.browseMode;}else{sound_div.innerHTML="curr: "+(currentNode?(currentNode.nodeName+' ('+currentNode.data+') '+(((currentNode.parentNode)?currentNode.parentNode.nodeName:""))):"nully")+" q: "+WA.Sound.soundQ.length+" b: "+WA.browseMode+' focus: '+focusedNode+' las: '+this.lastPath+' threads: '+this.free_threads+' '+(updatePlayingCount++)+' '+WA.Sound.soundQ+' val: '+valPath+' bMode:'+WA.browseMode;}}
function init_browser(){focusLocation();browserInit=true;setInterval('updatePlaying()',200);setInterval(function(){WA.Keyboard.resetKeyboardModifiers();},60000);var go_button=document.getElementById('location_go');var location_field=document.getElementById('location');if(window.attachEvent)location_field.attachEvent('onfocus',locationFocus);else if(window.addEventListener)location_field.addEventListener('focus',locationFocus,false);if(window.attachEvent)location_field.attachEvent('onblur',function(){top.navigation_frame.textBoxFocused=false;});else if(window.addEventListener)location_field.addEventListener('blur',function(){top.navigation_frame.textBoxFocused=false;},false);if(window.attachEvent)go_button.attachEvent('onfocus',goButtonFocus);else if(window.addEventListener)go_button.addEventListener('focus',goButtonFocus,false);if(window.attachEvent)document.attachEvent('onkeydown',function(e){WA.Keyboard.handleKeyDown(e)});else if(window.addEventListener)document.addEventListener('keydown',function(e){WA.Keyboard.handleKeyDown(e)},false);if(window.attachEvent)document.attachEvent('onkeyup',function(e){WA.Keyboard.handleKeyUp(e)});else if(window.addEventListener)document.addEventListener('keyup',function(e){WA.Keyboard.handleKeyUp(e)},false);if(window.attachEvent)document.attachEvent('onkeypress',function(e){WA.Keyboard.handleKeyPress(e)});else if(window.addEventListener)document.addEventListener('keypress',function(e){WA.Keyboard.handleKeyPress(e)},false);if(WA.Sound.soundMethod==WA.Sound.EMBED_SOUND_METHOD){WA.Sound.soundPlayerLoaded=true;top.soundPlayerLoaded=true;newPage();}
WA.Sound.startPlayWaiting();WA.Sound.Prefetch.prefetchLetters();}
function locationFocus(e){top.navigation_frame.textBoxFocused=true;var target;if(!e)e=window.event;if(e.target)target=e.target;else if(e.srcElement)target=e.srcElement;if(target.nodeType==3)target=target.parentNode;WA.Sound.resetSounds();WA.Sound.addSound("Location field text area:");if(target.value){WA.Sound.addSound(target.value);}}
function finderBarFocus(){WA.Sound.resetSounds();WA.Sound.addSound("Type a string to find in the current page");}
function goKeyDown(e){var key=top.navigation_frame.keyString(e);if(key=='tab'){if(currentDoc.body){top.navigation_frame.programmaticFocus=true;debug("goKeyDown:true");setCurrentNode(currentDoc.body);currentDoc.body.firstChild.focus();top.navigation_frame.programmaticFocus=false;WA.browseMode=WA.READ;}
stopProp(e);return false;}}
function goButtonFocus(e){var target;if(!e)e=window.event;if(e.target)target=e.target;else if(e.srcElement)target=e.srcElement;if(target.nodeType==3)
target=target.parentNode;var text=WA.Nodes.handleNode(target,true);WA.Sound.resetSounds();WA.Sound.addSound("Go");}
function tabEndNode(e){var key=top.navigation_frame.keyString(e);if(key=='tab'){WA.Sound.addSound("End of Page.");stopProp(e);return false;}}
function tabStartNode(e){var key=top.navigation_frame.keyString(e);if(key=='shift tab'){var go_butt=top.navigation_frame.document.getElementById('location_go');go_butt.focus();stopProp(e);return false;}}
function tabLocation(e){var key=top.navigation_frame.keyString(e);if(key=='ctrl l'){stopProp(e);return false;}else if(key=='shift tab'){WA.Sound.resetSounds();WA.Sound.addSound("Start of Page.");stopProp(e);return false;}}
function focusLocation(){var location_field=document.getElementById('location');if(location_field){location_field.blur();location_field.focus();location_field.select();}}
function focusElement(doc,element_id){WA.browseMode=WA.PAUSED;WA.Sound.resetSounds();var elem=doc.getElementById(element_id);if(elem){elem.blur();elem.focus();if(elem.select){elem.select();}
setCurrentNode(elem);}}
function focusBrowserElement(element_id){var doc=getNavigationDocument();focusElement(doc,element_id);}
function focusContentElement(element_id){var doc=getContentDocument();focusElement(doc,element_id);}
function getContentDocument(){return top.content_frame.document;}
function getFirstContent(){var doc=getContentDocument();var first=doc.getElementById('always_first_node');if(!first&&doc.body&&doc.body.firstChild){first=doc.body.firstChild;}
return first;}
function getLastContent(){var doc=getContentDocument();var last=doc.getElementById('always_last_node');if(!last&&doc.body&&doc.body.lastChild){last=doc.body.lastChild;}
return last;}
function getNavigationDocument(){return top.navigation_frame.document;}
function silenceAll(){WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();}
function textBoxFocus(element){}
function getCursor(myField){if(!myField){return-3;}
if(!myField.value||myField.value==''){return 0;}else if(document.selection){var delim="deliim";myField.focus();sel=document.selection.createRange();sel.text=delim;var pos=myField.value.indexOf("deliim");myField.value=myField.value.replace(/deliim/,'');return pos;}else if(myField.selectionStart||myField.selectionStart=='0'){var startPos=myField.selectionStart;return startPos;}
return'-2';}
function stopProp(e){if(e.stopPropagation){e.stopPropagation();e.preventDefault();}else{e.cancelBubble=true;e.returnValue=false;e.keyCode=0;}
return false;}
function docKeyUpDown(e){var key=keyString(e);alert('key: '+key);if(key.matches(/ctrl l/)){WA.browseMode=WA.KEYBOARD;WA.Sound.resetSounds();stopProp(e);return false;}else{return true;}}
function docKeyPress(e){var targ;if(!e)e=window.event;if(e.target)targ=e.target;else if(e.srcElement)targ=e.srcElement;if(targ.nodeType==3)
targ=targ.parentNode;var key=top.navigation_frame.keyString(e);if(targ.nodeName=="SELECT"&&/ctrl.*arrow(up|down)/.test(key)){return;}
if(top.navigation_frame.textBoxFocused){if(/\s|tab|enter|home|arrowleft|arrowright/.test(key)){return;}}
top.navigation_frame._docKeyPress(key,targ,e);}
var refocusedSelect=null;function refocusSelect(){top.navigation_frame.programmaticFocus=true;debug("refocusedSelect:true");refocusedSelect.focus();}
function isValidKey(k){if(k>=32&&k<=126)
return true;return false;}
function toUpperKeyCode(k){if(k>96&&k<123)
return k-32;return k;}
function _playkey(key,targ){WA.Sound.resetSounds();WA.browseMode=top.navigation_frame.WA.KEYBOARD;if(/ctrl l/.test(key)){focusLocation();}else if(/arrow|backspace|del/.test(key)){var pos=top.navigation_frame.getCursor(targ);var text=targ.value;if(/left|right|backspace|del/.test(key)){if(/left/.test(key)){text=text.substring((pos-1),pos);}else if(/right/.test(key)){text=text.substring(pos+1,(pos+2));}else if(/backspace/.test(key)){text=text.substring((pos-1),pos);}else if(/del/.test(key)){text=text.substring(pos,pos+1);}
if(!text||text==""){text="blank";}
top.navigation_frame.WA.Sound.addSound(text);}else{return;}}else if(key=="enter"){return;}else{WA.Sound.playSound(key,false);}}
function preVisit(node){if(isFocusable(node)){if(window.attachEvent){node.attachEvent('onfocus',gotFocus);}else if(window.addEventListener){node.addEventListener('focus',gotFocus,false);}}
if(WA.prefetchStrategy>=1){var text=WA.Nodes.handleNode(node,true);if(text&&(WA.prefetchStrategy<=1||WA.Sound.Prefetch.prefetch_curr_index==0)){WA.Sound.Prefetch.prefetch_array[WA.Sound.Prefetch.prefetch_curr_index].push(text);}}
if(node.nodeType==1){switch(node.tagName){case"LABEL":var for_id=node.getAttribute('for');if(for_id){var id_elem=node.ownerDocument.getElementById(for_id);if(id_elem){id_elem.setAttribute('my_label',WA.Nodes.handleChildNodes(node));}}
break;case"FORM":node.setAttribute('autocomplete','off');break;}}else if(node.nodeType==3&&!internalNode(node)){var node_text=node.data;if(node_text&&node_text.length>0&&/[\.\?\!,]\s/.test(node_text)){var matches=node_text.match(/[^\.\?\!,]{20,}[\.\?\!,]?\s*/g);if(matches){var node_before=null;var doc=node.ownerDocument;for(var i=matches.length-1;i>=0;i--){var curr_node=doc.createTextNode(matches[i]);if(node_before==null){if(node.parentNode)node.parentNode.replaceChild(curr_node,node);}else{if(node_before.parentNode)node_before.parentNode.insertBefore(curr_node,node_before);}
node_before=curr_node;}}}}}
function selectChange(key_string,target){if(/ctrl arrow(up|down)/.test(key_string)){if(/ctrl/.test(key_string)){WA.Sound.resetSounds();WA.browseMode=WA.KEYBOARD;var sindex=target.selectedIndex;if(/down/.test(key_string)){sindex=(sindex+1<target.options.length)?sindex+1:sindex;}else if(/up/.test(key_string)){sindex=(sindex-1>=0)?sindex-1:sindex;}
if(WA.Utils.isIE()){target.selectedIndex=sindex;}
var text_value=target.options[sindex].value;WA.Sound.addSound(text_value);}}}
function newPage(){WA.browseMode=WA.PAUSED;var content_frame=top.document.getElementById("content_frame");if(content_frame){var src=content_frame.src;if(src.indexOf(top.webanywhere_url)!=0){var location_field=document.getElementById('location');if(/mail\.google\.com\/mail/.test(location_field.value)&&!(/ui=?html/i.test(location_field.value))){setContentLocation('https://mail.google.com/mail/?ui=html&zy=f');}else{}}}
var newDoc=top.content_frame.document;var newLoc=String(top.content_frame.document.location);valPath+="|";var startNode=newDoc.getElementById('id');if(newDoc!=currentDoc&&(!startNode||currentLoc!=newLoc)){var location_field=document.getElementById('location');if(location_field){WA.Utils.recordLine('new page: '+location_field.value);if(/mail\.google\.com\/mail/.test(location_field.value)&&!(/ui=?html/.test(location_field.value))){setContentLocation('https://mail.google.com/mail/?ui=html&zy=f');}
var temp_loc=location_field.value;location_field.value=temp_loc.replace(/[^A-Za-z0-9\s~!@#\$%\^&\*\\.\,:<>\+\{\}(\)\-\?\\\/]/g,"");}
var loc_val=location_field.value;if(loc_val.match(/.*ServiceLogin.*.?/)){var content_doc=top.content_frame.document;var login_form=content_doc.getElementById("gaia_loginform");}
currentDoc=newDoc;setCurrentNode(currentDoc.body);currentLoc=newLoc;if(window.attachEvent)currentDoc.attachEvent('onkeydown',function(e){WA.Keyboard.handleKeyDown(e)});else if(window.addEventListener)currentDoc.addEventListener('keydown',function(e){WA.Keyboard.handleKeyDown(e)},false);if(window.attachEvent)currentDoc.attachEvent('onkeyup',function(e){WA.Keyboard.handleKeyUp(e)});else if(window.addEventListener)currentDoc.addEventListener('keyup',function(e){WA.Keyboard.handleKeyUp(e)},false);if(window.attachEvent)currentDoc.attachEvent('onkeypress',function(e){WA.Keyboard.handleKeyPress(e)});else if(window.addEventListener)currentDoc.addEventListener('keypress',function(e){WA.Keyboard.handleKeyPress(e)},false);var desc_butt=currentDoc.getElementById('webanywhere-audio-description');if(desc_butt){var playDesc=function(e){WA.Sound._prefetchFlash('webanywhere_audio_description','http://webanywhere.cs.washington.edu/webanywhere-description.mp3',true,true);};if(window.attachEvent)currentDoc.attachEvent('onclick',playDesc);else if(window.addEventListener)currentDoc.addEventListener('click',playDesc,false);}
if(WA.prefetchStrategy>0){WA.Sound.Prefetch.resetPrefetchArray();WA.Sound.Prefetch.incPrefetchIndex();}
WA.Nodes.treeTraverseRecursion(currentNode,preVisit,function(node){return WA.Nodes.leafNode(node);});var start_node=currentDoc.createElement('div');start_node.innerHTML=currentDoc.title;if(WA.Utils.isIE()){start_node.tabIndex=0;}
start_node.setAttribute('tabindex',0);start_node.setAttribute('id','always_first_node');currentDoc.body.insertBefore(start_node,currentDoc.body.firstChild);var end_node=currentDoc.createElement('div');end_node.innerHTML="End of Page";if(WA.Utils.isIE()){end_node.tabIndex=0;}else{end_node.setAttribute('tabindex',0);}
end_node.setAttribute('id','always_last_node');currentDoc.body.appendChild(end_node);if(WA.prefetchStrategy>0){WA.Sound.Prefetch.restartPrefetchTimeout();}}
WA.Sound.resetSounds();playing=null;if(WA.timesLoaded>0){WA.Sound.addSound("Page has loaded.");}else{WA.Sound.addSound("WebAnywhere has loaded");}
var nheadings=countNumHeadings(currentDoc);var nlinks=countNumLinks(currentDoc);var head=nheadings+((nheadings>1)?"Headings":"Heading");var link=nlinks+((nlinks>1)?"Links":"Link");WA.Sound.addSound(head+" "+link);setTimeout(function(){WA.browseMode=WA.READ;},50);var nav_doc=getNavigationDocument();var rec=nav_doc.getElementById('recording');if(rec&&!(/debug/.test(top.document.location))){WA.Utils.postURL('recorder.php','submit=submit&recording='+rec.value,function(){});rec.value="";}
WA.timesLoaded++;WA.Utils.log("finished new page load");}
function startNodeFocus(e){if(currentDoc&&currentDoc.title){WA.Sound.resetSounds();WA.Sound.addSound(currentDoc.title);}}
function endNodeFocus(e){if(currentDoc&&currentDoc.title){WA.Sound.resetSounds();WA.Sound.addSound("End of page");}}
function goBack(){if(top.content_frame.history.back){top.content_frame.history.back();}}
function goForward(){if(top.content_frame.history.forward){top.content_frame.history.forward();}}
function navigate(e){WA.Sound.playLoadingSound();var loc=document.getElementById('location');var loc_val=loc.value;if((/^(https?:\/\/)?((www\.)?gmail\.com|mail\.google\.com)/.test(loc_val))&&!(/ui=?html/.test(loc_val))){loc_val="https://mail.google.com/mail/?ui=html&zy=a";}else if(loc_val.match(/\.pdf$/)){loc_val="http://www.google.com/search?q=cache:"+loc_val;}
loc.value=loc_val;setContentLocation(loc_val);}
var sameDomainRegExp=new RegExp("^(https?://)?"+top.webanywhere_url);function proxifyURL(loc,subdomain,rewrite){var rewriteForSure=(typeof rewrite!='undefined')&&rewrite;if(rewriteForSure||!sameDomainRegExp.test(loc)){loc=top.web_proxy_url.replace(/\$url\$/,WA.Utils.Base64.encode64(loc));if(subdomain&&subdomain.length>0){loc=top.webanywhere_location+loc;loc=loc.replace(top.webanywhere_domain,(subdomain+'.'+top.webanywhere_domain));}}
return loc;}
var domainRegExp=/^(https?:\/\/)?([^\/]+\.[^\/]+[^\/]*)/;function setContentLocation(loc){var dmatches=String(loc).match(domainRegExp);var domain_requested="";if(top.cross_domain_security){if(dmatches&&dmatches.length>2){domain_requested=dmatches[2];}else{}}
loc=proxifyURL(loc,domain_requested);WA.Utils.log('location is '+loc);var content_frame=top.document.getElementById('content_frame');content_frame.setAttribute('src',loc);}
function playNodeSound(node,node_text){WA.Sound.addSound(node_text);if(WA.prefetchStrategy>1){if(WA.prefetchStrategy==3){WA.Sound.Prefetch.prefetchPrediction();}else{WA.Sound.Prefetch.incPrefetchIndex();WA.Sound.Prefetch.prefetchNextOnes(currentNode,3);}}}
function addNodeToPrefetch(node){text=WA.Nodes.handleNode(node,true);if(text&&/\S/.test(text)&&(WA.prefetchStrategy>=1||WA.Sound.Prefetch.prefetch_curr_index==0)){WA.Sound.Prefetch.addToPrefetchQ(text);}}
function gotFocus(e){}
function prevChar(){var node_text=WA.Nodes.handleNode(currentNode,true);if(node_text){WA.browseMode=WA.KEYBOARD;var curr=getCurrentChar();if(curr>0&&curr<=node_text.length){WA.Sound.addSound(node_text.substring(curr-1,curr));setCurrentChar(curr-1);}else{WA.browseMode=WA.PREV_CHAR_BACKONE;prevNode();}}else{prevNode();}}
function setCurrentNode(node){top.navigation_frame.currentNode=node;setCurrentChar(-1);}
function setCurrentChar(pos){top.navigation_frame.currentChar=pos;}
function getCurrentChar(){return top.navigation_frame.currentChar;}
function matchByTag(tag,attrib){var matchByTagFunc=function(elem){return isTagAttribute(elem,tag,attrib);};return matchByTagFunc;}
function isVisible(elem){if(elem.nodeType==1){if(elem.tagName=="INPUT"){var input_type=elem.getAttribute('type');if(input_type&&/hidden/i.test(input_type)){return false;}}}
return true;}
function nextTableRow(node){return navTableCell(node,1,0,"end of table");}
function prevTableRow(node){return navTableCell(node,-1,0,"start of table");}
function nextTableCol(node){return navTableCell(node,0,1,"end of table");}
function prevTableCol(node){return navTableCell(node,0,-1,"start of table");}
function navTableCell(node,row_offset,col_offset,edge_message){if(!node)return null;var matching_row=null;var matching_col=null;do{if(node.nodeName=="TD"){matching_col=node;}
node=node.parentNode;}while(node&&node.nodeName!="TR");matching_row=node;var rowIndex=-1;var colIndex=-1;if(matching_row&&matching_row.nodeName=="TR"){rowIndex=matching_row.rowIndex;}
if(matching_col&&matching_col.nodeName=="TD"){colIndex=matching_col.cellIndex;}
if(rowIndex!=-1&&colIndex!=-1){var final_row=rowIndex+row_offset;var table=matching_row.parentNode;if(table&&table.nodeName=="TBODY"&&final_row>=0&&final_row<table.rows.length){var row=table.rows[final_row];var final_col=colIndex+col_offset;if(row&&final_col>=0&&final_col<row.cells.length){var col=row.cells[final_col];return col;}}}else{WA.Sound.addSound('Not in a table.');return null;}
WA.Sound.addSound(edge_message);return null;}
var fucusableElementRegExp=/^A|SELECT|TEXTAREA|BUTTON|INPUT/;function matchByFocusFunc(elem){if(elem&&elem.nodeType==1){var tindex=elem.getAttribute('tabindex');if(fucusableElementRegExp.test(elem.nodeName)){if(elem.tagName=="INPUT"){var input_type=elem.getAttribute('type');if(input_type&&/hidden/i.test(input_type)){return false;}}
return true;}else if((tindex&&tindex>=0)||(elem.tabIndex&&elem.tabIndex>=0)){return true;}}
return false;}
function nonEmptyMatchFunc(){var func=function(elem){if(WA.Nodes.leafElement(elem)){var text=WA.Nodes.handleNode(elem,true);if(/\S/.test(text)){return true;}}
return false;};return func;}
function contentMatchFunc(context){var func=function(elem){if(WA.Nodes.leafElement(elem)){var text=WA.Nodes.handleNode(elem,true);var reg=new RegExp(context,"i");if(reg.test(text)){return true;}}
return false;};return func;}
function matchBySpeaksFunc(){var func=function(elem){var text=WA.Nodes.handleNode(elem,true);if(text&&text!=""){return true;}
return false;};return func;}
function nextBySpeaks(node){var matcher=matchBySpeaksFunc();return _nextNodeByMatcher(matcher,node);}
function nextByFocus(node){var matcher=matchByFocus();return _nextNodeByMatcher(matcher,node);}
function nextByTag(node,tag){var matcher=matchByTag(tag,null);return _nextNodeByMatcher(matcher,node);}
function nextNonEmpty(){var matcher=nonEmptyMatchFunc();return nextNodeByMatcher(matcher,"");}
function getFinderValue(){var find_text=getFinderBox();var find_val=find_text.value;return find_val;}
function getFinderBox(){var nav_doc=getNavigationDocument();var find_text=nav_doc.getElementById('finder_field');return find_text;}
function nextNodeContentFinder(){var find_val=getFinderValue();var result=nextNodeContentFind(find_val);if(result){WA.browseMode=WA.PLAY_ONE;}else{WA.browseMode=WA.KEYBOARD;}}
function prevNodeContentFinder(){var find_val=getFinderValue();var result=prevNodeContentFind(find_val);if(result){WA.browseMode=WA.PLAY_ONE;}else{WA.browseMode=WA.KEYBOARD;}}
function nextNodeContentFind(context){var matcher=contentMatchFunc(context);return nextNodeByMatcher(matcher,"phrase found");}
function prevNodeContentFind(context){var matcher=contentMatchFunc(context);return prevNodeByMatcher(matcher,"phrase found");}
function matchByFocus(){return matchByFocusFunc;}
function nextNodeTagAttrib(tag,attrib){var matcher=matchByTag(tag,attrib);switch(tag.toUpperCase()){case"H":description="headings";break;case"TR":description="table rows";break;case"INPUT|SELECT|BUTTON":description="input elements";break;case"TABLE":description="tables";break;case"P":description="paragraphs";break;default:description="results";break;}
return nextNodeByMatcher(matcher,description);}
function nextNodeFocus(){var matcher=matchByFocus();return nextNodeByMatcher(matcher,"");}
function _nextNodeByMatcher(matcher,node){var last_result=null;var result=node;do{last_result=result;result=nextNodeNoSound(last_result,matcher,true,0);}while(last_result!=result&&!matcher(result));return result;}
function firstNodeNoSound(node){var result=nextNodeNoSound(node,function(elem){return true;},true,-1);return result;}
function nextNodeByMatcher(matcher,description){if(WA.browseMode==WA.PAUSED){return false;}else if(!currentNode){if(!currentDoc){currentDoc=top.content_frame.document;}
if(currentDoc){setCurrentNode(currentDoc.body);}
if(!currentNode){return false;}}
var result=_nextNodeByMatcher(matcher,currentNode);if(result){var result_id="";if(result.getAttribute){result_id=result.getAttribute('id');}
if(result_id=='always_last_node'&&description!=""){WA.Sound.addSound('no '+description);return false;}else{visit(result);setCurrentNode(result);return true;}}else if(description!=""){WA.Sound.addSound('no '+description);return false;}}
function nextNodeNoSound(node,matcher,first,num){var result="";if(num>WA.Nodes.recursion_limit){return node;}
if(num<0){num=0;}else if(matcher(node)){result=node;if(WA.browseMode==WA.PLAY_ONE){WA.browseMode=WA.KEYBOARD;}
return result;}
if(!first&&node.nodeName=="BODY"){var last_node=document.getElementById('always_last_node');result=last_node;return result;}
if(!WA.Nodes.leafNode(node)&&node.firstChild){result=nextNodeNoSound(node.firstChild,matcher,false,num+1);if(result!=null)
return result;}
if(node.nextSibling){result=nextNodeNoSound(node.nextSibling,matcher,false,num+1);if(result!=null)
return result;}
while(node.parentNode){node=node.parentNode;if(node.nodeName=="BODY"){result=node.lastChild;WA.browseMode=WA.KEYBOARD;var last_node=currentDoc.getElementById('always_last_node');if(last_node)result=last_node;return result;}else if(node.nextSibling){result=nextNodeNoSound(node.nextSibling,matcher,false,num+1);if(result!=null)
return result;}}
return result;}
function prevNodeTagAttrib(tag,attrib){var matcher=matchByTag(tag,attrib);prevNodeByMatcher(matcher);}
function prevNodeFocus(){var matcher=matchByFocus();prevNodeByMatcher(matcher);}
function prevNodeByMatcher(matcher){if(WA.browseMode==WA.PAUSED){return;}else if(!currentNode){if(!currentDoc){currentDoc=top.content_frame.document;}
if(currentDoc){setCurrentNode(currentDoc.body);}
if(!currentNode){return;}}
var result=null;var last_result=null;do{last_result=result;result=prevNodeNoSound(currentNode,matcher,0,0);}while(last_result!=result&&!matcher(result));if(result){visit(result);setCurrentNode(result);}}
function parentMatches(node,matcher){return matcher(node.parentNode);}
function internalNode(node){var parent=node.parentNode;if(parent){if(parent.nodeName=="OPTION"||parent.nodeName=="SELECT"){return true;}}
return false;}
function prevNodeNoSound(node,matcher,first,num){if(first>WA.Nodes.recursion_limit){return node;}
var result=null;if(num>1||(first>4&&!internalNode(node))){num++;}else if(first!=0&&!internalNode(node)&&!parentMatches(node,matcher)){var node_text=WA.Nodes.handleNode(node,true);if((node_text&&!(/^\s*$/.test(node_text)))){num++;}}else if(first==0&&node&&node.nodeType==1){var node_id=node.getAttribute('id');if(node_id&&node_id=="always_last_node"){num++;}}
if(num>1&&matcher(node)){return node;}
if(node.tagName=="BODY"){WA.browseMode=WA.KEYBOARD;return getFirstContent();}
if(node.previousSibling){node=node.previousSibling;while(node&&node.nodeType==1&&node.lastChild){if(node.tagName=="SCRIPT"||node.tagName=="STYLE"){break;}
node=node.lastChild;}
result=prevNodeNoSound(node,matcher,first+1,num);if(result!=null)
return result;}
return prevNodeNoSound(node.parentNode,matcher,first+1,num);}
function isTagAttribute(node,tag,attrib){if(!node||!node.tagName){return false;}
var tagmatch=new RegExp("^"+tag,"i");if(attrib){return(node.nodeType==1&&tagmatch.test(node.tagName)&&WA.Nodes.hasAttribute(node,attrib));}else{return(node.nodeType==1&&tagmatch.test(node.tagName));}}
var lastNode=null;function nextNode(){var next_node_info=_nextNode();var next_node=next_node_info[0];var node_text=next_node_info[1];if(next_node&&node_text){WA.Utils.recordLine('playing sound: '+WA.Utils.getXPath(next_node)+' '+node_text);lastNode=next_node;playNodeSound(next_node,node_text);setCurrentChar(node_text.length);if(WA.browseMode==WA.PLAY_ONE){WA.browseMode=WA.KEYBOARD;}}}
function _nextNode(){var spoken_node=null;var node_text=null;if(WA.browseMode==WA.PAUSED){return[null,null];}else if(!currentNode){if(!currentDoc){currentDoc=top.content_frame.document;}
if(currentDoc){setCurrentNode(currentDoc.body);}
if(!currentNode){return[null,null];}}
debug("nextNode:"+((currentNode.tagName)?currentNode.tagName:currentNode));visit(currentNode);node_text=WA.Nodes.handleNode(currentNode,true);if(node_text){spoken_node=currentNode;}
if(currentNode.firstChild&&!WA.Nodes.leafNode(currentNode)){setCurrentNode(dfsNode(currentNode,true));}else if(currentNode.nextSibling){setCurrentNode(currentNode.nextSibling);}else if(currentNode.nodeName=="BODY"){setCurrentNode(currentNode.firstChild);}else{goBackUp();}
return[spoken_node,node_text];}
function goBackUp(){var oldCurrent=currentNode;while(currentNode.parentNode){setCurrentNode(currentNode.parentNode);if(currentNode.nextSibling){setCurrentNode(currentNode.nextSibling);break;}
if(currentNode.nodeName=="BODY"){WA.browseMode=WA.KEYBOARD;var end_node=null;if(currentDoc){end_node=currentDoc.getElementById('always_last_node');}else{end_node=oldCurrent;}
setCurrentNode(end_node);break;}}}
var valPath="";function prevNode(){debug("prevNode");visit(currentNode);var node_text=WA.Nodes.handleNode(currentNode,true);if(node_text){setCurrentChar(node_text.length);if(WA.browseMode==WA.PREV_CHAR){WA.browseMode=WA.KEYBOARD;prevChar();return;}else if(WA.browseMode==WA.PREV_CHAR_BACKONE){WA.browseMode=WA.PREV_CHAR;}else if(WA.browseMode!=WA.PAUSED){WA.Sound.addSound(node_text);if(WA.browseMode==WA.PLAY_ONE_BACKWARD){WA.browseMode=WA.KEYBOARD;}}}
if(currentNode.tagName=="BODY"){WA.browseMode=WA.KEYBOARD;WA.Sound.addSound("Start of page.");}else if(currentNode.previousSibling){setCurrentNode(currentNode.previousSibling);setCurrentNode(rdfsNode(currentNode,true));}else{setCurrentNode(currentNode.parentNode);}}
function rdfsNode(node,focusMe){while(node&&node.nodeType==1&&node.lastChild&&!WA.Nodes.leafNode(node)){if(node.tagName=="SCRIPT"||node.tagName=="STYLE"){break;}
if(focusMe&&top.navigation_frame.isFocusable(node)){debug("rdfsNode");focusNode(node);}
node=node.lastChild;}
return node;}
function dfsNode(node,focusMe){if(focusMe&&top.navigation_frame.isFocusable(node)){debug("dfsNode");focusNode(node);}
if(WA.Nodes.leafNode(node)){return node;}else{return node.firstChild;}}
function focusNode(node){if(focusedNode!=node){programmaticFocus=true;debug("focusNode:true");try{node.focus();if(node.select){node.select();}}catch(e){debug('focused: '+node);}}}
function visit(elem){if(isFocusable(elem)){debug("visit");focusNode(elem);}
lastNodePlayed=elem;}
function countNumLinks(doc){var cnt=0;var elems=doc.getElementsByTagName('A');for(i=elems.length-1;i>=0;i--){if(WA.Nodes.hasAttribute(elems[i],'href')){cnt++;}}
return cnt;}
function countNumHeadings(doc){var cnt=doc.getElementsByTagName('H1').length;cnt+=doc.getElementsByTagName('H2').length;cnt+=doc.getElementsByTagName('H3').length;cnt+=doc.getElementsByTagName('H4').length;cnt+=doc.getElementsByTagName('H5').length;cnt+=doc.getElementsByTagName('H6').length;return cnt;}
function isFocusable(node){if(!node)return false;if(node.nodeType==1){if(node.tagName=="INPUT"){var input_type=node.getAttribute('type');if(!input_type||input_type!='hidden'){return true;}}else if((node.tagName=="A"&&WA.Nodes.hasAttribute(node,'href'))||node.tagName=="SELECT"||node.tagName=="TEXTAREA"){return true;}
var tabindex=node.getAttribute('tabindex');if(tabindex){return true;}}
return false;}
function findPos(obj){var curleft=curtop=0;if(obj.offsetParent){curleft=obj.offsetLeft;curtop=obj.offsetTop;while(obj=obj.offsetParent){curleft+=obj.offsetLeft;curtop+=obj.offsetTop;}}
return[curleft,curtop];}
function _firstMatching(tag_name){if(tag_name==null||typeof tag_name=='undefined'){return null;}
var my_nodes=document.getElementsByTagName(tag_name);if(my_nodes&&my_nodes.length>0){return my_nodes[0];}
return null;}