var tartomany = "gdc.hu";
var protokoll = "mailto";

for (i=1; i<=9; i++) {
	eval("kepon" + i + " = new Image();");
	eval("kepon" + i + ".src = \"/data/images/" + fejlectipus + "menu" + i + ".2.gif\";");
	eval("kepoff" + i + " = new Image();");
	eval("kepoff" + i + ".src = \"/data/images/" + fejlectipus + "menu" + i + ".gif\";");
}


function csere(id, mod) {
	if (mod) { eval("document.getElementById('kep" + id + "').src = kepon" + id + ".src;"); }
	else eval("document.getElementById('kep" + id + "').src = kepoff" + id + ".src;");
}

function open_image(src, w, h) {
	imageview = window.open("", "imageview", "width=" + w + ",height=" + h);
	imageview.moveTo(Math.round((screen.width-w)/2), Math.round((screen.height-h)/2));
	imageview.document.open();
	imageview.document.write('<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">');
	imageview.document.write('<html><head><title>Kép megtekintése</title><link rel="stylesheet" type="text/css" href="/style.css" /><meta http-equiv="Content-type" content="text/html; charset=iso-8859-2" /><meta http-equiv="author" name="author" content="Mile Informatika - http://www.mile.hu/" /></head>');
	imageview.document.write('<body bgcolor="#000000" text="silver" link="orange" alink="yellow" vlink="orange" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >');
	imageview.document.write('<a href="#" onClick="window.close();" ><img src="' + src + '" width="' + w + '" height="' + h + '" border="0" /></a></body></html>');
	imageview.document.close();
	// imageview.document.oncontextmenu = RightClicker;
	
}

function show_hide_layer(layerid) {
	if (layerid != "") {
		v = document.getElementById(layerid).style.visibility;
		if (v != "visible") v = "visible";
			else v = "hidden";
		document.getElementById(layerid).style.visibility = v;
	}
}

function hide_layer(layerid) {
	if (layerid != "") {
		cucc = eval("$(" + layerid + ");");
		cucc.fadeOut("normal");
	} // document.getElementById(layerid).style.visibility = "hidden";
}

function show_layer(layerid) {
	if (layerid != "") {
		cucc = eval("$(" + layerid + ")");
		cucc.fadeIn("normal");
	} // document.getElementById(layerid).style.visibility = "visible";
}


function open_close_layer(layerid) {
	if (layerid != "") {
		d = document.getElementById(layerid).style.display;
		if (d != "block") d = "block";
			else d = "none";
		document.getElementById(layerid).style.display = d;
	}
}

function close_layer(layerid) {
	document.getElementById(layerid).style.display = "none";
}

function open_layer(layerid) {
	document.getElementById(layerid).style.display = "block";
}


function level_kuldes(hova) {
	window.location = protokoll + ":" + hova + "@" + tartomany;
}

function RightClicker() {
   return false;
}

function fmenu_preselect(menuid) {
	if (menuid) {
		eval("kepoff" + menuid + ".src = \"images/fmenu" + menuid + ".2.gif\";");
		document.getElementById("kep" + menuid).src = "images/fmenu" + menuid + ".2.gif";
	}
}


var opendropdown = "";
var dropintervalid = 0;
function dropdown_open(menuid) {
	if (dropintervalid) clearTimeout(dropintervalid);
	if (opendropdown != "" && opendropdown != menuid) {
		dropdown_hide(opendropdown);
	}
	if (opendropdown != menuid) show_layer(menuid);
	opendropdown = menuid;
}

function dropdown_hide() {
	if (dropintervalid) clearTimeout(dropintervalid);
	hide_layer(opendropdown);
	opendropdown = "";
}

function dropdown_timer() {
	if (dropintervalid) clearTimeout(dropintervalid);
	dropintervalid = setTimeout(dropdown_hide, 1500);
}

function dropdown_timer_stop() {
	if (dropintervalid) clearTimeout(dropintervalid);
}


function getPageSize() {
	var xScroll, yScroll;
	var xScrollPos = document.body.scrollLeft;
	var yScrollPos = document.body.scrollTop;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight, xScrollPos, yScrollPos);
	return arrayPageSize;
};


