function menuLevel(o,root){ var m = o, lev = 1; while (m!=root) { if (m.tagName=='UL') lev+=1; m=m.parentNode; } return lev; }
function menuDepth(o,d) { var u = o.getElementsByTagName('ul'); var maxD = d; for (var i=0; i<u.length; i++){ maxD = ((ulD=menuDepth(u[i],d+1))>maxD)?ulD:maxD; } return maxD; }
function smShow(){
	var sm = this.getElementsByTagName('ul')[0];
	var pos = elemPos(sm);
	var size = elemSize(sm);
	var lev = menuLevel(this, $('HMenu'));
	var iframe = $('MenuIFrameLev'+lev);
	iframe.style.left = (pos[0]+((hasElementClassName(sm, 'left'))?0:1)*(lev-1))+'px';
	iframe.style.top = (pos[1]+lev-1)+'px';
	iframe.style.width = size[0]+'px';
	iframe.style.height = size[1]+'px';
	iframe.style.visibility = 'visible';
}
function smHide(e){
	if (!e) e = window.event;					// e: event
	var o = eventTo(e);						// o: object the mouse moves to; this: object owning the event handler -> LI
	while (o) { if (o==this) return; o=o.parentNode; }
	
	$('MenuIFrameLev'+menuLevel(this, $('HMenu'))).style.visibility = 'hidden';
}
function aBlur(){ this.blur(); return false; }
var contentWidth = 800;
function OnResize (){
	var newleft = Math.max((Math.round(getClientWidth()-800)/2), 0);
	var contentleft = $('NavBar').style.width.substring(0, $('NavBar').style.width.indexOf('px'));
	$('Header').style.left = $('MenuBar').style.left = $('MenuBarEventCatcher2').style.left = $('IconBar').style.left = $('NavBar').style.left = $('Footer').style.left = newleft+'px';
	var contfr = $('ContentFrame')
	contfr.style.left = parseInt(newleft)+parseInt(contentleft)+'px';
	var ciframe = contfr.childNodes[0];
	if (ciframe){ if(ciframe.tagName=='IFRAME'){ ciframe.style.height = elemSize(contfr)[1]+'px'; } }
}
Event.observe(window, 'resize', function() { OnResize(); });
var dpLoaded = false;
var dpSplash1 = null;
var dpSplash2 = null;
function splashhideall(){
	$('SplashEvents').stopObserving('click');
	$('SplashTable').stopObserving('click');
	jQuery('#SplashOverlay').fadeTo(500, 0, function(){
		$('SplashContent').style.display='none';
		$('SplashOverlay').style.display='none';
		$('SplashEvents').style.display='none';
	});
}
function splash1close(){
	if (!dpLoaded) { return; }
	if (dpSplash1.timeToLive==-1) { return; }
	if (!dpSplash1.cancelledByUser) {
		if (dpSplash1.timeToLive==0) { return; }
		dpSplash1.age = ((+new Date) - dpSplash1.displayed)/1000; // seconds
		if (dpSplash1.age<dpSplash1.timeToLive) { window.setTimeout('splash1close();', (dpSplash1.timeToLive-dpSplash1.age)*1000); return; }
	}
	if (dpSplash2.timeToLive==-1) {
		$('SplashEvents').stopObserving('click');
		$('SplashTable').stopObserving('click');
		jQuery('#Splash1Div').fadeTo(500, 0);
		splashhideall();
		return;
	}
	if (dpSplash2.displayed==0) {
		$('SplashEvents').stopObserving('click');
		$('SplashTable').stopObserving('click');
		dpSplash2.displayed = 1; // do not run into this if branch next time the user clicks
		Event.observe('SplashEvents', 'click', function(event) { dpSplash2.cancelledByUser = true; splash1close(); });
		Event.observe('SplashTable', 'click', function(event) { dpSplash2.cancelledByUser = true; splash1close(); });		// IE miatt kell, mert ott lenyeli a kattintást
		jQuery('#Splash1Div').fadeTo(500, 0, function(){
			$('Splash1Div').style.display='none';
			$('Splash2Div').setStyle('opacity:0');
			$('Splash2Div').style.display='block';
			jQuery('#Splash2Div').fadeTo(500, 1, function(){
				dpSplash2.displayed = +new Date;
				splash1close();
			});
		});
		return;
	}
	if (!dpSplash2.cancelledByUser) {
		if (dpSplash2.timeToLive==0) { return; }
		dpSplash2.age = ((+new Date) - dpSplash2.displayed)/1000; // seconds
		if (dpSplash2.age<dpSplash2.timeToLive) { window.setTimeout('splash1close();', (dpSplash2.timeToLive-dpSplash2.age)*1000); return; }
	}
	jQuery('#Splash2Div').fadeTo(500, 0);
	splashhideall();
}
Event.observe(window, 'load', function() {
	// setting menu event handlers to align IFRAMEs
	var lt = $('MenuBar').getElementsByTagName('li');
	for (var i=0; i<lt.length; i++){ if (lt[i].getElementsByTagName('ul').length) { lt[i].onmouseover = smShow; lt[i].onmouseout = smHide; } }
	// handling empty menu elements' onclick
	var bh, b = ((bh=location.href.indexOf('#')) == -1)?location.href:location.href.substr(0,bh), ah, at = $('MenuBar').getElementsByTagName('a');
	for (i=0; i<at.length; i++){ if ((((ah=at[i].href.indexOf('#')) == -1)?at[i].href:at[i].href.substr(0,ah)) == b) { at[i].onclick = aBlur; } }
	// creating iframes for counting menu depth
	var iframe = document.createElement('iframe');
	iframe.setAttribute('src', "javascript:\'\';"); // javascript:'&lt;body style=\\'margin:0;padding:0;border:0;background-color:white;\\'&gt;&lt;/body&gt;';
	iframe.setAttribute('frameborder', "0");
	iframe.setAttribute('className', 'ddmenubg');	// for IE7 compatibility, iframe.setAttribute('style', "position:absolute; z-index:999; visibility:hidden;");		// not working in IE7
	iframe.setAttribute('class', 'ddmenubg');		// for FF2 compatibility, iframe.setAttribute('style', "position:absolute; z-index:999; visibility:hidden;");		// would work in FF2
	for (i=1; i<=menuDepth($('HMenu'),0); i++){ document.body.appendChild(iframe.cloneNode(false)).setAttribute('id', 'MenuIFrameLev'+i); }
	$('NavBar').style.width='120px';
	OnResize();
	dpLoaded = true;
	$('SplashOverlay').setStyle('opacity:0.9');
	var bShowSplash = (dpSplash1!=null)?((dpSplash1.timeToLive==-1)?false:true):false;
	if (bShowSplash) { splash1close(); } else { splashhideall(); }
});
