//
// Global bugObjectSlider management -- BOS (Bugimus Object Slider)
//

bugBase.prototype.attachBOS = function() {
	this.BOSnum = 0
	this.BOSobj = new Array()
}
window.bugimus.attachBOS()

//
// Local bugObjectSlider functionality
//

// Define object slider object
function objectSlider(refObj, xinit, yinit, winit, hinit, orientation) {
	this.objname = "window.bugimus.BOSobj[" + window.bugimus.BOSnum + "]"
	window.bugimus.BOSobj[window.bugimus.BOSnum++] = this

	this.hx=xinit
	this.hy=yinit
	this.hw=winit
	this.hh=hinit
	this.currentObj=0
	this.gap=0 // spacer for all buttons
	this.leftEdge=0 // left most position not including left nav button
	this.rightEdge=0 // right most position including right nav button
	this.maxpix=0 // this will grow with each object added, if you want to limit
	              // this size then you must reset this value after each addObj call

	// ------------------------------------------------------------
	// Create container div appended to body.
	refObj.appendChild(this.objectSliderObj=document.createElement("DIV"))

	this.objectSliderObj.getx = getoX
	this.objectSliderObj.getx = getoX
	this.objectSliderObj.gety = getoY
	this.objectSliderObj.setx = setoX
	this.objectSliderObj.sety = setoY
	this.objectSliderObj.getw = getoWidth
	this.objectSliderObj.geth = getoHeight
	this.objectSliderObj.setw = setoWidth
	this.objectSliderObj.seth = setoHeight
	this.objectSliderObj.clip = clipoDiv
	this.objectSliderObj.warp = warpoTo

	with(this.objectSliderObj.style) {
		position="absolute"
		left=this.hx+"px"
		top=this.hy+"px"
		width=this.hw+"px"
		height=this.hh+"px"
//	border="solid 1px #33f"
//	backgroundColor="#ddf" 
		overflow="hidden"
	}

	// Create two buttons to navigate the objectSlider.
/*
	bI1 = "bugButton-normal.gif"
	bI2 = "bugButton-hover.gif"
	bI3 = "bugButton-down.gif"

	this.leftObj = new bugButton(this.objectSliderObj, bI1, bI2, bI3)
	with(this.leftObj.buttonObj.style) {
		position="absolute"
		left=0+"px"
		top=0+"px"
		zIndex=1
	}
	this.leftEdge = this.leftObj.buttonObj.width + this.gap   // XBZR issue?
	this.leftObj.setCallFunc( this.objname+".goLeft()" )

	this.rightObj = new bugButton(this.objectSliderObj, bI1, bI2, bI3)
	this.rightEdge = this.objectSliderObj.getw() - this.rightObj.buttonObj.width +"px"    // XBZR issue?
	with(this.rightObj.buttonObj.style) {
		position="absolute"
		left= this.rightEdge
		top=0+"px"
		zIndex=1
	}
	this.rightObj.setCallFunc( this.objname+".goRight()" )
*/
	// Create a stripSlider object on the objectSlider main container.
	this.stripSliderObj = new stripSlider(this.objectSliderObj, 0, 0, orientation)
	this.stripSliderObj.stripObj.setz(0)
	this.stripSliderObj.stripObj.getw = getoWidth
	this.stripSliderObj.stripObj.geth = getoHeight

//	with (this.stripSliderObj) {
//		sweetspot=0
//		a=200
//		s=50
//		decay=10
//		fade=false        // fade on/off
//		pixgap=5          // default
//		pixwidth=100      // default
//		pixheight=100     // default
//		sweetspot=300     // default
//	}

	this.setFade(true)
	this.setSweetSpot(this.leftEdge)
	this.setGap(this.gap)
	this.setA(200)
	this.setS(50)
// Default background to white so it's easily seen and debugged
//	pObj.stripObj.style.backgroundColor = "fff"
//	pObj.stripObj.style.backgroundColor = "transparent"


}

//-----------------------------------------------------------------
objectSlider.prototype.addObj = function(newObj, objWidth, objHeight) { 

	pObj = this.stripSliderObj
	// Create each new object on the strip.
	this.stripSliderObj.stripObj.appendChild(pObj.pixObj[pObj.numpix]=document.createElement("DIV"))
	pObj.pixObj[pObj.numpix].id="P"+pObj.numpix
	pObj.pixObj[pObj.numpix].getx = getoX
	pObj.pixObj[pObj.numpix].gety = getoY
	pObj.pixObj[pObj.numpix].setopacity = setoOpacity
	pObj.pixObj[pObj.numpix].appendChild(newObj)
	with(pObj.pixObj[pObj.numpix].style) {
		position="absolute"
		width=objWidth+"px"      // IE5 and IE6 are at variance here.
		height=objHeight+"px"     // IE5 and IE6 are at variance here.
		if(pObj.orientation=="h") {
			top=pObj.pixgap+"px"
			left=(objWidth*pObj.numpix)+(pObj.pixgap*(pObj.numpix+1))+"px"
		} else {
			top=(objHeight*pObj.numpix)+(pObj.pixgap*(pObj.numpix+1))+"px"
			left=pObj.pixgap+"px"
		}
		border=pObj.imgborder
		filter="alpha(opacity=100)" 
	}

	pObj.numpix++
	this.maxpix++
	if(pObj.orientation=="h") {
		pObj.stripObj.setw(pObj.numpix*(objWidth+pObj.pixgap)+pObj.pixgap)
		pObj.stripObj.seth(objHeight+2*pObj.pixgap)
//b		this.objectSliderObj.setw(this.leftObj.buttonObj.width+this.rightObj.buttonObj.width+pObj.stripObj.getw()+this.gap)
		this.objectSliderObj.seth(objHeight+2*this.gap)
		pObj.stripObj.warp(pObj.sweetspot,0)
		
		if(this.rightObj)this.rightObj.buttonObj.setx(this.objectSliderObj.getw()-this.rightObj.buttonObj.width)
	} else {
		pObj.stripObj.seth(pObj.numpix*(objHeight+pObj.pixgap)+pObj.pixgap)
		pObj.stripObj.setw(objWidth+2*pObj.pixgap)
		this.objectSliderObj.setw(objWidth+2*this.gap)
//b		this.objectSliderObj.seth(this.leftObj.buttonObj.height+this.rightObj.buttonObj.height+pObj.stripObj.geth()+this.gap)
		pObj.stripObj.warp(0,pObj.sweetspot)
		
		this.rightObj.buttonObj.sety(this.objectSliderObj.geth()-this.rightObj.buttonObj.height)
		
	}

	
//this.rightEdge = this.objectSliderObj.geth() - this.rightObj.buttonObj.height +"px"    // XBZR issue?
//this.rightObj.buttonObj.style.top=this.rightEdge

	if(this.gap>0)pObj.stripObj.style.backgroundColor = "fff"
	if(pObj.fade)pObj.doAlpha()
}

