
function ModalWindow() {   
	this.startZindex = this.lastZindex = 1000000;
	this.DynLayer = DynLayer;
	this.DynLayer();
    
    this.content = [];
    if (arguments[0])
	    this.content[0] = arguments[0];

	this.setmodal();
    
    var txt = '<img src="' + arguments[1] + '" width="' + this.w +'" height="' + this.h + '">';
    this.setHTML(txt);    
};


ModalWindow.prototype = new DynLayer;

ModalWindow.prototype.addContent = function() {
    var i = this.content.length;
    this.content[i] = arguments[0];
    this.positionContent(i);
    this.content[i].setVisible(false);
}

ModalWindow.prototype.setmodal = function() {
    this.setZIndex(this.startZindex);
    var w = is.ie?document.body.scrollWidth:DynAPI.document.getWidth();
    var h = is.ie?document.body.scrollHeight:DynAPI.document.getHeight();
    this.setSize(w, h);
    
    this.moveTo(0,0);
    this.hide();

    for (i=0; i<this.content.length; i++) {
        this.positionContent(i);
        }    
};

ModalWindow.prototype.positionContent = function(i) {
    this.content[i].setZIndex(++this.lastZindex);
    this.moveContent(i);
}

ModalWindow.prototype.moveContent = function(i, startW, startH) {
	var x = startW + Math.round((DynAPI.document.getWidth()-this.content[i].w)/2);
	var y = startH + Math.round((DynAPI.document.getHeight()-this.content[i].h)/2);
	this.content[i].moveTo(x,y);
}

ModalWindow.prototype.show  = function () {
    this.setVisible(true);
    //var startW = is.ie?document.body.scrollLeft:0;
    //var startH = is.ie?document.body.scrollTop:0;
    var startW = document.body.scrollLeft;
    var startH = document.body.scrollTop;

    for (i=0; i<this.content.length; i++) {
        this.moveContent(i, startW, startH);
        this.content[i].setVisible(true);
        //this.content.setFocus();
        }    
}

ModalWindow.prototype.hide  = function () {
    this.setVisible(false);
    for (i=0; i<this.content.length; i++) {
        this.content[i].setVisible(false);
        //this.content.setFocus();
        }    
}

