function getID(elem) {
	if($(elem).attr("id") !== undefined) {
		var id=$(elem).attr("id").split('-')[1];
		return id;
	}
}
function hideAll() {
	$("a.menu").each(function(){
		var ID = getID(this);
		$("div#l-"+ID).hide();
		$("img#im-"+ID).attr({src:"images/p-0.gif"});
	})
}
function showThis(elem) {
	var to=parseInt($(elem)[0].offsetTop)-2;
	var le=parseInt($(elem)[0].offsetLeft)-4;
	var ID = getID(elem);
	$("div#l-"+ID).css({top:to+"px",left:le+"px"}).show();
	$("img#im-"+ID).attr({src:"images/p-1.gif"});
	//$("div#l-"+ID+" ul li a").
}
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}
function cl() {
	$("#W").hide();
	$("#MC").empty();
	$("#M").hide();
}
function of(wi,he) {
	var wh=winSize(window);
	var a=wh[0];var b=wh[1];var m=0;
	var c = $("#W")[0];
	if (c) {
		if(!document.all) {
			m=20;
		}
		c.style.left = "0"
		c.style.top = "0";
		c.style.width = (Math.max(document.body.clientWidth, a)-m) + "px";
		//c.style.height = (Math.max(document.body.clientHeight, b)+ document.body.scrollTop) + "px";
		c.style.height =  $("#maintable")[0].offsetHeight + "px";
		c.style.zIndex = '90';
		c.style.display='block';
	}
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		pause(350);
	}
	var m = $("#M")[0];
	if (m) {
		m.style.width = wi+"px";
		m.style.height = he+"px";
		var e = (a - wi)/2 + document.body.scrollLeft;
		var f = (b - he)/2 + document.body.scrollTop;
		m.style.left = e + "px";
		m.style.top = (f-60) + "px";
		m.style.zIndex = '150';
		m.style.display='block';
	}
}
function winSize(a) {
	var w = 0;var h = 0;
	if(a.document.body.clientWidth) {w=a.document.body.clientWidth;}
	if(a.document.documentElement.clientWidth) {w=a.document.documentElement.clientWidth;}
	if(a.innerWidth) {w=a.innerWidth;}
	if(a.document.body.clientHeight) {h=a.document.body.clientHeight;}
	if(a.document.documentElement.clientHeight) {h=a.document.documentElement.clientHeight;}
	if(a.innerHeight) {h= a.innerHeight;}
	var ret=[w,h];
	return ret;
}

