/* ---------------------------------------------------------------- */
/*
/* toolbox.js
/* ~~~~~~~~~~~~~~~~~~~~~
/*   history(yyyy.mm.dd author remarks):
/*     2007.09.29 kaneko リニューアル
/*
/* (c) BRAINSYNC, INC.
/*
/* assigned vars:
/*
/* ---------------------------------------------------------------- */

	function ToolBox(instanceName){
		this.targetName   = null;
		this.instanceName = instanceName;
		this.sampleName   = this.instanceName + '_sample';
		this.colorPaletteImgSpacer = null;
		this.cPalette = null;
		this.clientHeight = null;

		this.targetElt = null;
		this.targetEltHeight = null;
		
		this._positionMove = true;
	}
	ToolBox.prototype.init = function(){
		this.targetElt = document.getElementById(this.targetName);
		this.targetEltHeight = this.targetElt.clientHeight;

		if(!this.targetEltHeight){
			this.targetEltHeight = this.targetElt.offsetHeight;
		}

	}

	ToolBox.prototype.getXpos = function(el){
		var xpos = 0;
		while(el.offsetParent) {
			xpos += el.offsetLeft;
			el = el.offsetParent;
		}
		return xpos;
	}
	ToolBox.prototype.getYpos = function(el){
		var ypos = 0;
		while(el.offsetParent) {
			ypos += el.offsetTop;
			el = el.offsetParent;
		}
		return ypos;
	}


	ToolBox.prototype.openImage = function() {
	    var p = window.open("upload_pop.php", "image", 'width=500,height=400,resizable=yes,scrollbars=yes');
	    p.focus();
	    return p;
	}

	ToolBox.prototype.textHeightSet = function(type){
		if (type == 'down'){
			this.targetEltHeight += 50;
		}else if (this.targetEltHeight > 150){
			this.targetEltHeight -= 50;
		}
		this.targetElt.style.height = this.targetEltHeight + 'px';
		return this.targetEltHeight;
	}

	ToolBox.prototype.togglePalette = function(paletteTarget, paletteButton){
		objTarget = document.getElementById(paletteTarget);
		if (objTarget.style.display=='none') {
			this.openPalette(paletteTarget, paletteButton);
		} else {
			this.closePalette(paletteTarget);
		}
	}

	ToolBox.prototype.openPalette = function(paletteTarget, paletteButton){
		objTarget = document.getElementById(paletteTarget);
		objTarget.style.display = 'block';
		objTarget.style.top = ( objTarget.offsetTop + this.getYpos(paletteButton) + paletteButton.offsetHeight - this.getYpos(objTarget)) + 'px';
		objTarget.style.left = ( objTarget.offsetLeft + this.getXpos(paletteButton) - this.getXpos(objTarget)) + 'px';
	}

	ToolBox.prototype.closePalette = function(paletteTarget){
		objTarget = document.getElementById(paletteTarget);
		objTarget.style.display = 'none';
	}
