function Calque(width, height, handleOnClose) {
    this._isMoving = false;

    this._width = width;
    this._height = height;
    this._handleOnClose = handleOnClose;

    this._div = document.createElement('div');
    this._div.style.position = "absolute";
    this._div.style.zIndex = 1000;

    this._div.style.top = "50px";
    this._div.style.left = "50px";
    this._div.style.width = width+"px";
    this._div.style.height = height+"px";

    this._div.style.backgroundColor = "#FFF";
    this._div.style.padding = "3px";
    this._div.style.border = "1px solid #000";
    this._div.style.overflow = "auto";

    document.body.appendChild(this._div);

    // DRAG
    this._isOnBtDeplacer = false;
    this._btDeplacer = null; // Bouton pour déplacer le calque
    this._posMouseDragStart = new Point(0, 0);
    this._posCalqueDragStart = new Point(0, 0);

    // Bouton pour fermer
    this._btClose = document.createElement('p');
    this._btClose.style.textAlign = "center";

    var s = this;
    var input = document.createElement('input');
    input.type = "submit";
    input.value = "Fermer";
    input.onclick = function() { s.close(); };

    this._btClose.appendChild(input);
    this._div.appendChild(this._btClose);

    // Div de contenu
    this._divContenu = document.createElement('div');
    this._divContenu.style.height = "100%";

    this._div.appendChild(this._divContenu);

    // Pour IE : rien ne peut être au-dessus d'un select, et fait bugguer l'affichage
    var selects = document.getElementsByTagName('select');
    for (var i=0;i<selects.length;i++) selects[i].style.visibility = "hidden";
};

Calque.prototype.close = function() {
    document.body.removeChild(this._div);

    // Pour IE : rien ne peut être au-dessus d'un select, et fait bugguer l'affichage
    var selects = document.getElementsByTagName('select');
    for (var i=0;i<selects.length;i++) selects[i].style.visibility = "visible";

    if (this._handleOnClose) this._handleOnClose();
};

Calque.prototype.hide = function() { this._div.style.display = "none"; };
Calque.prototype.show = function() { this._div.style.display = "block"; };
Calque.prototype.hidden = function() { if (this._div.style.display=="none") return true; return false; };

Calque.prototype.setDraggabled = function(bool) {
    if (!bool) {
	if (this._btDeplacer!=null) this._div.removeChild(this._btDeplacer);
	return;
    }

    if (this._btDeplacer!=null) return;

    this._btDeplacer = document.createElement('div');
    this._div.insertBefore(this._btDeplacer, this._btClose);

    this._btDeplacer.style.backgroundImage = "url(/admin/css/images/cursorMove.gif)";
    this._btDeplacer.style.width = "16px";
    this._btDeplacer.style.height = "17px";
    this._btDeplacer.onmouseover = function() {
	this.style.cursor = "move";
	s._isOnBtDeplacer = true;
    };
    this._btDeplacer.onmouseout = function() {
	s._isOnBtDeplacer = false;
    };

    var s = this;
    document.onmousemove = function(evt) {
	if (!s._isMoving) return;

	var point = Mouse.pos(evt);
	var dx = point.x() - s._posMouseDragStart.x();
	var dy = point.y() - s._posMouseDragStart.y();

	var x = s._posCalqueDragStart.x() + dx;
	var y = s._posCalqueDragStart.y() + dy;

	s._div.style.left = x+"px";
	s._div.style.top = y+"px";	
    };

    document.onmousedown = function(evt) {
	if (!s._isOnBtDeplacer) {
	    s._isMoving = false;
	    return;
	}
	s._isMoving = true;

	s._posMouseDragStart = Mouse.pos(evt);
	s._posCalqueDragStart = CustomNode.posAbsolute(s._div);
    };

    document.onmouseup = function(evt) {
	s._isMoving = false;
    };  
};

Calque.prototype.setNodeContenu = function(node) { this._divContenu.appendChild(node); };
Calque.prototype.setInnerHTML = function(html) { this._divContenu.innerHTML = html; };

Calque.prototype.getNodeContenu = function() { return this._divContenu; };
Calque.prototype.getInnerHTML = function() { return this._divContenu.innerHTML; };


