function fomenu( panel )
{
	var self = this;
	this.preloader = new imagepreloader();
	this.panel = panel;
	this.timer = new Object;
	this.items = new Array();
	this.textdiv = document.createElement('div');
	this.textdiv.id = 'textDiv';
	this.textdiv.style.cssText = 'position: absolute; display: none; color: white; font-weight: 600; z-index: 3; width: auto; height: 26px;';
	document.body.appendChild(this.textdiv);
	this.submenu = new Object;
	this.submenu.active = -1;
	this.submenu.bottom = globalOffsetTop( this.panel ) + parseInt( this.panel.style.paddingTop );
	this.panel.style.overflow = 'hidden';
	this.menuLoader = new staticDataLoader( 'menu.php?nyelv=' + nyelv + '&height=88', function( text ) { self.onMenuLoaded( text ) } );
	this.onMenuLoaded = function( text )
	{
		this.panel.innerHTML = text;
		applyToAllSubelement( panel, function( element ) { if ( element.tagName.toLowerCase() == 'img' ) self.items.push( handler( element, self.items.length ) ); } );
		for( var index in this.items ) if ( parseInt( index ) == index )
		{
			this.items[ index ].onmouseover = function( element, event, index ) { self.openSubmenu( index ); }
			this.items[ index ].onmouseout = function( element, event, index ) { if ( self.submenu.active == index ) self.closeSubmenu();}
			this.items[ index ].element.style.cursor = 'pointer';
			this.items[ index ].kategoria = this.items[ index ].element.id.match( /^katkep-([0-9]{1,20})$/ )[ 1 ];
			this.preloader.add(this.items[ index ].element.src);
			this.preloader.add(this.items[ index ].element.src.replace(/\/bw_[^\/]+/,'/'));
			// Ha o alkategóriája van, akkor legyen kattintható
			var match = this.items[ index ].element.alt.match(/(.*)[ \t]*\(([0-9]{1,20})\)$/);
			var nev = match[1];
			var db = match[2];
			if (parseInt(db) == 0)
			{
				this.items[ index ].onclick = function(element, event, index)
				{
					var katid = element.id.match(/^katkep-([0-9]{1,20})$/)[1];
					location.href = 'main.php?oldal=kategoria&id=' + katid + '&nyelv=' + nyelv + '&penznem=' + penznem;
				}
				this.items[ index ].element.title = this.items[ index ].element.alt.match(/(.*) \([0-9]{1,20}\)$/)[1];
			}
			this.items[ index ].text = document.createElement('div');
			this.items[ index ].text.id = 'kattext-' + index;
			this.items[ index ].text.innerHTML = nev;
			this.items[ index ].text.style.position = 'absolute';
			this.items[ index ].text.style.top   = (this.submenu.bottom + this.items[ index ].element.offsetHeight + 20) + 'px';
			this.items[ index ].text.style.left  = globalOffsetLeft(this.items[ index ].element) + 'px';
			this.items[ index ].text.style.width = this.items[ index ].element.offsetWidth + 'px';
			this.items[ index ].text.style.textAlign = 'center';
			this.items[ index ].text.style.color = 'white';
			this.items[ index ].text.style.fontWeight = '600'; 
			document.body.appendChild(this.items[ index ].text);
		}
	}
	this.showText = function(parent, text)
	{
		this.textdiv.style.top = (globalOffsetTop(parent) - 26) + 'px';
		this.textdiv.style.left = globalOffsetLeft(parent) + 'px';
		this.textdiv.innerHTML = text;
		this.textdiv.style.display = 'block';
	}
	this.hideText = function() { this.textdiv.style.display = 'none'; }
	this.onLoaded = function( html, index )
	{
		this.items[ index ].submenu = document.createElement( 'div' );
		this.items[ index ].submenu.style.cssText = 'position: absolute; display: none; overflow: hidden;';
		this.items[ index ].submenu.innerHTML = html;
		document.body.appendChild( this.items[ index ].submenu );
		var h = handler(this.items[ index ].submenu, index);
		h.onmouseover = function(element, event, parameter) { self.submenu.on = true; }
		h.onmouseout  = function(element, event, parameter) { self.submenu.on = false; self.closeSubmenu(); }
		applyToAllSubelement(this.items[ index ].submenu, function(element) { if (element.tagName && element.tagName.toLowerCase() == "a") { element.onmouseover = function() {self.showText(element.childNodes[0], element.title);}; element.onmouseout = function() {self.hideText();}; } });
		this.openSubmenu( index );
	}
	this.openSubmenu = function( index )
	{
		//alert( 'open ' + index + "\r\n from " + arguments.callee.caller.toString() ); 
		if ( this.submenu.active != -1 )
		{
			this.submenu.on = false;
			this.reelCloseSubitem();
		}
		if ( !this.items[ index ].submenu )
		{
			if ( !this.items[ index ].dataLoader )
			{
				this.items[ index ].dataLoader = new staticDataLoader( 'submenu.php?nyelv=' + nyelv + '&height=70&kategoria=' + this.items[ index ].kategoria, function ( text, param ) { self.onLoaded( text, param ); }, null, index );
				this.items[ index ].dataLoader.loadData();
			}
		}
		else{ /*alert( 'I am to open : ' + this.submenu.active + ' : ' + index );*/ if ( this.submenu.active != index )
		{
			var element = this.items[ index ].submenu;
			if ( element )
			{
				var zero = globalOffsetLeft( this.items[ index ].element );
				var middle = zero + this.items[ index ].element.clientWidth / 2;
				this.submenu.active = index;
				this.submenu.panel = element;
				this.submenu.width = element.clientWidth;
				if ( this.submenu.panel.width / 2 < middle ) this.submenu.panel.style.left = (middle - this.submenu.panel.width / 2) + 'px';
				else this.submenu.panel.style.left = zero + 'px';
				this.submenu.panel.style.top = (this.submenu.bottom - 75) + 'px';
				this.submenu.panel.style.display = 'block';
				//alert( index + " : " + element.style.display );
				this.items[ this.submenu.active ].element.src = this.items[ this.submenu.active ].element.src.replace(/\/bw_/, '/');
				this.items[ this.submenu.active ].text.style.color = '#EFC830';
			}
		}}
	}
	this.closeSubmenu = function()
	{
		if ( !this.timeout || this.submenu.active != this.timer.index )
		{
			var tx = new Object();//{ index : this.submenu.active };
			tx.index = this.submenu.active;
			this.timer.index = this.submenu.active;
			setTimeout( function() { self.reelCloseSubitem( tx.index ); }, 200 );
		}
	}
	this.reelCloseSubitem = function( index )
	{
		if ( index && index != this.submenu.active && index != -1 )
		{
			if (this.items[ index ].element.src.search( /\/bw_[^\/]+/ ) == -1)
			{
				var scr = this.items[ index ].element.src.split( '/' );
				scr[ scr.length - 1 ] = 'bw_' + scr[ scr.length - 1 ]
				this.items[ index ].element.src = scr.join( '/' );
			}
		}
		else if ( !this.submenu.on && this.submenu.active != -1 )
		{
			//alert( 'close ' + index + " : " + arguments.callee.caller.toString() );
			this.submenu.panel.style.display = 'none';
			//alert( this.items[ this.submenu.active ].element.src.replace(/\/bw_/, '/') );
			{
				var scr = this.items[ this.submenu.active ].element.src.split( '/' );
				scr[ scr.length - 1 ] = 'bw_' + scr[ scr.length - 1 ]
				this.items[ this.submenu.active ].element.src = scr.join( '/' );
				this.items[ this.submenu.active ].text.style.color = 'white';
			}
 			this.submenu.active = -1;
		}
		this.timeout = false;
	}
	this.menuLoader.loadData();
}
