// Toolbar Object
// a toolbar with left/right and return button panel controls

// Copyright (C) 2000 Andreas Bauer based on DynAPI of Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynapi/

function Toolbar(x,y,vItems,nItems,itemwidth,activeItem,height,frame) {
	this.name="toolbar"+(Toolbar.count++)
	this.x=x
	this.y=y
	this.w=itemwidth*vItems
	this.h=height
	this.visible = false
	this.frame = frame || self
	this.itemw=itemwidth
	this.item=new Array
	this.item.length = nItems
	this.visibleItems = vItems
	this.currentItem = 0
	this.activeItem = activeItem
	this.currentVisible = 0
	this.obj=this.name+"Object"
	eval(this.obj+"=this")
}
{Toolbar.count=0
var p=Toolbar.prototype
p.setImages=ToolbarSetImages
p.add=ToolbarAddItem
p.build=ToolbarBuild
p.activate=ToolbarActivate
p.returnT = new Function()
p.moveleft=ToolbarLeft
p.moveright=ToolbarRight
p.moveTo=MoveTo
p.show=ToolbarShow
p.hide=ToolbarHide
p.showItem = ToolbarShowItem
p.setPanels=ToolbarSetPanels
}
function ToolbarSetImages(w,h,dir) {
	this.imageW = w
	this.imageH = h
	this.ireturn = new Image()
	this.ireturn.src = (dir||'')+'return.gif'
	this.ileft = new Image()
	this.ileft.src = (dir||'')+'fleche_g.gif'
	this.iright = new Image()
	this.iright.src = (dir||'')+'fleche_d.gif'
}
function ToolbarBuild() {
	this.css = css(this.name+'left',this.x-this.imageW,this.y,this.imageW,null,'#FFFFFF','hidden','15')
	this.css += css(this.name+'right',this.x+this.w,this.y,this.imageW,null,'#FFFFFF','hidden','15')
	this.css += css(this.name+'return',this.x-this.imageW*2,this.y,this.imageW,null,'#FFFFFF','hidden','15')
	this.css += css(this.name+'navDiv',this.x,this.y,this.w+this.imageW*3,null,'#FFFFFF','hidden','5')
	this.div =
	'<div id="'+this.name+'return"><a href="javascript:'+this.obj+'.returnT()"><img name="'+this.name+'Return" src="'+this.ireturn.src+'" border=0></a></div>'+
	'<div id="'+this.name+'left"><a href="javascript://" onMouseDown="'+this.obj+'.moveleft(); return false;"><img name="'+this.name+'Image0" src="'+this.ileft.src+'" border=0></a></div>'+
	'<div id="'+this.name+'right"><a href="javascript://" onMouseDown="'+this.obj+'.moveright(); return false;"><img name="'+this.name+'Image1" src="'+this.iright.src+'" border=0></a></div>'	+
	'<div id="'+this.name+'navDiv"><table width="'+(this.w+this.imageW*3)+'" cellpadding=0 cellspacing=0><tr><td><img src="../pict/blk.gif" width=2 height='+ (this.imageH)+' border=0 alt=""></td></tr><tr><td width="100%" bgcolor="#466A9F" height="1"><img src="../pict/blk.gif" width=2 height=1 border=0 alt=""></td></tr></table></div>'
}

function ToolbarAddItem(item) {
	this.item[this.currentItem] = item
	this.item[this.currentItem].moveTo(this.x+this.currentItem*this.itemw,this.y);
	this.currentItem++
}

function ToolbarActivate(x,y) {
	this.x = x
	this.y = y
	this.ileftlyr=new DynLayer(this.name+'left')
	this.irightlyr=new DynLayer(this.name+'right')
	this.ireturnlyr=new DynLayer(this.name+'return')
	this.background=new DynLayer(this.name+'navDiv')
	this.moveTo(x,y)
	if(this.visible) this.show()	
}
function ToolbarRight() {
	if(this.visibleItems < this.item.length && this.item.length > this.visibleItems+this.currentVisible) {	
		this.currentVisible++
		for(var i=0; i < this.item.length; i++) {
			this.item[i].moveBy(-this.itemw,null)
			if(i >= this.currentVisible && i < this.currentVisible+this.visibleItems)
				this.item[i].show()
			else
				this.item[i].hide()
		}
		this.ileftlyr.show()
		if(this.currentVisible+this.visibleItems == this.item.length) 
			this.irightlyr.hide()
	}
}
function ToolbarLeft() {
	if(this.currentVisible > 0 && this.visibleItems < this.item.length) {	
		this.currentVisible--
		for(var i=0; i < this.item.length; i++) {
			this.item[i].moveBy(this.itemw,null)		
			if(i >= this.currentVisible && i < this.currentVisible+this.visibleItems)
				this.item[i].show()
			else
				this.item[i].hide()
		}
		this.irightlyr.show()
		if(this.currentVisible == 0) 
			this.ileftlyr.hide()
	}

}

function MoveTo(x,y) {
	for(var i=0; i < this.item.length; i++) {
		this.item[i].moveTo(x+this.imageW*2+i*this.itemw,y)
	}
	this.ireturnlyr.moveTo(x,y)
	this.ileftlyr.moveTo(x+this.imageW,y)
	this.irightlyr.moveTo(x+this.w+this.imageW*2,y)
	if(b.isIE) 
		this.background.moveTo(x,y-1)
	else if(b.isNS)
		this.background.moveTo(x,y)
}

function ToolbarSetPanels(x,y) {
	this.show()	
}

function ToolbarShowItem(number) {
	if(this.item.length > 0 && number <this.item.length  && this.visible)
		while((this.item[number].css.visibility) == ((is.ns4)? "hide" : "hidden")) {
			this.moveright()
		}
}

function ToolbarShow() {
	this.visible = true
	for(var i=0; i < this.item.length; i++) {
		if(i >= this.currentVisible && i < this.currentVisible+this.visibleItems)
			this.item[i].show()
		else
			this.item[i].hide()
	}
	if(this.visibleItems < this.item.length && this.item.length > this.visibleItems+this.currentVisible)	
		this.irightlyr.show()
	if(this.currentVisible > 0 && this.visibleItems < this.item.length)
		this.ileftlyr.show()
	if(this.item.length > 0) {
		this.background.show()
		this.ireturnlyr.show()
	}
	else {
		this.background.hide()
		this.ireturnlyr.hide()
	}
	this.showItem(this.activeItem)
}

function ToolbarHide() {
	this.visible = false
	for(var i=0; i < this.item.length; i++) this.item[i].hide()
	this.irightlyr.hide()
	this.ileftlyr.hide()
	this.background.hide()
	this.ireturnlyr.hide()
}