
function loadTimer() {
	if (document.getElementById('footer') != null) {
		clearInterval(onLoadTimer);
		init();
	}
}
function init() {
	idozonaFrissit();
	setInterval(idozonaFrissit,30000);
	initMenu();
	checkFileUploadSubmit();
	openBoxes();
}


function idozonaFrissit() {
	ido = new Date();
	if (ido.getDay() == 0 || ido.getDay() == 6)
		return false;
	ido = ido.getHours();
	if (ido >= 1 && ido < 9)
		document.getElementById('timetokyo').className='nyitva';
	else document.getElementById('timetokyo').className='zarva';
	if (ido >= 0 && ido < 8)
		document.getElementById('timesydney').className='nyitva';
	else document.getElementById('timesydney').className='zarva';
	if (ido >= 8 && ido < 16)
		document.getElementById('timefrankfurt').className='nyitva';
	else document.getElementById('timefrankfurt').className='zarva';
	if (ido >= 9 && ido < 17)
		document.getElementById('timelondon').className='nyitva';
	else document.getElementById('timelondon').className='zarva';
	if (ido >= 14 && ido < 22)
		document.getElementById('timenewyork').className='nyitva';
	else document.getElementById('timenewyork').className='zarva';
}

function initMenu() {
	var menu = document.getElementById('menuleft');
	for (var i=0; i<menu.childNodes.length; i++) {
		if (menu.childNodes.item(i).tagName == 'LI') {
			menu.childNodes.item(i).onmouseover=function() { over(this)}
		}
		if (menu.childNodes.item(i).className == "selected") {
			initSubMenu(menu.childNodes.item(i));
		}
	}
	var menu = document.getElementById('menuright');
	for (var i=0; i<menu.childNodes.length; i++) {
		if (menu.childNodes.item(i).tagName == 'LI') {
			menu.childNodes.item(i).onmouseover=function() { over(this)}
		}
	}
}

function initSubMenu(menu) {
	var submenu = document.getElementById('submenu');
	if ( submenu ) {
		for (var i=0; i<submenu.childNodes.length; i++) {
			if (submenu.childNodes.item(i).tagName == 'LI' && submenu.childNodes.item(i).className != "menubreak") {
				submenu.childNodes.item(i).onmouseover=function() {subover(this)}
				submenu.childNodes.item(i).onmouseout=function() {subout(this)}
			}
		}
	}
}


function over(item) {
	item.saveClassName = item.className;
	item.className='over';
	if (item.hasChildNodes()) {
		for (var i=0; i<item.childNodes.length; i++) {
			if (item.childNodes.item(i).tagName == 'UL') {
				item.childNodes.item(i).style.display="block";
			}
		}
	}
	item.onmouseout = function() { out(this)}
}
function out(item) {
	if (item.saveClassName != 'selected') 
		item.className = '';
	else
		item.className='selected';
	if (item.hasChildNodes()) {
		for (var i=0; i<item.childNodes.length; i++) {
			if (item.childNodes.item(i).tagName == 'UL') {
				item.childNodes.item(i).style.display="none";
				break;
			}
		}
	}
}

function subover(item) {
	item.saveClass = (item.className=='subselected') ? true : false;
	item.className='subover';
}
function subout(item) {
	if (!item.saveClass)
		item.className = '';
	else item.className = 'subselected';
}

function newClock(name) {
	var clockWidth=80;
	var clockHeight=80;
	document.write("<embed src='./images/clock_"+name+".swf' width='"+clockWidth+"' height='"+clockHeight
		+"' wmode='transparent' type='application/x-shockwave-flash'></embed>");
}


function checkFileUploadSubmit() {
	var nodes = document.getElementsByTagName('input');
	for (var i=0; i < nodes.length; ++i) {
		if ( nodes[i].type == "file" ) {
			nodes[i].form.onsubmit = function() {return pleaseWait();};
		}
	}
	
}

function pleaseWait(){
	//Háttér elsötétítése
	var scrollHeight = document.body.scrollHeight || document.body.offsetHeight;
	var opacityDiv = document.createElement("div");
	opacityDiv.id="opacityDiv";
	opacityDiv.style.cssText =
		"position:absolute; top:0; background:black; opacity:0.1; filter:alpha(opacity=70);"+
		"width:100%; height:"+(scrollHeight+20)+"px;";
	document.body.appendChild(opacityDiv);
	
	//Fix doboz
	var ie6 = typeof document.body.style.maxHeight == "undefined";
	var alertDiv = document.createElement("div");
	alertDiv.id="pleaseWaitDiv";
	alertDiv.style.cssText =
		"position:"+ ((!ie6) ? "fixed" : "absolute") + "; " +
		"top:" + (Math.round((window.innerHeight
				|| (document.getElementsByTagName("html")[0].clientHeight))/2-85-55
				+ (ie6 ? document.documentElement.scrollTop : 0)) ) +"px; "+
		"left:"+ Math.round((window.innerWidth
				|| document.getElementsByTagName("html")[0].clientWidth) /2-200-55) +"px; "+
		"height:170px; width:400px; padding: 50px; font-size:2em; text-align: center; "+
		"background-color:white; border: solid 5px #548f58; box-shadow:2px 4px 10px 1px black;";
		
	alertDiv.innerHTML = "<img src='./images/loadingCircle.gif' alt='Loading...' /><br /><br />"+
		"<span style='font-size:80%'>Fájlok feltöltése folyamatban.<br />"+
		"<span style='font-size:80%'>Ez lassú internetkapcsolat mellett <strong>több percig</strong> is eltarthat. Ez alatt semmiképp se hagyja el az oldalt!</span></span><br /><br />"+
		"Kérem várjon!";
	document.body.appendChild(alertDiv);
	
	//Elsötétítás fokozatos megjelenítése
	currentOpacity = 1;
	interval = setInterval("document.getElementById('opacityDiv').style.opacity='0.'+ (++currentOpacity);"
		+"if (currentOpacity == 7) clearInterval(interval);"
		, 25);
	
	return true;
}



function getURLParam (strParamName){
//forrás: hu.wikipedia.org User:Kisbes/jaror.js
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return decodeURI(strReturn);
}

function belsoLinkUgorj() {
	if (getURLParam('ugras')) {
		var cim = new String(document.location);
		var cim = cim.replace("&ugras="+getURLParam('ugras'), "");
		var cim = cim.replace("?ugras="+getURLParam('ugras'), "");
		document.location=cim+'#'+getURLParam('ugras');
	}
}

function onLoadEvents() {
	onLoadTimer = setInterval("loadTimer()",50);
	belsoLinkUgorj();
}

document.onLoad=new onLoadEvents();

function nyitCsuk(element) {
	$('#'+element).slideToggle(200);
	/*
	element = document.getElementById(element);
	if ( element && element.style ) {
		if ( element.style.display == 'block' )
			 element.style.display="none";
		else element.style.display="block";
	}
	*/
	return false;
}

function openBoxes(){
	var boxName = document.location.href.match(/#([a-z]*)$/);
	if (boxName !== null) {
		boxName = boxName[1];
		var boxRes = document.getElementById(boxName + "Box");
		if (boxRes) {
			nyitCsuk(boxName + "Box");
		}
	}
	
	
}// Szövegbuborékok
$(function(){
	$('.tip').hover(
		function(e) {
			$('.tip > span').hide();
			$(this).find('span').show(200);
			return false;
		},
		function() {
			$(this).find('span').hide(200);
		}
	)
});
