/** 
 * this is a box that can change its size.
 */
function initBox (prefix) {
	if (this.content == null) this.content = '<img src="/' + prefix + 'img/spacer.gif" width="1" height="1">';
	if (this.styles == null) this.styles = 'background-color: #FFFFFF;';
	document.writeln ('<div id="morphBox' + this.id + '" name="morphBox' + this.id + '" style="position:absolute; left:' + this.start[0] + 'px; top:' + this.start[1] + 'px; width:' + (this.start[2] - this.start[0]) + 'px; height:' + (this.start[3] - this.start[1]) + 'px; z-index:' + (1000 + i) + '; visibility: hidden; ' + this.styles + '">' + this.content + '</div>');
	this.obj = findObj ('morphBox' + this.id);
	if (this.obj == null) whatNow (1000);
	if (this.obj.style) this.obj = this.obj.style;
}

function setStartCoordintes (x1, y1, x2, y2) {
	this.start = new Array (4);
	this.start[0] = x1;
	this.start[1] = y1;
	this.start[2] = x2;
	this.start[3] = y2;
}
function setDestinationCoordintes (x1, y1, x2, y2) {
	this.end = new Array (4);
	this.end[0] = x1;
	this.end[1] = y1;
	this.end[2] = x2;
	this.end[3] = y2;
}
function setSteps (s) { this.steps = s; }
function getSteps () { return this.steps; }
function show () {
	this.obj.visibility = 'visible';
	this.isVisible = true;
}
function hide () {
	this.obj.visibility = 'hidden';
	this.isVisible = false;
}

function morph () {
	if (this.steps <= 0) {
		this.setSteps (this.steps - 1);
		if (this.callback) setTimeout (this.callback, 0);
	}
	else {
		var d = new Array (4);
		for (i = 0; i < d.length; i++) d[i] = Math.ceil ((this.end[i] - this.start[i]) / this.steps);
		this.obj.left = this.start[0] = this.start[0] + d[0];
		this.obj.top = this.start[1] = this.start[1] + d[1];
		this.obj.width = this.start[2] - this.start[0] + d[2];
		this.obj.height = this.start[3] - this.start[1] + d[3];
		this.start[2] = this.start[2] + d[2];
		this.start[3] = this.start[3] + d[3];
		this.setSteps (this.steps - 1);
	}
}

function setCallback (callback) {
	this.callback = callback;
}

/** this is the object */
function MorphBox (id, styles, content) {
	this.id = id;
	this.styles = styles;
	this.content = content;
	this.isVisible = false;
	this.initBox = initBox;
	this.setStartCoordintes = setStartCoordintes;
	this.setDestinationCoordintes = setDestinationCoordintes;
	this.setSteps = setSteps;
	this.getSteps = getSteps;
	this.show = show;
	this.hide = hide;
	this.morph = morph;
	this.setCallback = setCallback;
}

