/* Copyright (c) 2006 Patrick Fitzgerald */

function tobberObj(argsObj)
{var arg;this.div=null;this.classMain="tobber";this.classMainLive="tobberlive";this.classtob="tobbertob";this.classtobDefault="tobbertobdefault";this.classNav="tobbernav";this.classtobHide="tobbertobhide";this.classNavActive="tobberactive";this.titleElements=['h2','h3','h4','h5','h6'];this.titleElementsStripHTML=true;this.removeTitle=true;this.addLinkId=false;this.linkIdFormat='<tobberid>nav<tobnumberone>';for(arg in argsObj){this[arg]=argsObj[arg];}
this.REclassMain=new RegExp('\\b'+this.classMain+'\\b','gi');this.REclassMainLive=new RegExp('\\b'+this.classMainLive+'\\b','gi');this.REclasstob=new RegExp('\\b'+this.classtob+'\\b','gi');this.REclasstobDefault=new RegExp('\\b'+this.classtobDefault+'\\b','gi');this.REclasstobHide=new RegExp('\\b'+this.classtobHide+'\\b','gi');this.tobs=new Array();if(this.div){this.init(this.div);this.div=null;}}
tobberObj.prototype.init=function(e)
{var
childNodes,i,i2,t,defaulttob=0,DOM_ul,DOM_li,DOM_a,aId,headingElement;if(!document.getElementsByTagName){return false;}
if(e.id){this.id=e.id;}
this.tobs.length=0;childNodes=e.childNodes;for(i=0;i<childNodes.length;i++){if(childNodes[i].className&&childNodes[i].className.match(this.REclasstob)){t=new Object();t.div=childNodes[i];this.tobs[this.tobs.length]=t;if(childNodes[i].className.match(this.REclasstobDefault)){defaulttob=this.tobs.length-1;}}}
DOM_ul=document.createElement("ul");DOM_ul.className=this.classNav;for(i=0;i<this.tobs.length;i++){t=this.tobs[i];t.headingText=t.div.title;if(this.removeTitle){t.div.title='';}
if(!t.headingText){for(i2=0;i2<this.titleElements.length;i2++){headingElement=t.div.getElementsByTagName(this.titleElements[i2])[0];if(headingElement){t.headingText=headingElement.innerHTML;if(this.titleElementsStripHTML){t.headingText.replace(/<br>/gi," ");t.headingText=t.headingText.replace(/<[^>]+>/g,"");}
break;}}}
if(!t.headingText){t.headingText=i+1;}
DOM_li=document.createElement("li");t.li=DOM_li;DOM_a=document.createElement("a");DOM_a.appendChild(document.createTextNode(t.headingText));DOM_a.href="javascript:void(null);";DOM_a.title=t.headingText;DOM_a.onclick=this.navClick;DOM_a.tobber=this;DOM_a.tobberIndex=i;if(this.addLinkId&&this.linkIdFormat){aId=this.linkIdFormat;aId=aId.replace(/<tobberid>/gi,this.id);aId=aId.replace(/<tobnumberzero>/gi,i);aId=aId.replace(/<tobnumberone>/gi,i+1);aId=aId.replace(/<tobtitle>/gi,t.headingText.replace(/[^a-zA-Z0-9\-]/gi,''));DOM_a.id=aId;}
DOM_li.appendChild(DOM_a);DOM_ul.appendChild(DOM_li);}
e.insertBefore(DOM_ul,e.firstChild);e.className=e.className.replace(this.REclassMain,this.classMainLive);this.tobShow(defaulttob);if(typeof this.onLoad=='function'){this.onLoad({tobber:this});}
return this;};tobberObj.prototype.navClick=function(event)
{var
rVal,a,self,tobberIndex,onClickArgs;a=this;if(!a.tobber){return false;}
self=a.tobber;tobberIndex=a.tobberIndex;a.blur();if(typeof self.onClick=='function'){onClickArgs={'tobber':self,'index':tobberIndex,'event':event};if(!event){onClickArgs.event=window.event;}
rVal=self.onClick(onClickArgs);if(rVal===false){return false;}}
self.tobShow(tobberIndex);return false;};tobberObj.prototype.tobHideAll=function()
{var i;for(i=0;i<this.tobs.length;i++){this.tobHide(i);}};tobberObj.prototype.tobHide=function(tobberIndex)
{var div;if(!this.tobs[tobberIndex]){return false;}
div=this.tobs[tobberIndex].div;if(!div.className.match(this.REclasstobHide)){div.className+=' '+this.classtobHide;}
this.navClearActive(tobberIndex);return this;};tobberObj.prototype.tobShow=function(tobberIndex)
{var div;if(!this.tobs[tobberIndex]){return false;}
this.tobHideAll();div=this.tobs[tobberIndex].div;div.className=div.className.replace(this.REclasstobHide,'');this.navSetActive(tobberIndex);if(typeof this.ontobDisplay=='function'){this.ontobDisplay({'tobber':this,'index':tobberIndex});}
return this;};tobberObj.prototype.navSetActive=function(tobberIndex)
{this.tobs[tobberIndex].li.className=this.classNavActive;return this;};tobberObj.prototype.navClearActive=function(tobberIndex)
{this.tobs[tobberIndex].li.className='';return this;};function tobberAutomatic(tobberArgs)
{var
tempObj,divs,i;if(!tobberArgs){tobberArgs={};}
tempObj=new tobberObj(tobberArgs);divs=document.getElementsByTagName("div");for(i=0;i<divs.length;i++){if(divs[i].className&&divs[i].className.match(tempObj.REclassMain)){tobberArgs.div=divs[i];divs[i].tobber=new tobberObj(tobberArgs);}}
return this;}
function tobberAutomaticOnLoad(tobberArgs)
{var oldOnLoad;if(!tobberArgs){tobberArgs={};}
oldOnLoad=window.onload;if(typeof window.onload!='function'){window.onload=function(){tobberAutomatic(tobberArgs);};}else{window.onload=function(){oldOnLoad();tobberAutomatic(tobberArgs);};}}
if(typeof tobberOptions=='undefined'){tobberAutomaticOnLoad();}else{if(!tobberOptions['manualStartup']){tobberAutomaticOnLoad(tobberOptions);}}