if ( !is.bs5 ) {
	document.location = '../public/browser_error.html';
};
loadEventBinding( window, initPage );

//eventBinding resize


function initPage() {
	function checkParents( el ) {
		 if ( el.parentNode && el.parentNode.parentNode && el.parentNode.parentNode.id == 'pg-menu' )
		 	return true;
		 else
		 	return false;
	}
	function checkMenuLink( el ) {
		if ( el.tagName.toLowerCase() == 'body' )
			 return false;
		else if ( el.tagName.toLowerCase() == 'ul' && el.id == 'pg-menu' )
			return true;
		else
			return checkMenuLink( el.parentNode );
	}
	var elsA, elA, i, j, elLI, elUL;
	// illutració
	i = Math.round( Math.random() * 2 );
	document.getElementById('pg-illustration').className = 'pg-illustration-' + i;
	
	// menü
	elRoot = document.getElementById('pg-menu');
	elRoot.aSub = [];
	elRoot.elActiveItem = null;
	elRoot.time = null;
	elRoot.elLenia = document.createElement('DIV');
	elRoot.elLenia.id = 'pg-menu-lenia';
	document.body.appendChild( elRoot.elLenia );
	elsA = document.getElementsByTagName('A');
	for ( i = 0; i < elsA.length; i++ ) {
		elA = elsA[i];
		// a linkek kötése
		if ( checkMenuLink( elA ) ) {
			eventBinding( elA, true, 'mouseout', menuClose, false );
			eventBinding( elA, true, 'mouseover', menuClear, false );
		}
		if ( elA.parentNode.tagName.toLowerCase() != 'li' || !checkParents( elA ) ) {
			// ie5-nél az almenük esetében utána kell húzni a magasságot
			if ( is.ie5 && !is.ie5mac )
				elA.parentNode.style.height = '10px';
			continue;	
		}
		// főmenüpont
		elA.elRoot = elA.parentNode.parentNode;
		elRoot.aSub[elRoot.aSub.length] = elA;
		eventBinding( elA, true, 'mouseover' , menuOpen, false );
		// almenüjei
		elLI = elA.parentNode;
		for ( j = 0; j < elLI.childNodes.length; j++ ) {
			if ( elLI.childNodes[j].nodeType != Node.ELEMENT_NODE ) continue;
			if ( elLI.childNodes[j].tagName.toLowerCase() == 'ul' ) {
				elA.elSub = elLI.childNodes[j];
				elA.elSub.elPanel = elA;
				break;
			}
		}
	}
	// IE pach
	if ( is.ie && !is.ie5mac ) {
		elUL = document.createElement('UL');
		elUL.appendChild( document.getElementById('pg-menu-lastitem') );
		elUL.id = 'pg-IE-pach-pg-menu-lastitem';
		document.getElementById('pg-foot').appendChild( elUL );
	}
	//document.body.scroll = 'no';
}

function menuOpen() {
	var el;
	if ( is.ie )
		el = window.event.srcElement;
	else
		el = this;
	createFullOffset( el );
	if ( el.elRoot.elActiveItem ) {
		el.elRoot.elActiveItem.elSub.style.display = 'none';
		el.elRoot.elLenia.style.display = 'none';
		el.elRoot.elActiveItem = null;
	}
	if ( el.elSub ) {
		el.elSub.style.display = 'block';
		el.elSub.style.left = el.offsetX - 449 + 'px';
		el.elSub.style.top = el.offsetY - 40 + 'px';
		el.elRoot.elLenia.style.display = 'block';
		el.elRoot.elLenia.style.left = parseInt( el.elSub.style.left ) + el.elSub.offsetWidth + 'px';
		el.elRoot.elLenia.style.top = el.offsetY + el.parentNode.offsetHeight - 15 + 'px';
		if ( is.ie5 && !is.ie5mac )
			el.elRoot.elLenia.style.top = parseInt( el.elRoot.elLenia.style.top ) + 8 + 'px';
		el.elRoot.elActiveItem = el;
	}
}

function menuClose() {
	var el, elRoot;
	if ( is.ie5 ) return;
	elRoot = document.getElementById('pg-menu');
	elRoot.time = setTimeout( function() {
		elRoot.elLenia.style.display = 'none';
		if ( elRoot.elActiveItem != null )
			elRoot.elActiveItem.elSub.style.display = 'none';
		elRoot.elActiveItem = null;
	}, 1500 )
}

function menuClear() {
	if ( is.ie5 ) return;
	elRoot = document.getElementById('pg-menu');
	clearTimeout( elRoot.time );
}