//
// Global bugSlideRule management -- BSR (Bugimus Slide Rule)
//

bugBase.prototype.attachBSR = function() {
	this.BSRnum = 0
	this.BSRobj = new Array()
}
window.bugimus.attachBSR()

//
// Local bugSlideRule functionality
//

// Define slide rule object
function slideRule( refObj, xinit, yinit,
                    lowerbaseimg, upperbaseimg,
					lowerbarimg, upperbarimg,
					lowerbrace, upperbrace ) {

	this.objname = "window.bugimus.BSRobj[" + window.bugimus.BSRnum + "]"
	window.bugimus.BSRobj[window.bugimus.BSRnum++] = this

	this.hx=xinit
	this.hy=yinit
	this.gap=5 // spacer for all buttons

	this.mWidth = 700
	this.mHeight = 400
	this.sWidth = 100
	this.sHeight = this.mHeight
	this.uWidth = this.mWidth
	this.uHeight = 15
	this.lWidth = this.mWidth
	this.lHeight = 15
	this.cWidth = this.sWidth
	this.cHeight = 15

	// create lowerBase
	refObj.appendChild(this.lowerBaseObj=document.createElement("DIV"))
	with(this.lowerBaseObj.style) {
		position="absolute"
		left=this.hx+"px"
		top=this.hy+"px"
		width=this.mWidth+"px"
		height=this.mHeight+"px"
		border="solid 1px #c00"
		backgroundColor="#fcc" 
		overflow="hidden"
		zIndex=0
	}
	imgString = "<img src='"+lowerbaseimg+"'"+" alt='' />"
	this.lowerBaseObj.appendChild(document.createElement(imgString))

	// create upperBase
	refObj.appendChild(this.upperBaseObj=document.createElement("DIV"))
	with(this.upperBaseObj.style) {
		position="absolute"
		left=this.hx+"px"
		top=this.hy+"px"
		width=this.mWidth+"px"
		height=this.mHeight+"px"
		border="solid 1px #000"
		backgroundColor="#ccc" 
		overflow="hidden"
		zIndex=5
	}
	imgString = "<img src='"+upperbaseimg+"'"+" alt='' />"
	this.upperBaseObj.appendChild(document.createElement(imgString))
	this.upperBaseObj.clip = clipoDiv
	this.upperBaseObj.clip(this.uHeight+this.gap, this.sWidth, this.sHeight-this.lHeight-2*this.gap, 0)

	// create upperBar
	refObj.appendChild(this.upperBarObj=document.createElement("DIV"))
	with(this.upperBarObj.style) {
		position="absolute"
		left=this.hx+5*this.gap+"px"
		top=this.hy+this.gap+"px"
		width=this.uWidth+"px"
		height=this.uHeight+"px"
		border="solid 1px #600"
		backgroundColor="#ccf" 
		overflow="hidden"
		zIndex=10
	}

	// create lowerBar
	refObj.appendChild(this.lowerBarObj=document.createElement("DIV"))
	with(this.lowerBarObj.style) {
		position="absolute"
		left=this.hx+5*this.gap+"px"
		top=this.hy+this.mHeight-this.lHeight-this.gap+"px"
		width=this.lWidth+"px"
		height=this.lHeight+"px"
		border="solid 1px #600"
		backgroundColor="#ccf" 
		overflow="hidden"
		zIndex=10
	}

	// create slider to hold upper and lower braces and define
	// clipping region
	this.sliderObj = new dragComponent(refObj, this.hx, this.hy, this.sWidth, this.sHeight)
	this.sliderObj.setCallFunc(this.objname+".clipIt()")

	this.sliderObj.dragObject.setz(100)

	// create upperBrace
	this.sliderObj.dragObject.appendChild(this.upperBraceObj=document.createElement("DIV"))
	with(this.upperBraceObj.style) {
		position="absolute"
		left=0+"px"
		top=0+"px"
		width=this.cWidth+"px"
		height=this.cHeight+"px"
		border="solid 0px #600"
		backgroundColor="#cfc" 
		overflow="hidden"
		zIndex=15
	}
	this.upperBraceObj.parentObj = this
	this.upperBraceObj.onmouseover = function() {
		this.parentObj.upperBraceObj.style.cursor = "e-resize"
	}

	// create lowerBrace
	this.sliderObj.dragObject.appendChild(this.lowerBraceObj=document.createElement("DIV"))
	with(this.lowerBraceObj.style) {
		position="absolute"
		left=0+"px"
		top=this.sHeight-this.cHeight+"px"
		width=this.cWidth+"px"
		height=this.cHeight+"px"
		border="solid 0px #600"
		backgroundColor="#cfc" 
		overflow="hidden"
		zIndex=15
	}
	this.lowerBraceObj.parentObj = this
	this.lowerBraceObj.onmouseover = function() {
		this.parentObj.lowerBraceObj.style.cursor = "e-resize"
	}
}

//-----------------------------------------------------------------
slideRule.prototype.clipIt = function() { 
	hoffset = this.sliderObj.dragObject.getx() - this.hx
	this.upperBaseObj.clip(this.uHeight, this.sWidth+hoffset, this.sHeight-this.lHeight, hoffset)
}
//-----------------------------------------------------------------
slideRule.prototype.setGap = function(val) { 
	this.stripSliderObj.pixgap = val
}
//-----------------------------------------------------------------
slideRule.prototype.constrainX = function(val) { 
	this.sliderObj.constrainX = val
}
//-----------------------------------------------------------------
slideRule.prototype.constrainY = function(val) { 
	this.sliderObj.constrainY = val
}