//-----------------------------------------------------------------
objectSlider.prototype.goLeft = function() {
	if( this.stripSliderObj.active == false  && this.currentObj < this.maxpix && this.currentObj < this.stripSliderObj.numpix-1 ) {
		this.stripSliderObj.gotoPic(++this.currentObj)
	}
}

//-----------------------------------------------------------------
objectSlider.prototype.goRight = function() { 
	if( this.stripSliderObj.active == false  && this.currentObj > 0 ) {
		this.stripSliderObj.gotoPic(--this.currentObj)
	}
}

//-----------------------------------------------------------------
objectSlider.prototype.gotoObj = function(which) {
	if( which < 0 ) {
		this.currentObj = 0
	} else if( which >= this.stripSliderObj.numpix ) {
		this.currentObj = this.stripSliderObj.numpix-1
	}
	this.stripSliderObj.gotoPic(which)
}

//-----------------------------------------------------------------
objectSlider.prototype.setSweetSpot = function(val) { 
	this.stripSliderObj.sweetspot = val + this.leftEdge
}
//-----------------------------------------------------------------
objectSlider.prototype.getSweetSpot = function() { 
	return this.stripSliderObj.sweetspot
}
//-----------------------------------------------------------------
objectSlider.prototype.setA = function(val) { 
	this.stripSliderObj.a = val
}
//-----------------------------------------------------------------
objectSlider.prototype.setS = function(val) { 
	this.stripSliderObj.s = val
}
//-----------------------------------------------------------------
objectSlider.prototype.setDecay = function(val) { 
	this.stripSliderObj.decay = val
}
//-----------------------------------------------------------------
objectSlider.prototype.setFade = function(val) { 
	this.stripSliderObj.fade = val
}
//-----------------------------------------------------------------
objectSlider.prototype.setGap = function(val) { 
	this.gap = val
	this.stripSliderObj.pixgap = val
}
//-----------------------------------------------------------------
objectSlider.prototype.setMaxPix = function(val) { 
	this.maxpix = val
}
//-----------------------------------------------------------------
objectSlider.prototype.attachLeftButton = function(btnObj) { 
	this.leftObj = btnObj
	this.objectSliderObj.appendChild(this.leftObj.buttonObj)
	this.leftObj.buttonObj.style.position="absolute"
	this.leftObj.buttonObj.style.zIndex=1
	this.leftObj.buttonObj.style.left=0+"px"
	this.leftObj.buttonObj.style.top=0+"px"
	if(this.stripSliderObj.orientation=="h") {
		this.leftEdge = this.leftObj.buttonObj.width + this.gap
//b		this.objectSliderObj.setw(this.leftEdge)
		this.objectSliderObj.seth(this.leftObj.buttonObj.height + this.gap)
	} else {
		// In vertical mode left becomes top
		this.leftEdge = this.leftObj.buttonObj.height + this.gap
		this.objectSliderObj.setw(this.leftObj.buttonObj.width + this.gap)
//b		this.objectSliderObj.seth(this.leftEdge)
	}
	this.leftObj.setCallFunc( this.objname+".goLeft()" )
	this.setSweetSpot(this.gap)
}
//-----------------------------------------------------------------
objectSlider.prototype.attachRightButton = function(btnObj) { 
	this.rightObj = btnObj
	this.objectSliderObj.appendChild(this.rightObj.buttonObj)
 	this.rightObj.buttonObj.style.position="absolute"
	this.rightObj.buttonObj.style.zIndex=1
	if(this.stripSliderObj.orientation=="h") {
		this.rightEdge = this.leftEdge + this.objectSliderObj.getw() - this.rightObj.buttonObj.width
		this.rightObj.buttonObj.style.left=this.rightEdge
		this.rightObj.buttonObj.style.top=0+"px"
//b		this.objectSliderObj.setw(this.rightEdge + this.rightObj.buttonObj.width)
		this.objectSliderObj.seth(this.rightObj.buttonObj.height + this.gap)
	} else {
		// In vertical mode right becomes bottom
		this.rightEdge = this.leftEdge + this.objectSliderObj.geth() - this.rightObj.buttonObj.height
		this.rightObj.buttonObj.style.left=0+"px"
		this.rightObj.buttonObj.style.top=this.rightEdge
		this.objectSliderObj.setw(this.rightObj.buttonObj.width + this.gap)
//b		this.objectSliderObj.seth(this.rightEdge + this.rightObj.buttonObj.height)
	}
	this.rightObj.setCallFunc( this.objname+".goRight()" )
}