function showPanel(id,w) {
	w = typeof(w) != 'undefined' ? w : 400;
	pause(250);
	of(w,370);
	$.get("/getpopup.php",
		{ id: id, lang:'hu' },
	  function(data){
		$("#MC").html(data);
	  }
	);
	window.scrollbars='no';
}
function showPanelEn(id) {
	pause(250);
	of(400,370);
	$.get("/getpopup.php",
	  { id: id, lang:'en' },
	  function(data){
		$("#MC").html(data);
	  }
	);
	window.scrollbars='no';
}
function drawMap() {
	var map='<map name="szervezetimap">'+
	'<area shape="polygon" href="javascript:showPanel(&#39;jogikepviselo&#39;)" alt="" title="" coords="70,5 36,10 13,28 40,45 77,49 120,42 135,24 102,7" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;taggyules&#39;)" alt="" title="" coords="188,6 501,6 512,27 498,46 197,49 180,26" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;elnokseg&#39;)" alt="" title="" coords="193,103 498,104 513,124 500,146 196,146 181,123" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;konyvvizsgalo&#39;)" alt="" title="" coords="610,5 576,10 553,28 580,45 617,49 660,42 675,24 642,7" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;elnokvezerigazgato&#39;)" alt="" title="" coords="194,203 498,202 514,223 499,243 202,245 182,225" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;bizottsagireferens&#39;)" alt="" title="" coords="15,248 151,248 165,271 149,292 19,292 3,270" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;mbfotitkar&#39;)" alt="" title="" coords="265,248 401,248 415,271 400,292 269,292 253,270" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;titkarsag&#39;)" alt="" title="" coords="15,308 151,308 165,331 149,352 19,352 3,330" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;szakmaiigazgato&#39;)" alt="" title="" coords="193,308 325,308 342,332 326,351 201,353 180,332" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;fotitkar&#39;)" alt="" title="" coords="364,308 498,308 513,328 499,351 369,352 354,322" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;kommunikaciosmenedzser&#39;)" alt="" title="" coords="542,308 674,308 691,327 674,351 542,351 527,329" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;infrastrukturabizottsag&#39;)" alt="" title="" coords="18,438 317,440 337,463 318,481 19,483 5,462" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;operativvasutibizottsag&#39;)" alt="" title="" coords="367,441 671,439 690,459 675,483 371,484 356,461" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;szemelyszallitas&#39;)" alt="" title="" coords="19,501 319,500 337,523 321,542 18,545 3,523" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;jogibizottsag&#39;)" alt="" title="" coords="370,501 673,501 689,522 675,542 373,544 356,524" />'+
	'<area shape="polygon" href="javascript:showPanel(&#39;kommunikaciosbizottsag&#39;)" alt="" title="" coords="194,525 496,556 513,578 498,599 195,600 182,577" />'+
	'</map>';
	document.write(map);
}
function drawMapEn() {
	var map='<map name="szervezetimap">'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;jogikepviselo&#39;)" alt="" title="" coords="70,5 36,10 13,28 40,45 77,49 120,42 135,24 102,7" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;taggyules&#39;)" alt="" title="" coords="188,6 501,6 512,27 498,46 197,49 180,26" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;elnokseg&#39;)" alt="" title="" coords="193,103 498,104 513,124 500,146 196,146 181,123" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;konyvvizsgalo&#39;)" alt="" title="" coords="610,5 576,10 553,28 580,45 617,49 660,42 675,24 642,7" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;elnokvezerigazgato&#39;)" alt="" title="" coords="194,203 498,202 514,223 499,243 202,245 182,225" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;bizottsagireferens&#39;)" alt="" title="" coords="15,248 151,248 165,271 149,292 19,292 3,270" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;mbfotitkar&#39;)" alt="" title="" coords="265,248 401,248 415,271 400,292 269,292 253,270" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;titkarsag&#39;)" alt="" title="" coords="15,308 151,308 165,331 149,352 19,352 3,330" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;szakmaiigazgato&#39;)" alt="" title="" coords="193,308 325,308 342,332 326,351 201,353 180,332" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;fotitkar&#39;,&#39;800&#39;)" alt="" title="" coords="364,308 498,308 513,328 499,351 369,352 354,322" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;kommunikaciosmenedzser&#39;)" alt="" title="" coords="542,308 674,308 691,327 674,351 542,351 527,329" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;infrastrukturabizottsag&#39;)" alt="" title="" coords="18,438 317,440 337,463 318,481 19,483 5,462" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;operativvasutibizottsag&#39;)" alt="" title="" coords="367,441 671,439 690,459 675,483 371,484 356,461" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;szemelyszallitas&#39;)" alt="" title="" coords="19,501 319,500 337,523 321,542 18,545 3,523" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;jogibizottsag&#39;)" alt="" title="" coords="370,501 673,501 689,522 675,542 373,544 356,524" />'+
	'<area shape="polygon" href="javascript:showPanelEn(&#39;kommunikaciosbizottsag&#39;)" alt="" title="" coords="194,525 496,556 513,578 498,599 195,600 182,577" />'+
	'</map>';
	document.write(map);
}
function showhide(ID,elem) {
	var s=$("#"+elem+"-"+ID).css("display");
	if(s=="none") {
		$("#"+elem+"-"+ID).show("fast");
	} else {
		$("#"+elem+"-"+ID).hide();
	}
}
$(document).ready(function () {
	$("body").append('<div id="W" onclick="cl()"></div><div id="M"><div id="MC"></div></div>');
	$("a.menu").click(function(){
		hideAll();
		showThis(this);
	})
	//$("#content").click(function(){hideAll();})
	//$("#content").bind('click',function(){hideAll();})
	$("#content").bind('mouseover',function(){hideAll();})
	$("#linkek-box").bind('mouseover',function(){hideAll();})
});