// ScrollPane Object
// a widget that draws layers that are to be scrolled, being built for a new Scroll Object
// Copyright (C) 2000 DynAPI of Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynapi/
/* improved by Andreas Bauer 2000/20001 */

function ScrollPane(x,y,width,height,imageDir,frame,name,nestLayer) {
	this.name=(name!=null)? name : "ScrollPane"+(ScrollPane.count++)
	this.x=x
	this.y=y
	this.w=width
	this.h=height
	this.topBorderH = 6
	this.scrollActive = false
	this.isScrolling = false
	this.btnHeight = 15
	this.borderWidth = 1
	this.imageLocation = (imageDir) ? imageDir : "picts"
	this.nestref = (nestLayer) ? nestLayer : null	
	this.frame=((is.ie || is.ns5) && frame!=null)? window.top.frames[frame] : parent
	this.obj=this.name+"Object"
	eval(this.obj+"=this")
	this.setMargins=ScrollPaneSetMargins
	this.setMargins(0,0,0,0)	
}
{var p=ScrollPane.prototype
p.usebuffer=true
p.inlineBlocks=0
p.inc=15
p.speed=60
p.border=0
p.borderColor='black'
p.bgColor=null
p.build=ScrollPaneBuild
p.activate=ScrollPaneActivate
p.up=ScrollPaneUp
p.down=ScrollPaneDown
p.stop=ScrollPaneStop
p.getXfactor=ScrollPaneGetXfactor
p.getYfactor=ScrollPaneGetYfactor
p.load=ScrollPaneLoad
p.reload=ScrollPaneReload
p.moveTo=ScrollPaneMoveTo
p.show=ScrollPaneShow
p.hide=ScrollPaneHide
p.writeContent=ScrollPaneWriteContent
p.showBlock=ScrollPaneShowBlock
p.history=new Array()
p.historyLoc=-1
p.historyLen=-1
p.updateMarker=ScrollPaneUpdateMarkerPosition
p.onScroll=new Function()
p.scrollTo=ScrollPaneScrollTo
p.scrollIt=ScrollPaneScrollIt
p.onLoad=new Function()
p.mouseUp=DragmouseUp
p.mouseMove=DragmouseMove
p.mouseDown=DragmouseDown

}
function ScrollPaneSetMargins(l,r,t,b) {
	this.marginL=l
	this.marginR=r
	this.marginT=t
	this.marginB=b
}
function ScrollPaneBuild() {
	var w=this.w
	var h=this.h
	var b=this.border
	var bc=this.borderColor
	var ml=this.marginL
	var mr=this.marginR
	var mt=this.marginT
	var mb=this.marginB
	this.css=css(this.name,this.x,this.y,w,h,null,null,null,'overflow:hidden')+
	css(this.name+'Screen',b,b,w-2*b,h-2*b,this.bgColor,'hidden') 
	if (this.border>0) this.css+=css(this.name+'BorderT',0,0,w,b,bc)+css(this.name+'BorderB',0,h-b,w,b,bc)+css(this.name+'BorderL',0,0,b,h,bc)+css(this.name+'BorderR',w-b,0,b,h,bc)
	if (this.inlineBlocks) {
		this.css+=css(this.name+'Content',0,0,w-2*b,null)
		this.css+=css(this.name+'Block0',ml,mt,w-2*b-ml-mr,null,this.bgColor)
		for (var i=1;i<this.inlineBlocks;i++) {
			this.css+=css(this.name+'Block'+i,ml,mt,w-2*b-ml-mr,null,this.bgColor,'hidden')
		}
	}
	else this.css+=css(this.name+'Content',ml,mt,w-2*b-ml-mr)
	this.css+=css(this.name+'scrollbar',this.x+this.w,this.y-this.borderWidth,this.btnHeight,null,null,'hidden','1')
	this.css+=css(this.name+'scrollTop',this.x,this.y-17-this.topBorderH,this.w,null,null,'hidden','5')
	this.css+=css(this.name+'scrollBottom',this.x,this.y+this.h-1,this.w,null,null,'hidden')
	this.css+=css(this.name+'scrollmarker',this.x+this.w,this.y+this.btnHeight,14,null,null,'hidden','16')
	
	this.divStart=((is.ie || is.ns5) && this.usebuffer)? '<iframe name="'+this.name+'Frame" width=0 height=0 style="position:absolute; left:0; top:0; visibility:hidden"></iframe>\n':''
	this.divStart+='<div id="'+this.name+'">'+'<div id="'+this.name+'Screen">'
	if ((is.ie || is.ns5) && !this.usebuffer) this.divStart+='<iframe name="'+this.name+'Frame" width='+(this.w-2*b-ml-mr)+' height='+(this.h-2*b)+' marginwidth=0 marginheight=0 scrolling="no" frameborder="no"></iframe>\n'
	else this.divStart+='<div id="'+this.name+'Content">'
	this.divEnd='</div>'
	if ((is.ns && !is.ns5) || this.usebuffer) this.divEnd+='</div>'
	if (this.border>0) this.divEnd+='<div id="'+this.name+'BorderT"></div><div id="'+this.name+'BorderB"></div><div id="'+this.name+'BorderL"></div><div id="'+this.name+'BorderR"></div>\n'
	this.divEnd+='</div>\n'
	this.divScrollbar='<div id="'+this.name+'scrollbar"><table cellpadding=0 cellspacing=0 border=0 width=15 height='+this.h+' bgcolor="#9C9A9C"><tr><td height="15"><a href="javascript://" '
	this.divScrollbar+='onMouseDown="' + this.obj + '.up(); return false" '
	this.divScrollbar+='onMouseUp="' + this.obj + '.stop()" '
	this.divScrollbar+='onMouseOut="' + this.obj + '.stop()" '
	this.divScrollbar+='onMouseOver="' + this.obj + '.up(); return false"><img src="'+this.imageLocation+'scrollup.gif" width="15" height="15" border="0"></a></td></tr>'
	this.divScrollbar+='<tr><td height="'+(this.h-28)+'"><img src="'+this.imageLocation+'space.gif" width="15" height="'+(this.h-28)+'" border="0"></td></tr>'
	this.divScrollbar+='<tr><td height="15"><a href="javascript://" '
	this.divScrollbar+='onMouseDown="' + this.obj + '.down(); return false" '
	this.divScrollbar+='onMouseUp="' + this.obj + '.stop()" '
	this.divScrollbar+='onMouseOut="' + this.obj + '.stop()" '
	this.divScrollbar+='onMouseOver="' + this.obj + '.down(); return false"><img src="'+this.imageLocation+'scrlldown.gif" width="15" height="15" border="0"></a></td></tr></table></div>'
	this.divScrollbar+='<div id="'+this.name+'scrollmarker"><img src="'+this.imageLocation+'marker.gif" width=15 height=16 border=0 alt=""></div>\n'
	this.divScrollBorder='<div id="'+this.name+'scrollTop"><table cellpadding=0 cellspacing=0 border=0 width="'+this.w+'"><tr><td width="16" valign="top"><img src="'+this.imageLocation+'cadrelt.gif" width="16" height="16" border="0" alt=""></td><td bgcolor="'+this.bgColor+'" width="'+(this.w-32)+'"><img src="'+this.imageLocation+'space.gif" width="1" height="1" border="0" alt=""></td><td width="16" align="right" valign="top"><img src="'+this.imageLocation+'cadrert.gif" width="16" height="16" border="0" alt=""></td></tr><tr><td colspan="3" bgcolor="'+this.bgColor+'" height="'+this.topBorderH+'"><img src="'+this.imageLocation+'space.gif" width="1" height="'+this.topBorderH+'" border="0" alt=""></td></tr></table></div>\n'
	this.divScrollBorder+='<div id="'+this.name+'scrollBottom"><table width="'+this.w+'" cellpadding="0" cellspacing="0" border="0"><tr><td width="16" valign="bottom"><img src="'+this.imageLocation+'cadrelb.gif" width="16" height="16" border="0" alt=""></td><td bgcolor="'+this.bgColor+'" width="'+(this.w-32)+'"><img src="'+this.imageLocation+'space.gif" width="1" height="1" border="0" alt=""></td><td align="right" valign="bottom" width="16"><img src="'+this.imageLocation+'cadrerb.gif" width="16" height="16" border="0" alt=""></td></tr></table></div>\n'
	this.div=this.divStart
	this.div+=this.divEnd
	this.div+=this.divScrollbar
	this.div+=this.divScrollBorder	
	
	
	/*var w=this.w
	var h=this.h
	var b=this.border
	var bc=this.borderColor
	var ml=this.marginL
	var mr=this.marginR
	var mt=this.marginT
	var mb=this.marginB
	this.css=css(this.name,this.x,this.y,w,h,null,null,null,'overflow:hidden')+
	css(this.name+'Screen',b,b,w-2*b,h-2*b,this.bgColor,'hidden') 
	if (this.border>0) this.css+=css(this.name+'BorderT',0,0,w,b,bc)+css(this.name+'BorderB',0,h-b,w,b,bc)+css(this.name+'BorderL',0,0,b,h,bc)+css(this.name+'BorderR',w-b,0,b,h,bc)
	if (this.inlineBlocks) {
		this.css+=css(this.name+'Content',0,0,w-2*b,null)
		this.css+=css(this.name+'Block0',ml,mt,w-2*b-ml-mr,null,this.bgColor)
		for (var i=1;i<this.inlineBlocks;i++) {
			this.css+=css(this.name+'Block'+i,ml,mt,w-2*b-ml-mr,null,this.bgColor,'hidden')
		}
	}
	else this.css+=css(this.name+'Content',ml,mt,w-2*b-ml-mr)
	this.css+=css(this.name+'scrollbar',this.x+this.w,this.y-this.borderWidth,this.btnHeight,null,null,'hidden','1')
	this.css+=css(this.name+'scrollBorder',this.x-this.borderWidth,this.y-1,1,null,null,'hidden','1')
	this.css+=css(this.name+'scrollTop',this.x,this.y-this.borderWidth,this.w,null,null,'hidden','1')
	this.css+=css(this.name+'scrollBottom',this.x,this.y+this.h,this.w,null,null,'hidden','1')
	this.css+=css(this.name+'scrollmarker',this.x+this.w,this.y+this.btnHeight,14,null,null,'hidden','6')
	
	this.divStart=((is.ie || is.ns5) && this.usebuffer)? '<iframe name="'+this.name+'Frame" width=0 height=0 style="position:absolute; left:0; top:0; visibility:hidden"></iframe>\n':''
	this.divStart+='<div id="'+this.name+'">'+'<div id="'+this.name+'Screen">'
	if ((is.ie || is.ns5) && !this.usebuffer) this.divStart+='<iframe name="'+this.name+'Frame" width='+(this.w-2*b-ml-mr)+' height='+(this.h-2*b)+' marginwidth=0 marginheight=0 scrolling="no" frameborder="no"></iframe>\n'
	else this.divStart+='<div id="'+this.name+'Content">'
	this.divEnd='</div>'
	if ((is.ns && !is.ns5) || this.usebuffer) this.divEnd+='</div>'
	if (this.border>0) this.divEnd+='<div id="'+this.name+'BorderT"></div><div id="'+this.name+'BorderB"></div><div id="'+this.name+'BorderL"></div><div id="'+this.name+'BorderR"></div>\n'
	this.divEnd+='</div>\n'
	this.divScrollbar='<div id="'+this.name+'scrollbar"><table cellpadding=0 cellspacing=0 border=0 width=14 height='+(this.h+2*this.borderWidth)+'><tr><td height="'+this.btnHeight+'"><a href="javascript://" '
	this.divScrollbar+='onMouseDown="' + this.obj + '.up(); return false" '
	this.divScrollbar+='onMouseUp="' + this.obj + '.stop()" '
	this.divScrollbar+='onMouseOut="' + this.obj + '.stop()" '
	this.divScrollbar+='onMouseOver="' + this.obj + '.up(); return false"><img src="'+this.imageLocation+'scrlup.gif" width="14" height="'+this.btnHeight+'" border="0"></a></td></tr>'
	this.divScrollbar+='<tr><td height="'+(this.h-2*this.btnHeight)+'"><img src="'+this.imageLocation+'scrlfond.gif" width="14" height="'+(this.h-2*this.btnHeight+2*this.borderWidth)+'" border="0"></td></tr>'
	this.divScrollbar+='<tr><td height="'+this.btnHeight+'"><a href="javascript://" '
	this.divScrollbar+='onMouseDown="' + this.obj + '.down(); return false" '
	this.divScrollbar+='onMouseUp="' + this.obj + '.stop()" '
	this.divScrollbar+='onMouseOut="' + this.obj + '.stop()" '
	this.divScrollbar+='onMouseOver="' + this.obj + '.down(); return false"><img src="'+this.imageLocation+'scrldown.gif" width="14" height="'+this.btnHeight+'" border="0"></a></td></tr></table></div>'
	this.divScrollbar+='<div id="'+this.name+'scrollmarker"><img src="'+this.imageLocation+'scrlmark.gif" width="14" height="14" border=0 alt=""></div>\n'
	this.divScrollBorder='<div id="'+this.name+'scrollBorder"><img src="'+this.imageLocation+'scrlbord.gif" width=1 height='+(this.h+2)+' border=0 alt=""></div>\n'
	
	this.divScrollBorder+='<div id="'+this.name+'scrollTop"><table cellpadding=0 cellspacing=0 border=0 width="'+this.w+'">'
	this.divScrollBorder+='<tr><td><img src="'+this.imageLocation+'scrlhori.gif" width=38 height=1 border=0 alt=""></td>'
	this.divScrollBorder+='<td width="'+(this.w-76)+'"><img src="'+this.imageLocation+'space.gif" width=1 height=1 border=0 alt=""></td>'
	this.divScrollBorder+='<td><img src="'+this.imageLocation+'scrlhori.gif" width=38 height=1 border=0 alt=""></td></tr></table></div>\n'
	this.divScrollBorder+='<div id="'+this.name+'scrollBottom"><table cellpadding=0 cellspacing=0 border=0 width="'+this.w+'">'
	this.divScrollBorder+='<tr><td><img src="'+this.imageLocation+'scrlhori.gif" width=38 height=1 border=0 alt=""></td>'
	this.divScrollBorder+='<td width="'+(this.w-76)+'"><img src="'+this.imageLocation+'space.gif" width=1 height=1 border=0 alt=""></td>'
	this.divScrollBorder+='<td><img src="'+this.imageLocation+'scrlhori.gif" width=38 height=1 border=0 alt=""></td></tr></table></div>\n'
	
	this.div=this.divStart
	this.div+=this.divEnd
	this.div+=this.divScrollbar
	this.div+=this.divScrollBorder	*/
}
function ScrollPaneActivate(w,h) {
	if (!this.activated) {
		this.lyr=new DynLayer(this.name)
		this.screenlyr=new DynLayer(this.name+'Screen')
		this.screenlyr.show()  
		this.blocklyr=new Array()
		this.blockActive=0
	}
	if (this.inlineBlocks) {
		DynLayerInit()
		for (var i=0;i<this.inlineBlocks;i++) this.blocklyr[i]=new DynLayer(this.name+'Block'+i)
	}
	if ((is.ie || is.ns5) && this.usebuffer && this.frame.frames[this.name+'Frame'].document.body.innerHTML) {
		if(is.ie) document.all[this.name+'Content'].innerHTML=this.frame.frames[this.name+'Frame'].document.body.innerHTML
		else document.getElementById(this.name+'Content').innerHTML=this.frame.frames[this.name+'Frame'].document.body.innerHTML
	}
	if (this.inlineBlocks) {
		this.contentlyr=this.blocklyr[this.blockActive]
	}
	else if ((is.ie || is.ns5) && !this.usebuffer) 
			this.contentlyr=new DynLayer('content',null,this.frame.frames[this.name+'Frame'])
		else 
			this.contentlyr=new DynLayer(this.name+'Content')
	var c=this.contentlyr
	c.onSlide=new Function(this.obj+'.onScroll()')
	this.contentHeight = h || ((is.ns)? ((is.ns5) ? c.h : c.doc.height) : c.elm.scrollHeight)
	this.contentWidth = w || ((is.ns)? ((is.ns5) ? c.w : c.doc.width) : c.elm.scrollWidth)
	if (is.ns && !is.ns5) {
		c.css.clip.bottom=Math.max(this.contentHeight,this.h)
		c.css.clip.right=Math.max(this.contentWidth,this.w)
	}
	this.offsetHeight=this.contentHeight+this.marginT+this.marginB-this.screenlyr.h
	this.offsetWidth=this.contentWidth+this.marginL+this.marginR-this.screenlyr.w
	this.enableVScroll=(this.offsetHeight>0)
	this.enableHScroll=(this.offsetWidth>0)
	this.scrollbar 		= new DynLayer(this.name+'scrollbar')
	//this.scrollBorder 	= new DynLayer(this.name+'scrollBorder')
	this.scrollBorderBottom = new DynLayer(this.name+'scrollBottom')
	this.scrollBorderTop = new DynLayer(this.name+'scrollTop')
	this.scrollMarker 	= new DynLayer(this.name+'scrollmarker')
	this.scrollMarker.moveTo(this.x+this.w,this.y+this.btnHeight-this.borderWidth)
	this.show()
	this.onScroll()
	this.onLoad()
	this.activated=true
	drag.add(this.scrollMarker)
}
function ScrollPaneMoveTo(x,y) {
	this.x = x
	this.y = y
	this.lyr=new DynLayer(this.name)
	this.scrollbar 		= new DynLayer(this.name+'scrollbar')
	//this.scrollBorder 	= new DynLayer(this.name+'scrollBorder')
	this.scrollBorderBottom = new DynLayer(this.name+'scrollBottom')
	this.scrollBorderTop = new DynLayer(this.name+'scrollTop')	
	this.scrollMarker 	= new DynLayer(this.name+'scrollmarker')
	this.lyr.moveTo(this.x,this.y-this.borderWidth)
	this.scrollbar.moveTo(this.x+this.w,this.y-this.borderWidth)
	//this.scrollBorder.moveTo(this.x-this.borderWidth,this.y-this.borderWidth)
	//this.scrollBorderTop.moveTo(this.x,this.y-this.borderWidth)
	this.scrollBorderTop.moveTo(this.x,this.y-17-this.topBorderH)
	this.scrollBorderBottom.moveTo(this.x,this.y+this.h-this.borderWidth)
	this.scrollMarker.moveTo(this.x+this.w,this.y+this.btnHeight-this.borderWidth)
}
function ScrollPaneHide() {
	this.lyr.hide()
	this.contentlyr.hide()
	this.scrollbar.hide()
	//this.scrollBorder.hide()
	this.scrollBorderTop.hide()
	this.scrollBorderBottom.hide()
	this.scrollMarker.hide()
}
function ScrollPaneShow() {
	this.lyr.show()
	this.contentlyr.show()
	this.scrollbar.show()
	//this.scrollBorder.show()
	this.scrollBorderTop.show()
	this.scrollBorderBottom.show()
	this.scrollMarker.show()
}
function ScrollPaneLoad(url) {
	if (url != this.url) {
	this.historyLoc+=1
	this.historyLen=this.historyLoc
	this.history[this.historyLen]=url
	}
	this.reload(0)
}
function ScrollPaneReload(i) {
	this.historyLoc+=i
	this.url=this.history[this.historyLoc]
	this.refresh=true
	this.contentlyr=new DynLayer(this.name+'Content')
	this.contentlyr.moveTo(this.marginL,this.marginT)
	if (is.ns && !is.ns5) {
		if (this.inlineBlocks) this.contentlyr.elm.load(this.url,this.w-2*this.border)
		else this.contentlyr.elm.load(this.url,this.w-2*this.border-this.marginL-this.marginR)
	}
	else this.frame.frames[this.name+'Frame'].document.location=this.url
}
function ScrollPaneUp() {
	if (this.enableVScroll) {
		if(this.contentlyr.y < this.marginT)	{
			this.contentlyr.moveBy(0,this.inc)
			this.isScrolling = window.setTimeout(this.obj+'.up()',this.speed)
			this.updateMarker()
		}		
	}
}
function ScrollPaneDown() {
	if (this.enableVScroll) {
		if(this.contentlyr.y > -this.offsetHeight+this.marginT)	{
			this.contentlyr.moveBy(0,-this.inc)
			this.isScrolling = window.setTimeout(this.obj+'.down()',this.speed)
			this.updateMarker()
		}
	}
}
function ScrollPaneStop() {
	if (this.activated) {
		if(this.isScrolling) window.clearTimeout(this.isScrolling)		
	}
}
function ScrollPaneGetXfactor() {
	if (this.offsetWidth==0) return 0
	return Math.min(((this.offsetWidth-this.contentlyr.x+this.marginL)/this.offsetWidth)-1,1)
}
function ScrollPaneGetYfactor() {
	if (this.offsetHeight==0) return 0
	return Math.min(((this.offsetHeight-(this.contentlyr.y)+this.marginT)/this.offsetHeight)-1,1)
}
function ScrollPaneWriteContent(doc) {
	if (is.ie || is.ns5) doc.write(css('content',0,0,this.w-2*this.window.border))
}
function ScrollPaneShowBlock(i,fn) {
	if (this.blockActive!=i) {
	this.blockActive=i
	this.contentlyr.moveTo(this.marginL,this.marginT)
	this.contentlyr.hide()
	this.blocklyr[i].css.visibility='inherit'
	this.activate()
	eval(fn)
	}
}
function ScrollPaneUpdateMarkerPosition() {
	this.scrollbar.y = this.y
	var newpos = this.scrollbar.y + (this.getYfactor()*(this.scrollbar.h-2*this.btnHeight))
	if(newpos < (this.scrollbar.y+this.btnHeight)) newpos = this.scrollbar.y +this.btnHeight
	if(this.scrollMarker)
		this.scrollMarker.moveTo(this.scrollbar.x, newpos)	
}

