//
// Global bugButton management -- BBB (Bugimus Button)
//

bugBase.prototype.attachBBB = function() {
	this.BBBnum = 0
	this.BBBobj = new Array()
	this.BBB_NORMAL = 0
	this.BBB_HOVER = 1
	this.BBB_DOWN = 2
}
window.bugimus.attachBBB()

//
// Local bugButton functionality
//

// Define button object
function bugButton(refObj, normalImage, hoverImage, downImage, width, height) {
	this.objname = "window.bugimus.BBBobj[" + window.bugimus.BBBnum + "]"
	window.bugimus.BBBobj[window.bugimus.BBBnum++] = this

	this.buttonObj = document.createElement("IMG")
	this.buttonObj.id = this.objname
	this.buttonObj.alt = ""
	this.buttonObj.title = ""
	this.buttonObj.src = normalImage
	this.buttonObj.setx = setoX
	this.buttonObj.sety = setoY
	if(width) this.buttonObj.width = width
	if(height) this.buttonObj.height = height
	refObj.appendChild( this.buttonObj )

	// Define an imageSwapper for the mouseover effect
	this.bisOver = new imageSwapper(20)
	// Normal image is required
	this.bisOver.loadimage(normalImage)
	// If no hover use normal
	if (hoverImage) {
		this.bisOver.loadimage(hoverImage)
	} else {
		this.bisOver.loadimage(normalImage)
	}
	// If no down use normal
	if (downImage) {
		this.bisOver.loadimage(downImage)
	} else {
		this.bisOver.loadimage(normalImage)
	}

	this.buttonObj.onmouseout = this.buttonObj.onmouseup = function() {
		this.parentObj.bisOver.showimage(this.parentObj.objname, window.bugimus.BBB_NORMAL)
	}
	this.buttonObj.onmouseover = function() {
		this.parentObj.buttonObj.style.cursor = "pointer"
		this.parentObj.bisOver.showimage(this.parentObj.objname, window.bugimus.BBB_HOVER)
	}
	this.buttonObj.onmousedown = function() {
		this.parentObj.bisOver.showimage(this.parentObj.objname, window.bugimus.BBB_DOWN)
	}
	this.buttonObj.onmouseup = function() { 
		this.parentObj.bisOver.showimage(this.parentObj.objname, window.bugimus.BBB_NORMAL)
		// call external function for this event
		if(this.parentObj.externalCall) setTimeout(this.parentObj.externalCall, 0)
	}
	this.buttonObj.parentObj = this

}

bugButton.prototype.setCallFunc = function(funcname) { 
	this.externalCall = funcname
}

bugButton.prototype.setTitle = function(text) { 
	this.buttonObj.title = text
}