function open_gallery_item(src, w, h, desc) {
	var arrPageSizes = getPageSize();
	posx = Math.abs(Math.round((arrPageSizes[2]-w)/2));
	// posy = Math.abs(dy + Math.round((arrPageSizes[3]-h)/2));
	posy = arrPageSizes[5] + Math.abs(Math.round(arrPageSizes[3]/2 - h/2));
	out = '<div id="overlaycontainer" style="left: ' + posx + 'px; top: ' + posy + 'px; width: ' + w + 'px; ">'; // height: ' + (h+20) + 'px;
	out += '<img src="' + src + '" width="' + w + '" height="' + h + '" border="0" alt="' + desc + '"/><br />' + desc + '</div>';
	$('body').append('<div id="blackoverlay" style="display: none; position: absolute; top: 0; left: 0; z-index: 90; width: 100%; height: 500px;"></div>');
	$('body').append(out);
	
	$('#blackoverlay').css({
		backgroundColor:	'#000000',
		opacity:			0.8,
		width:				arrPageSizes[0],
		height:				arrPageSizes[1]
	}).fadeIn("slow", function() {
		$('#overlaycontainer').fadeIn("slow");
		
	});
	
	$('#blackoverlay').click(function() {
		$('#overlaycontainer').remove();
		$('#blackoverlay').remove();
	});
	
	$('#overlaycontainer').click(function() {
		$('#overlaycontainer').remove();
		$('#blackoverlay').remove();
	});
}


function open_video_item(itemid) {
	var arrPageSizes = getPageSize();
	dy = arrPageSizes[1] - arrPageSizes[3];
	w = 610;
	posx = Math.abs(Math.round((arrPageSizes[2]-w)/2));
	// posy = Math.abs(dy + Math.round((arrPageSizes[3]-h)/2));
	// posy = arrPageSizes[5] + Math.abs(Math.round(arrPageSizes[3]/2 - h/2));
	posy = arrPageSizes[5] + 30;
	out = '<div id="overlaycontainer" style="left: ' + posx + 'px; top: ' + posy + 'px; width: ' + w + 'px; ">'; // height: ' + (h+20) + 'px;
	out += '<div align="center"><br /><br /><br /><br /><img src="/data/images/loading.gif" width="36" height="36" border="0" alt="" /><br /><br /><br /><br /></div></div>';
	$('body').append('<div id="blackoverlay" style="display: none; position: absolute; top: 0; left: 0; z-index: 90; width: 100%; height: 500px;"></div>');
	$('body').append(out);
	
	$('#blackoverlay').css({
		backgroundColor:	'#000000',
		opacity:			0.8,
		width:				arrPageSizes[0],
		height:				arrPageSizes[1]
	}).fadeIn("slow", function() {
		$('#overlaycontainer').fadeIn("slow", function() {
			document.getElementById('ajaxframe').src = '/video_loader.php?id=' + itemid;
		});
		
	
	});
	/*
	$('#blackoverlay').click(function() {
		$('#overlaycontainer').remove();
		$('#blackoverlay').remove();
	});
	
	$('#overlaycontainer').click(function() {
		$('#overlaycontainer').remove();
		$('#blackoverlay').remove();
	});
	*/
}


function open_bg_item(itemid) {
	var arrPageSizes = getPageSize();
	w = 602;
	h = 480;
	posx = Math.abs(Math.round((arrPageSizes[2]-w)/2));
	// posy = Math.abs(dy + Math.round((arrPageSizes[3]-h)/2));
	posy = arrPageSizes[5] + Math.abs(Math.round(arrPageSizes[3]/2 - h/2));
	out = '<div id="overlaycontainer" style="left: ' + posx + 'px; top: ' + posy + 'px; width: ' + w + 'px; ">'; // height: ' + (h+20) + 'px;
	// out += '<img src="' + src + '" width="' + w + '" height="' + h + '" border="0" alt="' + desc + '"/><br />' + desc + '</div>';
	out += '</div>'
	$('body').append('<div id="blackoverlay" style="display: none; position: absolute; top: 0; left: 0; z-index: 90; width: 100%; height: 500px;"></div>');
	$('body').append(out);
	
	$('#blackoverlay').css({
		backgroundColor:	'#000000',
		opacity:			0.8,
		width:				arrPageSizes[0],
		height:				arrPageSizes[1]
	}).fadeIn("slow", function() {
		document.getElementById("ajaxframe").src = '/hatterkep_loader.php?id=' + itemid;
		$('#overlaycontainer').fadeIn("slow");
	});
	
	$('#blackoverlay').click(function() {
		$('#overlaycontainer').remove();
		$('#blackoverlay').remove();
	});
	
	$('#overlaycontainer').click(function() {
		$('#overlaycontainer').remove();
		$('#blackoverlay').remove();
	});
}