function ScrollPaneScrollTo(pos,correct) {
	if(this.scrollMarker)	{		
		//if(this.scrollActive) {
			this.scrollbar.y = this.y
			if((pos-correct) >= (this.scrollbar.y+this.btnHeight) && (pos-correct) <=(this.scrollbar.y+this.scrollbar.h-2*this.btnHeight)) {
				var incrY = (pos-correct-this.scrollbar.y-this.btnHeight)/(this.scrollbar.h-44)*this.offsetHeight-this.marginT
				this.scrollMarker.moveTo(this.scrollbar.x, pos-correct)
				this.contentlyr.moveTo(this.contentlyr.x, -incrY)
			}
		}
}

function ScrollPaneScrollIt() {
	this.scrollActive = !this.scrollActive
}

ScrollPane.count=0

function DragmouseDown(e) {
	if ((is.ns && e.which!=1) || (is.ie && event.button!=1)) return true
	var yInset = (hScrollPane.nestref) ? eval(hScrollPane.nestref+'.y') : 0
	var xInset = (hScrollPane.nestref) ? eval(hScrollPane.nestref+'.x') : 0
	var x = (is.ns)? e.pageX-xInset: event.x+document.body.scrollLeft-xInset
	var y = (is.ns)? e.pageY-yInset : event.y+document.body.scrollTop-yInset
	if (drag.mouseDown(x,y)) {
		return false
	}
	else return true
}

