
function DialogBox(id,width,height)
{
	this.id = id;
	this.width = width;
	this.height = height;
	this.object = document.getElementById(id);
	if(! this.object) { alert("mauvaise boite"); return; }
	this.object.style.zIndex = 0;
	this.selected = false;
	this.rapport = 1;
	this.isOpen = false;
}

function debug(msg)
{
	debugDiv = document.getElementById('debug');
	if(debugDiv) debugDiv.innerHTML = msg;
}
DialogBox.prototype.setSize = function(w,h)
{
	if (! this.isOpen) return;
	this.width = w;
	this.height = h;
}
DialogBox.prototype.close = function()
{
	if (! this.isOpen) return;
	this.doClose(10);
}
DialogBox.prototype.open = function(x,y)
{
	if (this.isOpen) return;
	this.isOpen = true;
	this.moveTo(x,y);
	this.doOpen(0);
}
DialogBox.prototype.getCoord = function(index)
{
	var coords = new Array (
		{"dx":10,"dy":10,"rate":0},
		{"dx":10,"dy":10,"rate":0.1},
		{"dx":10,"dy":10,"rate":0.2},
		{"dx":10,"dy":10,"rate":0.3},
		{"dx":10,"dy":10,"rate":0.4},
		{"dx":10,"dy":10,"rate":0.5},
		{"dx":10,"dy":10,"rate":0.6},
		{"dx":10,"dy":10,"rate":0.7},
		{"dx":10,"dy":10,"rate":0.8},
		{"dx":10,"dy":10,"rate":0.9},
		{"dx":10,"dy":10,"rate":1}
	);
	if (index >= coords.length || index < 0) return null;
	return coords[index];
}
DialogBox.prototype.doClose = function(index)
{
	var coord = this.getCoord(index);
	if(! coord) {
		this.object.style.display = "none";
		this.isOpen = false;
		return;
	}
	this.moveBy(coord.dy,coord.dy);
	this.display(coord.rate);
	var localThis = this;
	setTimeout(function(){ localThis.doClose(index-1);},50);
}
DialogBox.prototype.doOpen = function(index)
{
	var coord = this.getCoord(index);
	if(! coord) return;
	this.object.style.display = "block";
	this.object.style.zIndex = "1";
	this.moveBy(coord.dy,coord.dy);
	this.display(coord.rate);
	var localThis = this;
	setTimeout(function(){ localThis.doOpen(index+1);},50);
}
DialogBox.prototype.display = function(rate)
{
	this.object.style.top = this.top+"px";
	this.object.style.left = this.left+"px";
	this.object.style.visibility = "visible";
	this.object.style.width = (this.width*rate)+"px";
	this.object.style.height = (this.height*rate)+"px";
	this.object.style.fontSize = rate+"em";
}
DialogBox.prototype.select = function(y, x)
{
	this.color_deselect = this.object.style.backgroundColor;
	this.object.style.borderWidth= "2px";
	this.x_select = x;
	this.y_select = y;
	this.selected = true;
	this.object.style.zIndex++;
}
DialogBox.prototype.deselect = function()
{
	this.object.style.borderWidth= "1px";
	this.selected = false;
	this.object.style.zIndex--;
}
DialogBox.prototype.moveTo = function(top,left)
{
	this.top = top;
	this.left = left;
}
DialogBox.prototype.moveBy = function(dy,dx)
{
	this.top += dy;
	this.left += dx;
	this.x_select += dx;
	this.y_select += dy;
}