var cikk_gallery_elements = Array();
var cikk_gallery_elements_desc = Array();
var maxImg = 0;
var actImg = 0;
function imgadvance(d) {
	nextImg = actImg;
	maxImg = cikk_gallery_elements.length - 1;
	nextImg += d;
	if (nextImg > maxImg) nextImg = 0;
	if (nextImg < 0) nextImg = maxImg;
	if (nextImg != actImg) {
		actImg = nextImg;
		var nextImage = new Image();
		document.getElementById('slidecontainer').innerHTML = '<table style="width: 100%; height: 100%; "><tr><td align="center"><img src="/data/images/lightbox-ico-loading_black.gif" width="32" height="32" border="0" alt="Töltés..." title="Töltés..." /></td></tr></table>';
		nextImage.onload = function() {
			var w = this.width;
			var h = this.height;
			var arrPageSizes = getPageSize();
			posx = Math.round((arrPageSizes[2] - w)/2)-22;
			if (posx < 0) posx = 0;
			posy = arrPageSizes[5] + Math.round(arrPageSizes[3]/2 - h/2) - 25;
			$('#slidecontainer').animate({ width: (w+44), height: (h+25), left: posx, top: posy}, "normal", function(){
				var innercontainerstring = 
				'<table border="0" cellspacing="0" cellpadding="0"><tr><td><a href="javascript:imgadvance(-1)"><img src="/data/images/previmg.gif" width="22" height="22" border="0" alt="" /></a></td>'  + 
				'<td align="center"><strong>' + cikk_galeria_nev + '</strong><br />' + 
				'<a href="javascript:imgadvance(1)"><img src="' + cikk_gallery_elements[actImg] + '" width="' + w + '" height="' + h + '" border="0" alt="" /></a><br /><span class="egyes">' + cikk_gallery_elements_desc[actImg] + '</span></td>' + 
				'<td><a href="javascript:imgadvance(1)"><img src="/data/images/nextimg.gif" width="22" height="22" border="0" alt="" /></a></td></tr></table>';
				document.getElementById('slidecontainer').innerHTML = innercontainerstring;
			});
		}
		nextImage.src = cikk_gallery_elements[actImg];
	}
}

var cikk_galeria_nev = "";

function cikk_galeria(galerianev) {
	cikk_galeria_nev = galerianev;
	var nextImage = new Image();
	actImg = 0;
	nextImage.onload = function(){
		var w = this.width;
		var h = this.height;
		var arrPageSizes = getPageSize();
		posx = Math.round((arrPageSizes[2] - w)/2)-22;
		if (posx < 0) posx = 0;
		posy = arrPageSizes[5] + Math.round(arrPageSizes[3]/2 - h/2) - 25;
		out = '<div id="slidecontainer" style="background-color: black; position: absolute; left: ' + posx + 'px; top: ' + posy + 'px; width: ' + (w + 44) + 'px; height: ' + (h+25) + 'px; z-index: 100; display: none; ">';
		out += '</div>'
		$('body').append('<div id="blackoverlay" style="display: none; position: absolute; top: 0; left: 0; z-index: 90; width: 100%; height: 500px;"></div>');
		$('body').append(out);
		$('#blackoverlay').css({
			backgroundColor:	'#000000',
			opacity:			0.8,
			width:				arrPageSizes[0],
			height:				arrPageSizes[1]
		}).fadeIn("fast", function() {
			$('#slidecontainer').fadeIn("fast", function(){
				innercontainerstring = '<table border="0" cellspacing="0" cellpadding="0"><tr><td><a href="javascript:imgadvance(-1)"><img src="/data/images/previmg.gif" width="22" height="22" border="0" alt="" /></a></td>' +  //  style="background-color: transparent; "
				'<td align="center"><strong>' + cikk_galeria_nev + '</strong><br />' + 
				'<a href="javascript:imgadvance(1)"><img src="' + cikk_gallery_elements[actImg] + '" width="' + w + '" height="' + h + '" border="0" alt="" /></a><br /><span class="egyes">' + cikk_gallery_elements_desc[actImg] + '</span></td>' + 
				'<td><a href="javascript:imgadvance(1)"><img src="/data/images/nextimg.gif" width="22" height="22" border="0" alt="" /></a></td></tr></table>';
				document.getElementById('slidecontainer').innerHTML = innercontainerstring;
			});
		});
		
		$('#blackoverlay').click(function() {
			$('#slidecontainer').remove();
			$('#blackoverlay').remove();
			$(document).unbind('keydown');
		});
		
		$(document).keydown(function(event) {
			if (event.keyCode == 27) {
				$('#slidecontainer').remove();
				$('#blackoverlay').remove();
				$(document).unbind('keydown');
			} 
		});
		
	}
	nextImage.src = cikk_gallery_elements[actImg]; 
}


function jq_update_layer(tartalom) {
	$("#" + jqtargetlayer).html(tartalom);
}


