// *** JSF Window
// *** (c) feel by fish 
// *** http://www.imagen.pl
// *** 2001.03.06
// *** GNU GPL distribution

// * modified for SPP

// * based on DynAPI
// * by Dan Steinman, http://www.dansteinman.com/dynapi/
// * libs: dynlayer, dynlayer-common, createdestroy

// -> obsluga animowanych okien 
// layername - nazwa warstwy okna

function JSFWindow(layername) {
	// nazwa warstwy i obiektu
	this.layername = layername;
	this.objname = layername + "awin";
	eval(this.objname + "=this");
	
	// init warstwy
	this.lay = new DynLayer(this.layername, null);
	// init warstwy z ramkami
	createLayer(this.layername + "frm",this.layername,0,0,this.lay.w,this.lay.h);
	this.layfrm = new DynLayer(this.layername + "frm", this.layername);
	// init warstwy z zawartoscia
	this.laybody = new DynLayer(this.layername + "body", this.layername);
	
	this.steps = 4;
	this.step = 1;
	this.time = 20;

	this.w = this.laybody.getContentWidth();
	this.h = this.laybody.getContentHeight();
	this.laybody.hide();

	this.opened = false;
	this.busy = false;
	this.run = null;
	
	this.onOpen = null;
	this.onClose = null;
}

// metody obiektu: otworz, zamknij, zmien stan, 
JSFWindow.prototype.show = JSFWindowShow;
JSFWindow.prototype.hide = JSFWindowHide;
JSFWindow.prototype.toggle = JSFWindowToggle;

// pokaz okno
function JSFWindowShow() {
	//if ((!this.opened && this.busy) || (this.opened && !this.busy)) return;
	this.busy = true;
	this.opened = false;

	this.layfrm.show();
	if (this.run) clearTimeout(this.run);
	//this.step = 0;
	this.run = setTimeout("_jsfwinshow(\"" + this.objname + "\")", this.time);
}

// ukryj okno
function JSFWindowHide() {
	//if ((!this.opened && !this.busy) || (this.opened && this.busy)) return;
	this.busy = true;
	this.opened = true;

	this.laybody.hide();
	this.layfrm.show();
	if (this.run) clearTimeout(this.run);
	//this.step = this.steps-1;
	this.run = setTimeout("_jsfwinhide(\"" + this.objname + "\")", this.time);
}

// przelacz stan
function JSFWindowToggle() {
	//if (!this.opened) this.show(); else this.hide();
	if ((!this.opened && this.busy) || (this.opened && !this.busy)) this.hide(); else this.show();
}

	
// --- pomocnicze
function _jsfwinshow(objname) {
	o = eval(objname);
	if (o.step >= o.steps) {
		clearInterval(o.run);
		o.run = null; o.busy = false; o.opened = true;
		o.layfrm.hide();
		o.laybody.show();
		if (o.onOpen) o.onOpen();
	}		
	else {
		frm_w = Math.round((o.w/o.steps)*o.step+1);
		frm_h = Math.round((o.h/o.steps)*o.step+1);
		o.layfrm.write("<table width=" + o.w + " height=" + o.h + " border=0 cellspacing=0 cellpadding=0><tr><td align=\"center\"><table width=\"" + frm_w + "\" height=\"" + frm_h + "\" border=\"1\" bordercolor=\"#FFFFFF\"><tr><td></td></tr></table></td></tr></table>");
		o.run = setTimeout("_jsfwinshow(\"" + o.objname + "\")", o.time);
		o.step++;
	}
}

function _jsfwinhide(objname) {
	o = eval(objname);
	if (o.step <= 1) {
		clearInterval(o.run);
		o.run = null; o.busy = false; o.opened = false;
		o.layfrm.hide();
		if (o.onClose) o.onClose();
	}		
	else {
		o.step--;
		frm_w = Math.round((o.w/o.steps)*o.step+1);
		frm_h = Math.round((o.h/o.steps)*o.step+1);
		o.layfrm.write("<table width=" + o.w + " height=" + o.h + " border=0 cellspacing=0 cellpadding=0><tr><td align=\"center\"><table width=\"" + frm_w + "\" height=\"" + frm_h + "\" border=\"1\" bordercolor=\"#000000\"><tr><td></td></tr></table></td></tr></table>");
		o.run = setTimeout("_jsfwinhide(\"" + o.objname + "\")", o.time);
	}
}

// modfish: load part
if (window.JSFModules!=null) {
	JSFModules[JSFModules.length] = "jsf-window";
	loadJSFModules();
}
