var DBGCNT = 1;
function dbg(m)
{
	var c = $('DebugDiv').get('html');
	h = DBGCNT+'. '+ m +'<br/>'+ c;
	DBGCNT++;
	$('DebugDiv').set('html', h);
}
//





/*
* Breadcrumb menu
*/
var BcMenu =  new Class
({
	initialize: function()
	{
		this.hDelay = 350;

		// menu1
		this.bcMenu1 = $('Bc_ddm_1');
		this.bcOpener1 = $('Bc_ddm_opener_1');
		if (this.bcMenu1 && this.bcOpener1)
		{
			this.bcOpener1.addEvent('mouseenter', function(e) {this.openBcMenu(this.bcMenu1);}.bind(this));
			this.bcOpener1.addEvent('mouseleave', function(e) {this.timerBcm = this.closeBcMenu.delay(this.hDelay, this, this.bcMenu1);}.bind(this));
			//
			this.bcMenu1.addEvent('mouseenter', function(e) {this.openBcMenu(this.bcMenu1);}.bind(this));
			this.bcMenu1.addEvent('mouseleave', function(e) {this.timerBcm = this.closeBcMenu.delay(this.hDelay, this, this.bcMenu1);}.bind(this));
		}

		// menu2
		this.bcMenu2 = $('Bc_ddm_2');
		this.bcOpener2 = $('Bc_ddm_opener_2');
		if (this.bcMenu2 && this.bcOpener2)
		{
			this.bcOpener2.addEvent('mouseenter', function(e) {this.openBcMenu(this.bcMenu2);}.bind(this));
			this.bcOpener2.addEvent('mouseleave', function(e) {this.timerBcm = this.closeBcMenu.delay(this.hDelay, this, this.bcMenu2);}.bind(this));
			//
			this.bcMenu2.addEvent('mouseenter', function(e) {this.openBcMenu(this.bcMenu2);}.bind(this));
			this.bcMenu2.addEvent('mouseleave', function(e) {this.timerBcm = this.closeBcMenu.delay(this.hDelay, this, this.bcMenu2);}.bind(this));
		}
	},

	//
	openBcMenu: function(m)
	{
		clearTimeout(this.timerBcm);
		m.setStyle('display', 'block');
	},


	//
	closeBcMenu: function(m)
	{
		m.setStyle('display', 'none');
	}
});
// END BcMenu





//
var TopMenu =  new Class
({
	initialize: function()
	{
		this.hDelay = 350;
		this.activeL1 = false;
		this.activeL2 = false;
		this.activeL3 = false;

		this.mainUl = $('TopMenuCnt').getElements('li.top_menu_li');

		// topmenu
		this.mainUl.each(function(li)
		{
			li.addEvent('mouseenter', function(e)
			{
				this.switchMainOn(li);
			}.bind(this));

			li.addEvent('mouseleave', function(e)
			{
				//li.removeClass('over');
				this.timerL2 = this.switchMainOff.delay(this.hDelay, this, li);
			}.bind(this));

		}.bind(this));
	},



	//
	switchMainOn: function(m)
	{
		//dbg('switchmainon');
		//
		clearTimeout(this.timerL2);

		// jelenlegi fomenu ki
		if (this.activeL1 && m!=this.activeL1)
			this.switchMainOff(this.activeL1);

		// fomenu be
		m.addClass('over');
		this.activeL1 = m;

		// 2. szint ha van
		if (sm = m.getElement('ul.ML2'))
			this.switchSubOn(sm, 2);

		// ha van bread
		if (bc = $('BreadCrumb'))
			bc.setStyle('display', 'none');
	},


	// fomenu kikapcs
	switchMainOff: function(m)
	{
		//dbg('switchMainOff');
		// fomenu ki
		m.removeClass('over');

		//
		this.activeL1 = false;

		// ha van bread
		if (bc = $('BreadCrumb'))
			bc.setStyle('display', 'block');

		// aktiv 2. szint ha van: kikapcs
		if (this.activeL2)
			this.switchSubOff(this.activeL2, 2);

		// aktiv 3. szint ha van: kikapcs
		if (this.activeL3)
			this.switchSubOff(this.activeL3, 3);
	},



	//
	switchSubOn: function(m, lvl)
	{
		m.setStyle('display', 'block');

		if (lvl==2)
		{

			// 2. szintu lista elemekre lehet lvlv3 menu
			if (this.activeL2!=m)
			{
				m.getElements('li.M2li').each(function(l)
				{

					l.getElement('a').addEvent('mouseenter', function()
					{
						//dbg('level3 enter');
						if (mm3 = l.getElement('ul.menu_level3'))
						{
							if (this.activeL3 && mm3!=this.activeL3)
								this.switchSubOff(this.activeL3, 3);
							this.switchSubOn(mm3, 3);
						}
//						else
//						{
//							if (this.activeL3 && mm3!=this.activeL3)
//								this.switchSubOff(this.activeL3, 3);
//						}

						if (this.activeL3 && mm3!=this.activeL3)
							this.switchSubOff(this.activeL3, 3);

					}.bind(this));


					/*
					l.addEvent('mouseleave', function()
					{
						if (mm3 = l.getElement('ul.menu_level3'))
						{
							//this.switchSubOff(mm3, 3);
							args =[mm3,3];
							this.timerL2 = this.switchSubOff.delay(900, this, args);
						}
					}.bind(this));
					*/

				}.bind(this));
			}

			this.activeL2 = m;
		}
		// END lvl2

		// lvl3
		if (lvl==3)
		{
			this.activeL3 = m;
		}
	},


	//
	switchSubOff: function(m, lvl)
	{
		//dbg('suboff');
		m.setStyle('display', 'none');

		if (lvl==2)
		{
			this.activeL2 = false;
			//2
			m.getElements('li.M2li').each(function(l)
			{
				l.getElement('a').removeEvents('mouseenter');
			}.bind(this));
		}

		if (lvl==3)
		{
			this.activeL3 = false;
		}
	}
});
// END TopMenu