function alert_overlay(msg) {
   	w = 400;
	h = 100;
	var arrPageSizes = getPageSize();
	posx = Math.round((arrPageSizes[2]-w)/2);
	if (posx < 0) posx = 0;
	posy = arrPageSizes[5] + Math.round(arrPageSizes[3]/2 - h/2);
	if (posy < 0) posy = 0;
	out = '<div class="overlaywarning" id="overlaywarning" style="position: absolute; display: none; z-index: 100; left: ' + posx + 'px; top: ' + posy + 'px; width: 400px; height: 100px; text-align: center; ">'; // </div>
	out += '<p align="center">' + msg + '</p><p><input type="button" name="" value="OK" onclick="$(\'#warningunderlay\').click();" class="button" /></p></div>';
	$('body').append('<div id="warningunderlay" class="popupunderlay"></div>');
	$('body').append(out);
	$('#warningunderlay').css({
		opacity:			0.8,
		width:				arrPageSizes[0],
		height:				arrPageSizes[1]
	}).fadeIn("fast", function() {
		$('#overlaywarning').fadeIn("fast");

	});

	$('#warningunderlay').click(function() {
		$('#overlaywarning').remove();
		$('#warningunderlay').remove();
	});
}



function ajax_tool(to, vars, targetlayer, msg) {
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			resp = xmlhttp.responseText;
			if (targetlayer == "inline_gallery_container") {
				gallery_elements = new Array();
				tmparr = resp.split("<sep>");
				for (i=0; i<tmparr.length; i++) {
					tmpcells = tmparr[i].split(";");
					gallery_elements[i] = tmpcells[0];
				}
				open_inline_gallery();
				target = "";
				resp = "";
				targetlayer = "";
			}
			if (targetlayer != "") {
				if (resp != "0") {
					$('#' + targetlayer).html(resp);
					if (msg != "") alert_overlay(msg);
				} else alert_overlay(msg);
			} else if (resp != "") alert_overlay(resp);
		}
	}
	xmlhttp.open("POST", to, true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send(vars);
}


var gallery_elements = Array();
var maxImg = 0;
var actImg = 0;
function inline_gallery_advance(d) {
	nextImg = actImg;
	maxImg = gallery_elements.length - 1;
	nextImg += d;
	if (nextImg > maxImg) nextImg = 1;
	if (nextImg < 1) nextImg = maxImg;
	if (nextImg != actImg) {
		actImg = nextImg;
		var nextImage = new Image();
		// document.getElementById('gallerycontainer').innerHTML = '<table style="width: 100%; height: 100%; "><tr><td align="center"><img src="/images/loading.gif" width="32" height="32" border="0" alt="Töltés..." title="Töltés..." /></td></tr></table>';
		nextImage.onload = function() {
			$('#inline_gallery_element').fadeOut('fast', function(){
				var w = this.width;
				var h = this.height;
				var arrPageSizes = getPageSize();
				$(this).attr({src: gallery_elements[actImg], width: w, height: h});
				$(this).fadeIn('fast');
			});

		}
		nextImage.src = gallery_elements[actImg];
	}
}



function open_inline_gallery() {
	cw = $('#inline_gallery_container').width();
	ch = $('#inline_gallery_container').height();
	poz = $('#inline_gallery_container').offset();
	cx = poz.left;
	cy = poz.top;
	inline_gallery_container
	$('#inline_gallery_container').css({ width: cw + 'px', height: ch + 'px', overflow: 'hidden'});
	html = '<a href="javascript:inline_gallery_advance(-1)"><img src="/data/images/previmg3.png" width="22" height="22" border="0" alt="" style="position: absolute; z-index: 5; width: 22px; height: 22px; ';
	html += 'top: ' + (cy + Math.round(ch/2) - 11) + 'px; left: ' + (cx + 10) + 'px; "/></a>';
	html += '<a href="javascript:inline_gallery_advance(1)"><img src="/data/images/nextimg3.png" width="22" height="22" border="0" alt="" style="position: absolute; z-index: 5; width: 22px; height: 22px; ';
	html += 'top: ' + (cy + Math.round(ch/2) - 11) + 'px; left: ' + (cx + cw - 32) + 'px; "/></a>';
	$('body').append(html);

	var nextImage = new Image();
	actImg = 1;
	nextImage.onload = function(){
		var w = this.width;
		var h = this.height;
		var arrPageSizes = getPageSize();
		posx = Math.abs(Math.round((arrPageSizes[2]-w-44)/2));
		posy = arrPageSizes[5] + Math.abs(Math.round(arrPageSizes[3]/2 - h/2 - 30));
		$('#inline_gallery_container').html('');
		html = '<a href="javascript:inline_gallery_advance(1)"><img src="' + gallery_elements[actImg] + '" width="' + w + '" height="' + h + '" border="0" alt="" align="absmiddle" id="inline_gallery_element" /></a></div>';
		$('#inline_gallery_container').html(html);
	}
	nextImage.src = gallery_elements[actImg];
}

// document.oncontextmenu = RightClicker;
