/*

  DHTML SCROLLER v4.0beta (c) 2001-2003 Angus Turnbull. All Rights Reserved.
  Visit http://www.twinhelix.com for licensing info and more scripts!

*/

var isDOM=document.getElementById?1:0;
var isIE=document.all?1:0;
var isNS4=navigator.appName=='Netscape'&&!isDOM?1:0;
var isIE4=isIE&&!isDOM?1:0;
var isOp=window.opera?1:0;
var isDyn=isDOM||isIE||isNS4;
function getRef(id,par)
{
par=!par?document:(par.navigator?par.document:par);
return isIE?par.all[id]:
(isDOM?(par.getElementById?par:par.ownerDocument).getElementById(id):
(isNS4?par.layers[id]:null));
}
function getSty(id,par)
{
var r=getRef(id,par);
return r?(isNS4?r:r.style):null;
}
if(!window.LayerObj)var LayerObj=new Function('id','par',
'this.ref=getRef(id,par);this.sty=getSty(id,par);return this');
function getLyr(id,par){return new LayerObj(id,par)}
function LyrFn(fn,fc)
{
LayerObj.prototype[fn]=new Function('var a=arguments,p=a[0],px=isNS4||isOp?0:"px";'+
'with(this){'+fc+'}');
}
LyrFn('x','if(!isNaN(p))sty.left=p+px;else return parseInt(sty.left)');
LyrFn('y','if(!isNaN(p))sty.top=p+px;else return parseInt(sty.top)');
LyrFn('w','if(p)(isNS4?sty.clip:sty).width=p+px;'+
'else return(isNS4?ref.document.width:ref.offsetWidth)');
LyrFn('h','if(p)(isNS4?sty.clip:sty).height=p+px;'+
'else return(isNS4?ref.document.height:ref.offsetHeight)');
LyrFn('vis','sty.visibility=p');
LyrFn('clip','if(isNS4)with(sty.clip){left=a[0];top=a[1];right=a[2];bottom=a[3]}'+
'else sty.clip="rect("+a[1]+"px "+a[2]+"px "+a[3]+"px "+a[0]+"px)" ');
if(!window.page)var page={win:window,minW:0,minH:0,MS:isIE&&!isOp,
db:document.compatMode&&document.compatMode.indexOf('CSS')>-1?'documentElement':'body'}
page.winW=function()
{with(this)return Math.max(minW,MS?win.document[db].clientWidth:win.innerWidth)}
page.winH=function()
{with(this)return Math.max(minH,MS?win.document[db].clientHeight:win.innerHeight)}
page.scrollY=function()
{with(this)return MS?win.document[db].scrollTop:win.pageYOffset}
page.elmPos=function(e,p)
{
var x=0,y=0,w=p?p:this.win;
e=e?(e.substr?(isNS4?w.document.anchors[e]:getRef(e,w)):e):p;
if(isNS4){if(e&&(e!=p)){x=e.x;y=e.y};if(p){x+=p.pageX;y+=p.pageY}}
else while(e){x+=e.offsetLeft;y+=e.offsetTop;e=e.offsetParent}
return{x:x,y:y};
}
function addProps(obj,data,names,addNull)
{
for(var i=0;i<names.length;i++)if(i<data.length||addNull)obj[names[i]]=data[i];
}
function ScrDiv()
{
addProps(this,arguments,['id','x','y','w','h','v','par','lyr'],true);
}
function DHTMLScroller()
{
var names=['myName','loadingFile','loadedFile','bookmark','bufRef','div','bar','thm',
'loaded','timer','divHeight','thmHeight','barHeight','cHeight','cWidth','dragOffset',
'onbeforeload','onload','onscroll','onsetup','onlayout','onthumbdown','onthumbup',
'loadHack'];
addProps(this,arguments,names,true);
this.cTop=0;
this.history=new Array();
this.histPos=-1;
this.divs=new Array();
this.minThmHeight=20;
this.maxThmHeight=9999;
this.padTop=this.padBot=0;
this.checkBounds=true;
this.ySpeed=this.stepsLeft=0;
this.stick=1;
this.stickTop=0;
DHTMLScroller.list[this.myName]=this;
}
DHTMLScroller.list=[];
var activeScr=null;
with(DHTMLScroller)
{
prototype.load=function(fName){with(this)
{
if(!fName||!loaded||!isDyn)return;
if(fName.match(/^(.*)#(.*)$/))with(RegExp)
{
bookmark=$2;
if(!$1||($1==loadedFile))return fileLoaded(false);
fName=$1;
}
else bookmark='';
loadingFile=fName;
if(onbeforeload)onbeforeload();
if(fName!=history[histPos])
{
histPos++;
history[histPos]=fName;
history.length=histPos+1;
}
if(isOp&&!document.documentElement)return fileLoaded(false);
if(isIE||isDOM)with(isOp?getRef(myName+'Buf').contentDocument:bufRef.document)
{
if(!loadHack)
{
write('<html><body onload="setTimeout(\'parent.'+myName+'.fileLoaded(true)\',50)">'+
'<iframe name="nestBuf" src="'+fName+'"></iframe></body></html>');
close();
}
if(loadHack||!bufRef.nestBuf||(isIE4&&!window.external))
{
bufRef.location.href=fName;
setTimeout(myName+'.fileLoaded(true)',5000);
}
}
else if(isNS4)
{
if(window.ns4LayerLoading)
{
setTimeout(myName+'.load("'+fName+'")',100);
return;
}
window.ns4LayerLoading=true;
div.ref.onload=new Function(myName+'.fileLoaded(true)');
div.ref.load(fName,eval(divs[0].w));
}
}}
prototype.fileLoaded=function(doSwap){with(this)
{
activeScr=null;
if(isNS4)window.ns4LayerLoading=false;
if((isDOM||isIE)&&loadingFile&&doSwap)
{
var bufDoc=bufRef.nestBuf?bufRef.nestBuf.document:bufRef.document;
if(bufDoc&&bufDoc.body)div.ref.innerHTML=bufDoc.body.innerHTML;
bufRef.location.replace('about:blank');
}
loadedFile=loadingFile;
var newPos=bookmark?page.elmPos(bookmark,div.ref).y-page.elmPos(null,div.ref).y:0;
setTimeout('with('+myName+'){layout();scrollTo('+newPos+');if(onload)onload()}',1);
}}
prototype.go=function(dir){with(this)
{
histPos+=dir;
if(histPos<0){histPos=0;return}
if(histPos>=history.length){histPos=history.length-1;return}
load(history[histPos]);
}}
prototype.scrollTo=function(pos,isStick){with(this)
{
if(!isDyn||!loaded)return;
cTop=pos;
if(!isStick)stickTop=cTop;
divHeight=div.h()+padTop+padBot;
if(divHeight==0)divHeight=1;
if(checkBounds)
{
if(cTop+cHeight>divHeight)cTop=divHeight-cHeight;
if(cTop<0)cTop=0;
}
div.y(0-cTop+padTop);
thmHeight=Math.ceil(barHeight*(cHeight/divHeight));
with(Math)thmHeight=min(barHeight,min(maxThmHeight,max(thmHeight,minThmHeight)));
thm.h(thmHeight);
if(onscroll)onscroll();
if(activeScr||isStick)return;
var fracDivDown=(cTop/(divHeight-cHeight));
thm.y(bar.y()+fracDivDown*(barHeight-thmHeight));
}}
prototype.scrollBy=function(amount){with(this)
{
scrollTo(cTop+amount);
}}
prototype.setScroll=function(newSpeed,steps){with(this)
{
if(!loaded)return;
stepsLeft=steps;
if(timer)clearInterval(timer);
timer=setInterval('with('+myName+'){'+
'if(stepsLeft>0){ySpeed+='+((newSpeed-ySpeed)/steps)+';stepsLeft--}'+
'else if(parseInt(ySpeed)==0){clearInterval(timer);timer=null}scrollBy(ySpeed)}',50);
}}
prototype.thumbDown=function(evt){with(this)
{
var evt=evt?evt:window.event;
activeScr=this;
dragOffset=(isNS4?evt.pageY:page.scrollY()+evt.clientY)-thm.y();
if(onthumbdown)onthumbdown();
if(timer)clearInterval(timer);
timer=null;
return false;
}}
window.scrThumbMove=function(evt)
{
var evt=evt?evt:window.event;
if(!activeScr)return true;
else with(activeScr)
{
if((cTop+cHeight>divHeight)||(thmHeight==barHeight))return true;
var thmTop=(isNS4?evt.pageY:page.scrollY()+evt.clientY)-dragOffset-bar.y();
if(thmTop<0)thmTop=0;
if(thmTop+thmHeight>barHeight)thmTop=barHeight-thmHeight;
thm.y(bar.y()+thmTop);
stickTop=(divHeight-cHeight)*(thmTop/(barHeight-thmHeight));
if(stick==1)scrollTo(stickTop);
else if(!timer)timer=setInterval(myName+'.stickScroll()',40);
return false;
}
}
window.scrThumbUp=function(evt)
{
if(activeScr)with(activeScr)if(onthumbup)onthumbup();
activeScr=null;
}
prototype.stickScroll=function(){with(this)
{
if(Math.abs(cTop-stickTop)>1)
{
cTop+=(stickTop-cTop)*stick;
scrollTo(cTop,true);
}
else if(cTop!=stickTop)
{
cTop=stickTop;
scrollTo(cTop,true);
}
}}
prototype.barClick=function(evt){with(this)
{
var evt=evt?evt:window.event;
clickPos=isNS4?evt.pageY:page.scrollY()+evt.clientY;
var thmY=page.elmPos(null,thm.ref).y;
if(clickPos<thmY)scrollBy(0-cHeight);
if(clickPos>(thmY+thmHeight))scrollBy(cHeight);
if(isNS4)return document.routeEvent(evt);
}}
prototype.layout=function(){with(this)
{
if(!isDyn||!loaded)return;
barHeight=eval(divs[1].h);
cWidth=eval(divs[0].w);
cHeight=eval(divs[0].h);
var isSmall=(div.h()<cHeight);
for(var i=0;i<divs.length;i++)with(divs[i].lyr)
{
x(eval(divs[i].x));w(Math.max(0,eval(divs[i].w)));
y(eval(divs[i].y));h(Math.max(0,eval(divs[i].h)));
if(divs[i].v)vis(divs[i].v==1&&isSmall?'hidden':'visible');
}
divs[0].lyr.clip(0,0,cWidth,cHeight);
div.vis('visible');
div.w(cWidth);
if(onlayout)onlayout();
scrollBy(0);
}}
prototype.setup=function(){with(this)
{
if(!isDyn)return;
for(var i=0;i<divs.length;i++)with(divs[i])
{
par=eval(par);
lyr=getLyr(id,par);
}
div=getLyr(divs[0].id+'Inner',isNS4?divs[0].lyr.ref:null);
bar=divs[1].lyr;
thm=divs[2].lyr;
if(!isNS4)bufRef=eval('window.'+myName+'Buf');
if(isNS4)
{
bar.ref.captureEvents(Event.CLICK);
thm.ref.captureEvents(Event.MOUSEDOWN);
}
bar.ref.onclick=new Function('evt','return '+myName+'.barClick(evt)');
thm.ref.onmousedown=new Function('evt','return '+myName+'.thumbDown(evt)');
thm.ref.ondragstart=new Function('return false');
var fileName=''
var URL=location.search.substring(1);
if(URL)
{
URL=URL.split('&');
for(var i=0;i<URL.length;i++)
if(URL[i].split('=')[0]==myName)fileName=unescape(URL[i].split('=')[1]);
}
if(onsetup)onsetup();
loaded=true;
if(fileName)load(fileName);
else if(loadingFile)load(loadingFile);
else fileLoaded();
}}
}
var scrOL=window.onload,scrOR=window.onresize,nsWinW=window.innerWidth,nsWinH=window.innerHeight;
document.scrMM=document.onmousemove;
document.scrMU=document.onmouseup;
var DSL=DHTMLScroller.list;
window.onload=function()
{
if(scrOL)scrOL();
for(var s in DSL)DSL[s].setup();
}
window.onresize=function()
{
if(scrOR)scrOR();
if(isNS4&&(nsWinW!=innerWidth||nsWinH!=innerHeight))
{
var fileName=location.href,fileArr=[];
if(fileName.indexOf('?')!=-1)fileName=fileName.substring(0,fileName.indexOf('?'));
for(var s in DSL)fileArr[fileArr.length]=s+'='+DSL[s].loadedFile;
location.href=fileName+'?'+fileArr.join('&');
}
for(var s in DSL)DSL[s].layout();
}
if(isNS4)document.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
document.onmousemove=function(evt)
{
var ret1=scrThumbMove(evt),ret2=(document.scrMM?document.scrMM(evt):1);
return(ret1?(isNS4&&!document.scrMM?document.routeEvent(evt):ret2):false);
}
document.onmouseup=function(evt)
{
scrThumbUp(evt);
return document.scrMU?document.scrMU(evt):(isNS4?document.routeEvent(evt):true);
}
document.onselectstart=document.onselect=function()
{
if(activeScr)return false;
}