//
function fadeIn(el, dur)
{
	// ie eseten csak sima kirakas lehet, amig nincs fix a fade antialias bugra
	if (Browser.ie)
		el.setStyle('display', 'block');
	else
	{
		// eloszor nemlatszik
		el.setStyle('opacity', 0);
		// effektet gyartunk neki
		var dFX = new Fx.Tween(el, {duration: dur});
		// blockra
		el.setStyle('display', 'block');
		// fade-in
		dFX.start('opacity', 0, 1);
	}
}
//





// full oldal overlay layer   #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
var FullOverlay = new Class
({
	// johet onclick fuggveny
	initialize: function(onclick_function)
	{
		//
		this.overlay = $('Overlay');
		this.overlayId = 'Overlay';

		// stilus
		this.overlay.set(
			{'styles':{
				'width':window.getScrollSize().x,
				'height':window.getScrollSize().y,
				'opacity': 0.6
			}}
		)

		// onclick
		if (onclick_function)
			this.overlay.addEvent('click', function(){eval(onclick_function())});
	},


	// bekapcsol
	show: function()
	{
		this.overlay.setStyle('display', 'block');

		// selectek elrejtese ie6 alatt
		if (Browser.ie6)
		{
			this.selects = document.getElements('select');
			this.selects.each
			(
			function(s)
			{
				s.setStyle('visibility', 'hidden');
			}
			)
		}
	},


	// kikapcsol
	hide: function()
	{
		this.overlay.setStyle('display', 'none');
		this.overlay.removeEvent('click');

		// selectek visszarakasa ie6 alatt
		if (Browser.ie6)
		{
			this.selects.each
			(
			function(s)
			{
				s.setStyle('visibility', 'visible');
			}
			)
		}
	},


	// meret beallitas
	updateSize: function(w, h)
	{
		if (w>0)
			this.overlay.setStyle('width', w);
		if (h>0)
			this.overlay.setStyle('height', h);
	},


	// meret reset: az ablakhoz igazija
	resetSize: function()
	{
		this.overlay.setStyle('width', window.getScrollSize().x);
		this.overlay.setStyle('height', window.getScrollSize().y);
	}
});





// kep nagyito class #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
var EnlargePics = new Class
({
	initialize: function()
	{
		this.picLinks = $$('a.PicThumb');
		if (this.picLinks.length>0)
		{
			// elemek
			this.gallery = $('Img_layer');
			this.galleryTable = this.gallery.getElement('table');
			this.galleryLink = this.gallery.getElement('a');
			this.galleryPic = this.gallery.getElement('img');

			// overlay
			this.overlay = new FullOverlay();
			$(this.overlay.overlayId).addEvent('click', function(){this.close()}.bind(this));

			// bezaras a kepen, tablazaton
			this.galleryLink.addEvent('click', function(e){e.stop();this.close()}.bind(this));
			this.galleryTable.addEvent('click', function(e){e.stop();this.close()}.bind(this));
			this.gallery.addEvent('click', function(e){e.stop();this.close()}.bind(this));

			// megnyitasok
			this.picLinks.each(function(a)
			{
				a.addEvent('click', function(e)
				{
					e.stop();
					var src = a.getElement('img').get('src');
					src = src.replace('.thu', '.gal');
					this.showPic(src);
				}.bind(this))
			}.bind(this))
		}
	},


	showPic: function(src)
	{
		// overlay
		this.overlay.show();

		// kep forras
		this.galleryPic.set('src', src);
		this.galleryPic.setStyle('zIndex', 25);

		// x pos (a center divhez)
		xPos = $('Center_div').getPosition().x;

		// y pos kozepre az ablakhoz
		yPos = window.getScroll().y + ( (window.getSize().y/2)-588/2 );
		if (yPos<1)
			yPos = 1;

		// beallitja a classokat, megjelenik
		this.gallery.set({
			styles: {
				display:'block',
				position:'absolute',
				left:xPos,
				top:yPos
			}
		});
	},


	close: function()
	{
		this.galleryPic.set('src', '');
		//
		this.gallery.set({
			styles: {
				display:'none',
				left:0,
				top:0
			}
		});
		//
		this.overlay.hide();
	}
});
//















//
//
window.addEvent('domready',function()
{
	new TopMenu();
	new BcMenu();
});






