// obsluga menu
// na podstawie dynlayer.js (Copyright (C) 1999 Dan Steinman)
// 19991106

// ktore menu otwarte 
var menuopened = null;		

// obsluga wysuwanych menu
// layername - nazwa warstwy menu
// object - nazwa obiektu
// x1, y1, x2, y2 -  definicja dodatkowego obszaru aktywnego menu (np. obszar grafiki wskazujacej na menu)
function Menu(layername, object, x1, y1, x2, y2) {
	// nazwa warstwy i obiektu
	this.name = layername;
	this.object = object;
	// init warstwy
	this.lay = new DynLayer(this.name,null);
	this.lay.slideInit();
	this.lay.wipeInit = DynLayerWipeInit;
	if (is.ie5 || is.ns6 || is.ie6) this.lay.wipeInit(0,this.lay.w,this.lay.h,0)
	else this.lay.wipeInit();
	this.clip_y = 0;
	
	// init (numer metody jak w close())
	this.lay.clipTo(null, null, this.clip_y, null);
	//this.lay.clipTo(this.lay.h, null, null, null);
	//this.lay.moveBy(0,-this.lay.h);
	
	if (x1 != null) this.x1 = x1; else this.x1 = this.lay.x;
	if (x2 != null) this.x2 = x2; else this.x2 = this.x1 + this.lay.w;
	if (y1 != null) this.y1 = y1; else this.y1 = this.lay.y;
	if (y2 != null) this.y2 = y2; else this.y2 = this.y1 + this.lay.h;
	
	// menu otwarte			
	this.opened = false;
	// trwa otwieranie
	this.busy = false;
	
	// metody obiektu: otworz, zamknij, zmien stan, 
	// podaj czy wspolrzedne sa w obszarze aktywnym warstwy
	this.show = show;
	this.hide = hide;
	this.toggle = toggle;
	this.inbound = inbound;

	// pokaz menu	
	function show() {
		this.lay.show();
		// jesli otwarte nic nie rob
		if (this.opened) return;
		// czy jest otwarte inne menu?
		if (menuopened != null) {
			// jesli trwa otwieranie innego menu nic nie rob
			if (eval(menuopened + '.busy')) return;
			// w przeciwnym razie zamknij inne menu
			eval(menuopened + '.hide()');
		}
		// przypisz nazwe do zmiennej globalnej
		menuopened = this.object;
		this.opened = true;
		// trwa otwieranie
		this.busy = true;

		// rozne metody otwarcia menu
		// 1.
		this.lay.wipeTo(null,null,this.lay.h,null,10,20,'openFinish()');
		// 2.
		//this.lay.wipeTo(-this.lay.h,null,null,null,10,10,'openFinish()');
		//this.lay.slideBy(0,this.lay.h,30,20,null);
		// 3.
		//this.lay.clipTo(null,null,this.lay.h,null);openFinish();
	}
	
	// ukryj menu
	function hide() {
		// jesli zadne menu nie jest otwarte lub trwa otwieranie nic nie rob
		if (menuopened == null || eval(menuopened + '.busy')) return true;

		// rozne metody otwarcia menu
		// 1. v 3.
		this.lay.clipTo(null, null, this.clip_y,null);
		// 2.
		//this.lay.clipTo(this.lay.h, null, null, null);
		//this.lay.moveBy(0,-this.lay.h);
		this.lay.hide();
		this.opened = false;
		menuopened = null;
	}

	// przelacz stan
	function toggle() {
		if (!this.opened) this.show();
		else this.hide();
	}

	// podaj czy wspolrzedne sa w obszarze aktywnym warstwy
	function inbound(x, y) {
		if ( (x>=this.lay.x && x<=(this.lay.x + this.lay.w) && y>=this.lay.y && y<=(this.lay.y + this.lay.h) )
		  || (x>=this.x1 && x<=this.x2 && y>=this.y1 && y<=this.y2 ) )
			return true;
		else
			return false;
	}
}

// funkcja pomocnicza wykonywana na zakonczenie procesu otwierania menu		
function openFinish() {
	if (menuopened != null) eval(menuopened + '.busy = false;');
}