function DragmouseMove(e) {
	if (hScrollPane.activated){
		if (hScrollPane.enableVScroll) {	
			var yInset = (hScrollPane.nestref) ? eval(hScrollPane.nestref+'.y') : 0
			var x = (hScrollPane.scrollbar.x)
			var y = (is.ns)? e.pageY-yInset : event.y+document.body.scrollTop-yInset 
			if((y) >= (hScrollPane.scrollbar.y+hScrollPane.btnHeight) && (y) <=(hScrollPane.scrollbar.y+hScrollPane.scrollbar.h-2*hScrollPane.btnHeight)) {
				if (drag.mouseMove(x,y)) {
					hScrollPane.scrollTo(y,0)
					return false
				}
				else return true
			}
			else{
				return (is.ns)
			}
		}
	}
}
function DragmouseUp(e) {
	var yInset = (hScrollPane.nestref) ? eval(hScrollPane.nestref+'.y') : 0
	var xInset = (hScrollPane.nestref) ? eval(hScrollPane.nestref+'.x') : 0
	var x = (is.ns)? e.pageX-xInset: event.x+document.body.scrollLeft-xInset
	var y = (is.ns)? e.pageY-yInset : event.y+document.body.scrollTop-yInset
	if (drag.mouseUp(x,y)) {
		return false
	}
	else return true
}

finished = true
finishcount = 0
function finish() {
	finishcount++
	if (finishcount==36) {
		finished = true
		finishcount = 0
	}
}