// javascript gallery 1.9
// Copyright (c) 2007 IRQ Internet Kft. All rights reserved.
GalleryViewer = {
	win : window,
	border : 5,
	bezar_margin : 5,
	frame_border : 1,
	margin : 4,
	nav_margin : 32,
	indicator_width : 70,
	indicator_height : 10,
	nyil_width : 74,
	nyil_height : 32,
	nyil_margin : 7,
	min_width : 100,
	min_height : 100,
	view_delay : 10,
	view_steps : 40,
	pos_on_frame : false,
	pos_on_nav : true,
	speed_num : 5,
	slideshow_def_speed : 3,
	panel_width : 501,
	panel_height : 45,
	nav_width : 501,
	nav_height : 45,
	speed_left : 262,
	speed_top : 22,
	pos_width : 70,
	pos_left : 255,
	pos_top : 8,
	pos_color : '#000',
	blackbg : true,
	disable_alairas : false,
	megjelenes_szamolas : false,

	kepek : new Array(),
	leirasok : new Array(),
	kodok : new Array(),
	open : false,
	darab : 0,
	slideshow_wait : 0,
	ajaxload : false,
	getWinWidth : function() {
		var w = this.win.innerWidth;
		if(w==undefined || w===0 || isNaN(w))
			w = this.win.document.documentElement.clientWidth;
		if(w==undefined || w===0 || isNaN(w))
			w = this.win.document.body.clientWidth;
		return w;
	},
	getWinHeight : function() {
		var h = this.win.innerHeight;
		if(h==undefined || h===0 || isNaN(h))
			h = this.win.document.documentElement.clientHeight;
		if(h==undefined || h===0 || isNaN(h))
			h = this.win.document.body.clientHeight;
		return h;
	},
	getScrollLeft : function() {
		var l = this.win.pageXOffset;
		if(l==undefined || l===0)
			l = this.win.document.documentElement.scrollLeft;
		if(l==undefined || l===0)
			l = this.win.document.body.scrollLeft;
		return l;
	},
	getScrollTop : function() {
		var t = this.win.pageYOffset;
		if(t==undefined || t===0)
			t=this.win.document.documentElement.scrollTop;
		if(t==undefined || t===0)
			t=this.win.document.body.scrollTop;
		return t;
	},
	getDocWidth : function() {
		var w=0, i;
		i = this.win.document.documentElement.offsetWidth;
		if (i>w) w = i;
		i = this.win.document.documentElement.scrollWidth;
		if (i>w) w = i;
		i = this.win.document.body.offsetWidth;
		if (i>w) w = i;
		i = this.win.document.body.scrollWidth;
		if (i>w) w = i;
		return w;
	},
	getDocHeight : function() {
		var h=0, i;
		i = this.win.document.documentElement.offsetHeight;
		if (i>h) h = i;
		i = this.win.document.documentElement.scrollHeight;
		if (i>h) h = i;
		i = this.win.document.body.offsetHeight;
		if (i>h) h = i;
		i = this.win.document.body.scrollHeight;
		if (i>h) h = i;
		return h;
	},
	panel_poz : function() {
		if (this.panel!=undefined) {
			this.panel.style.left = Math.round(this.getWinWidth()/2-parseInt(this.panel.style.width)/2)+this.getScrollLeft()+'px';
			this.panel.style.top = this.getWinHeight()-parseInt(this.panel.style.height)-this.nav_margin+this.getScrollTop()+'px';
		}
	},
	viewer_poz : function() {
		if (!this.open)
			return;
		var descheight = 0;
		var width = this.getWinWidth()-this.border*2-this.frame_border*2-this.margin*2;
		var fullheight = this.getWinHeight()-this.border*2-this.frame_border*2-(this.panel!=undefined ? parseInt(this.panel.style.height)+this.nav_margin : 0)-this.margin*2-this.border;
		var height, nwidth=this.kep_width, nheight=this.kep_height, loop;
		if (width < this.min_width)
			width = this.min_width;
		do {
			height = fullheight-descheight;
			if (height < this.min_height)
				height = this.min_height;
			if (nwidth > width) {
				nheight = nheight * width / nwidth;
				nwidth = width;
			}
			if (nheight > height) {
				nwidth = nwidth * height / nheight;
				nheight = height;
			}
			this.view.style.width = Math.round(nwidth+this.border*2)+'px';
			this.view2.style.width = Math.round(nwidth+this.border*2)+'px';
			this.view.style.height = Math.round(nheight+this.border*2+this.leiras_y)+'px';
			this.view2.style.height = Math.round(nheight+this.border*2+this.leiras_y)+'px';
			if (descheight < this.desc.offsetHeight) {
				descheight+=1;
				loop = true;
			} else
				loop = false;
			if (nwidth < this.min_width || nheight < this.min_height || descheight > nheight)
				loop = false;
		} while (loop);
		if (this.iframe!=undefined) {
			this.iframe.style.width = parseInt(this.view.style.width)+this.frame_border*2+'px';
			this.iframe.style.height = parseInt(this.view.style.height)+this.frame_border*2+'px';
		}
		this.kep.width = Math.round(nwidth);
		this.kep.height = Math.round(nheight);

		this.kep.style.left = this.border+'px';
		this.kep.style.top = this.border+'px';
		if (this.blackbg) {
			this.viewbg.style.left = this.kep.style.left;
			this.viewbg.style.top = this.kep.style.top;
			this.viewbg.style.width = this.kep.width+'px';
			this.viewbg.style.height = this.kep.height+'px';
		}
		this.view.style.left = Math.round(width/2-this.kep.width/2)+this.margin+this.getScrollLeft()+'px';
		this.view2.style.left = Math.round(width/2-this.kep.width/2)+this.margin+this.getScrollLeft()+'px';
		this.view.style.top = Math.round(height/2-this.kep.height/2)+this.margin+this.getScrollTop()+'px';
		this.view2.style.top = Math.round(height/2-this.kep.height/2)+this.margin+this.getScrollTop()+'px';
		if (this.iframe!=undefined) {
			this.iframe.style.left = this.view.style.left;
			this.iframe.style.top = this.view.style.top;
		}
		this.desc.style.marginTop = parseInt(this.kep.style.top)+this.kep.height+'px';

		this.elozo.style.left = this.nyil_margin+'px';
		this.elozo.style.top = Math.round(parseInt(this.view.style.height)/2-this.nyil_height/2)+'px';
		this.kovetkezo.style.left = parseInt(this.view.style.width)-this.nyil_margin-this.nyil_width+'px';
		this.kovetkezo.style.top = this.elozo.style.top;

		this.bezar.style.left = parseInt(this.view.style.width)-this.bezar.width-this.bezar_margin+'px';
		this.bezar.style.top = this.bezar_margin+'px';
	},
	getEventTarget : function(event) {
		if (event==undefined)
			return undefined;
		if (event.srcElement!=undefined)
			return event.srcElement;
		else
			return event.target;
	},
	getEvent : function(event) {
		return (event!=undefined ? event : window.event);
	},
	blurElement : function(event) {
		var target = GalleryViewer.getEventTarget(GalleryViewer.getEvent(event));
		if (target!=undefined && target.blur)
			target.blur();
	},
	addEvent : function(obj, evType, fn) {
		if (obj.addEventListener) {
			obj.addEventListener(evType, fn, false);
			return true;
		} else if (obj.attachEvent) {
			var r = obj.attachEvent("on"+evType, fn);
			return r;
		} else {
	   		return false;
	 	}
	},
	removeEvent : function(obj, evType, fn) {
		if (obj.removeEventListener) {
			obj.removeEventListener(evType, fn, false);
			return true;
		} else if (obj.detachEvent) {
			var r = obj.detachEvent("on"+evType, fn);
			return r;
		} else {
	   		return false;
	 	}
	},
	myHandleKey : function(event) {
		if (!GalleryViewer.open)
			return;
		event = GalleryViewer.getEvent(event);
		if (event.ctrlKey || event.altKey)
			return true;
		var keyCode = event.keyCode;
		switch (keyCode) {
			case 37 : GalleryViewer.previous(); break;
			case 39 : GalleryViewer.next(); break;
			case 32 : case 13 : GalleryViewer.slideshow(); break;
			case 27 : GalleryViewer.close(); break;
			default : return true;
		}
		return false;
	},
	myResize : function(event) {
		if (!GalleryViewer.open)
			return;
		event = GalleryViewer.getEvent(event);
		GalleryViewer.panel_poz();
		GalleryViewer.viewer_poz();
		GalleryViewer.back.style.width = GalleryViewer.getDocWidth()+'px';
		GalleryViewer.back.style.height = GalleryViewer.getDocHeight()+'px';
	},
	myScroll : function(event) {
		if (!GalleryViewer.open)
			return;
		event = GalleryViewer.getEvent(event);
		GalleryViewer.panel_poz();
		GalleryViewer.viewer_poz();
	},
	mouseOffsetX : function(event) {
		if (event && event.offsetX!=undefined)
			return event.offsetX;
		else if (event && event.layerX)
			return event.layerX;
		else
			return -1;
	},
	mouseOffsetY : function(event) {
		if (event && event.offsetY && event.offsetY!=undefined)
			return event.offsetY;
		else if (event && event.layerY)
			return event.layerY;
		else
			return -1;
	},
	setOpacity : function(a, o) {
		if (a.style.opacity!=undefined)
			a.style.opacity = o;
		else
			a.style.filter = 'Alpha(Opacity='+(o*100)+', Style=0)';
	},
	Show : function(pos, tip) {
		this.kepek = Array();
		this.leirasok = Array();
		this.kodok = eval('gallery_'+tip);
		this.ajaxload = true;
		this.darab = this.kodok.length;
		this.create(pos);
	},
	create : function(pos) {
		this.flash_hidden();

		this.slideshow_on = false;
		this.loading = false;
		this.preloading = false;
		this.kep = undefined;
		this.elozokep = undefined;
		this.leiras_y = 0;
		this.timeout = undefined;
		this.monnyil = false;
		this.tonnyil = undefined;

		this.pos = pos==undefined ? 0 : pos;

		this.back = document.createElement('div');
		this.back.style.position = 'absolute';
		this.back.style.left = '0px';
		this.back.style.top = '0px';
		this.back.style.width = this.getDocWidth()+'px';
		this.back.style.height = this.getDocHeight()+'px';
		this.back.style.backgroundColor = '#000';
		this.back.onclick = function() { GalleryViewer.close(); };
		this.back.onmouseover = function() { if (GalleryViewer.bezar && GalleryViewer.bezar.style.visibility=='visible') GalleryViewer.bezar.style.visibility='hidden'; if (GalleryViewer.elozo && GalleryViewer.elozo.style.visibility=='visible') GalleryViewer.elozo.style.visibility='hidden'; if (GalleryViewer.kovetkezo && GalleryViewer.kovetkezo.style.visibility=='visible') GalleryViewer.kovetkezo.style.visibility='hidden'; };
		this.setOpacity(this.back, 0.5);
		this.back.style.zIndex = 10000;
		document.body.appendChild(this.back);

		if (navigator.userAgent.indexOf('Opera')!=-1 && parseFloat(navigator.appVersion)<=4) {
			this.iframe = undefined;
		} else {
			this.iframe = document.createElement('iframe');
			this.iframe.style.position = 'absolute';
			this.iframe.style.background = '#fff';
			this.iframe.style.border = 'none';
			this.iframe.frameBorder = 0;
			this.iframe.style.visibility = 'hidden';
			this.iframe.style.zIndex = 10001;
			document.body.appendChild(this.iframe);
		}

		this.view = document.createElement('div');
		this.view.style.position = 'absolute';
		//this.view.style.background = '#fff';
		this.view.style.backgroundImage = 'url(art/kepkeret1024.gif)';
		this.view.style.backgroundPosition = 'top left';
		this.view.style.backgroundRepeat = 'no-repeat';
		this.view.style.textAlign = 'left';
		this.view.style.border = this.frame_border+'px solid #000';
		this.view.style.overflow = 'hidden';
		this.view.style.visibility = 'hidden';
		this.view.style.zIndex = 10002;
		document.body.appendChild(this.view);

		this.view2 = document.createElement('div');
		this.view2.style.position = 'absolute';
		this.view2.style.background = '#000';
		this.view2.style.backgroundImage = 'url(art/kepkeret1024.gif)';
		this.view2.style.backgroundPosition = 'bottom right';
		this.view2.style.backgroundRepeat = 'no-repeat';
		this.view2.style.textAlign = 'left';
		this.view2.style.border = this.frame_border+'px solid #000';
		this.view2.style.overflow = 'hidden';
		this.view2.style.visibility = 'hidden';
		this.view2.style.zIndex = 10001;
		document.body.appendChild(this.view2);

		if (this.blackbg) {
			this.viewbg = document.createElement('div');
			this.viewbg.style.background = '#000';
			this.viewbg.style.position = 'absolute';
			this.view.appendChild(this.viewbg);
		}

		if (this.darab > 1 || this.ajaxload) {
			this.panel = document.createElement('div');
			this.panel.style.position = 'absolute';
			this.panel.style.width = this.panel_width+'px';
			this.panel.style.height = this.panel_height+'px';
			this.panel_poz();
			this.panel.style.textAlign = 'center';
			this.panel.style.zIndex = 10002;
			document.body.appendChild(this.panel);

			this.nav = document.createElement('img');
			this.nav.style.width = this.nav_width+'px';
			this.nav.style.height = this.nav_height+'px';
			this.update_navbar();
			this.nav.useMap = "#gallery_viewer_navbar";
			this.nav.style.border = "none";
			this.panel.appendChild(this.nav);

			var areas = [];
			areas.push(["GalleryViewer.first()","rectangle","9, 8, 34, 34","Első kép"]);
			areas.push(["GalleryViewer.previous()","rectangle","49, 8, 74, 34","Előző kép"]);
			areas.push(["GalleryViewer.slideshow()","rectangle","90, 4, 126, 39","Diavetítés"]);
			areas.push(["GalleryViewer.next()","rectangle","141, 8, 166, 34","Következő kép"]);
			areas.push(["GalleryViewer.last()","rectangle","180, 8, 205, 34","Utolsó kép"]);
			areas.push(["GalleryViewer.mailto()","rectangle","376, 8, 402, 34","Kép linkjének küldése e-mailben"]);
			areas.push(["GalleryViewer.link()","rectangle","417, 8, 442, 34","Megnyitás új ablakban"]);
			areas.push(["GalleryViewer.close()","rectangle","456, 9, 482, 34","Bezárás"]);

			this.map = document.createElement("map");
			this.map.name = "gallery_viewer_navbar";
			this.map.id = "gallery_viewer_navbar";
			var i;
			this.area = new Array();
			this.area_length = areas.length;
			for(i = 0; i < areas.length; i++) {
				this.area[i] = document.createElement("area");
				this.area[i].href = "javascript:void("+areas[i][0]+")";
				this.area[i].shape = areas[i][1];
				this.area[i].coords = areas[i][2];
				this.area[i].alt = this.area[i].title = areas[i][3];
				this.area[i].onclick = this.blurElement;
				this.map.appendChild(this.area[i]);
			}
			this.panel.appendChild(this.map);

			this.speed = document.createElement('img');
			this.speed.style.position = 'absolute';
			this.speed.style.left = this.speed_left+'px';
			this.speed.style.top = this.speed_top+'px';
			this.speed.style.cursor = 'pointer';
			this.speed.alt = this.speed.title = 'Diavetítés sebessége';
			this.speed.onclick = function(event) {
				event = GalleryViewer.getEvent(event);
				GalleryViewer.slideshow_def_speed = Math.floor(GalleryViewer.mouseOffsetX(event) / this.width * GalleryViewer.speed_num) + 1;
				GalleryViewer.setSpeed(GalleryViewer.slideshow_def_speed);
			};
			this.setSpeed(this.slideshow_def_speed);
			this.panel.appendChild(this.speed);

			if (this.pos_on_nav) {
				this.pos_nav = document.createElement('div');
				this.pos_nav.style.position = 'absolute';
				this.pos_nav.style.width = this.pos_width+'px';
				this.pos_nav.style.left = this.pos_left+'px';
				this.pos_nav.style.top = this.pos_top+'px';
				this.pos_nav.style.textAlign = 'center';
				this.pos_nav.style.fontFamily = 'verdana';
				this.pos_nav.style.fontSize = '10px';
				this.pos_nav.style.fontWeight = 'normal';
				this.pos_nav.style.color = this.pos_color;
				this.pos_nav.innerHTML = '';
				this.panel.appendChild(this.pos_nav);
			}
		} else {
			this.panel = undefined;
			this.nav = undefined;
			this.map = undefined;
			this.area_length = 0;
			this.pos_nav = undefined;
			this.speed = undefined;
		}

		this.desc = document.createElement('div');
		this.desc.style.marginLeft = this.border+'px';
		this.desc.style.marginRight = this.border+'px';
		this.desc.style.paddingLeft = '0px';
		this.desc.style.paddingRight = '0px';
		this.desc.style.paddingTop = this.border+'px';
		this.desc.style.paddingBottom = '0px';
		this.desc.style.fontFamily = 'verdana';
		this.desc.style.fontSize = '10px';
		this.desc.style.fontWeight = 'bold';
		this.desc.style.color = '#777';
		this.desc.style.visibility = 'hidden';
		this.desc.innerHTML = '';
		this.view.appendChild(this.desc);

		this.elozo = document.createElement('img');
		this.elozo.style.width = this.nyil_width+'px';
		this.elozo.style.height = this.nyil_height+'px';
		this.elozo.style.position = 'absolute';
		this.elozo.style.visibility = 'hidden';
		this.elozo.style.cursor = 'pointer';
		this.elozo.style.zIndex = 1000;
		this.elozo.alt = this.elozo.title = 'Előző kép';
		this.elozo.src = 'art/gallery/prev.gif';
		this.elozo.onmousemove = function() { GalleryViewer.monnyil = true; };
		this.elozo.onclick = function() { if (this.style.visibility == 'visible') GalleryViewer.previous(); };
		this.view.appendChild(this.elozo);

		this.kovetkezo = document.createElement('img');
		this.kovetkezo.style.width = this.nyil_width+'px';
		this.kovetkezo.style.height = this.nyil_height+'px';
		this.kovetkezo.style.position = 'absolute';
		this.kovetkezo.style.visibility = 'hidden';
		this.kovetkezo.style.cursor = 'pointer';
		this.kovetkezo.style.zIndex = 1000;
		this.kovetkezo.alt = this.kovetkezo.title = 'Következő kép';
		this.kovetkezo.src = 'art/gallery/next.gif';
		this.kovetkezo.onmousemove = function() { GalleryViewer.monnyil = true; };
		this.kovetkezo.onclick = function() { if (this.style.visibility == 'visible') GalleryViewer.next(); };
		this.view.appendChild(this.kovetkezo);

		this.bezar = document.createElement('img');
		this.bezar.src = 'art/gallery/exit.gif';
		this.bezar.style.position = 'absolute';
		this.bezar.style.zIndex = 1000;
		this.bezar.alt = this.bezar.title = 'Bezárás';
		this.bezar.style.cursor = 'pointer';
		this.bezar.style.visibility = 'hidden';
		this.bezar.onmousemove = function() { GalleryViewer.monnyil = true; if (GalleryViewer.kovetkezo.style.visibility=='visible') GalleryViewer.kovetkezo.style.visibility='hidden'; if (GalleryViewer.elozo.style.visibility=='visible') GalleryViewer.elozo.style.visibility='hidden'; };
		this.bezar.onmouseover = function() { this.src='art/gallery/exit2.gif'; };
		this.bezar.onmouseout = function() { this.src='art/gallery/exit.gif'; };
		this.bezar.onclick = function() { if (this.style.visibility == 'visible') GalleryViewer.close(); };
		this.view.appendChild(this.bezar);

		this.indicator = document.createElement('img');
		this.indicator.src = 'art/gallery/indicator.gif';
		this.indicator.style.position = 'absolute';
		this.indicator.style.visibility = 'hidden';
		this.indicator.width = this.indicator_width;
		this.indicator.height = this.indicator_height;
		this.indicator.old_scrollTop = this.getScrollTop();
		this.indicator.old_scrollLeft = this.getScrollLeft();
		this.indicator.style.left = Math.round(this.getWinWidth()/2-this.indicator.width/2)+'px';
		this.indicator.style.top = Math.round((this.getWinHeight()-(this.panel!=undefined ? parseInt(this.panel.style.height) : 0))/2-this.indicator.height/2)+'px';
		this.indicator.style.zIndex = 10003;
		document.body.appendChild(this.indicator);

		this.open = true;

		this.go();

		this.addEvent(this.win, "resize", this.myResize);
		this.addEvent(this.win, "scroll", this.myScroll);
		this.addEvent(this.win.document, "keydown", this.myHandleKey);

	},
	go : function() {
		this.preloading = true;
		this.indicator.src = this.indicator.src;
		this.indicator.style.left = parseInt(this.indicator.style.left)+this.indicator.old_scrollLeft-this.getScrollLeft()+'px';
		this.indicator.style.top = parseInt(this.indicator.style.top)+this.indicator.old_scrollTop-this.getScrollTop()+'px';
		setTimeout("if (GalleryViewer.preloading && GalleryViewer.indicator && GalleryViewer.indicator.style) GalleryViewer.indicator.style.visibility='visible';", 250);

		if (this.ajaxload) {
			var xmlHttpReq = false;
			if (window.XMLHttpRequest)
				xmlHttpReq = new XMLHttpRequest();
			// IE
			else if (window.ActiveXObject)
				xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			xmlHttpReq.open("POST", "mod_gallery_ajax.php", true);
			xmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xmlHttpReq.onreadystatechange = function() {
				if (xmlHttpReq.readyState == 4) {
					var a = xmlHttpReq.responseText.split('|');
					GalleryViewer.kepek[GalleryViewer.pos] = unescape(a[1]);
					GalleryViewer.leirasok[GalleryViewer.pos] = unescape(a[2]);
					GalleryViewer.go_kep();
				}
			}
			xmlHttpReq.send("kod="+this.kodok[this.pos]);
		} else {
			this.go_kep();
		}
	},
	go_kep : function() {
		if (this.loading) {
			if (this.elozokep) {
				this.elozokep.onclick = null;
				this.elozokep.onmousemove = null;
				this.elozokep.onmouseout = null;
				this.view.removeChild(this.elozokep);
				delete(this.elozokep);
				this.elozokep = undefined;
			}
			this.kep.onload = function() {};
		}
		this.elozo.style.visibility = 'hidden';
		this.kovetkezo.style.visibility = 'hidden';
		this.loading = true;
		if (this.kep) {
			this.panel_poz();
			this.viewer_poz();
		}

		this.elozokep = this.kep;
		this.kep = document.createElement('img');
		this.kep.style.visibility = 'hidden';
		this.kep.style.position = 'absolute';
		this.kep.main = this;
		this.kep.onload = this.loaded;
		this.kep.src = this.kepek[this.pos];
		this.view.appendChild(this.kep);
		this.update_navbar();
	},
	loaded : function() {
		if (!this.main.open || !this.main.desc)
			return;
		this.main.desc.innerHTML = (this.main.pos_on_frame&&this.main.darab>1 ? '<span style="float: right; font-weight: normal;">&nbsp;'+(this.main.pos+1)+'/'+this.main.darab+'</span>' : '') + (this.main.leirasok[this.main.pos]!='' ? this.main.leirasok[this.main.pos]+'<br style="clear: both;" />' : '');

		if (this.main.desc.innerHTML!='') {
			this.main.desc.style.background='#fff';
			this.main.desc.style.marginLeft = '0px';
			this.main.desc.style.marginRight = '0px';
			this.main.desc.style.paddingLeft = this.main.border+'px';
			this.main.desc.style.paddingRight = this.main.border+'px';
			this.main.desc.style.paddingTop = this.main.border/2+'px';
			this.main.desc.style.paddingBottom = this.main.border/2+'px';
			/*this.main.desc.style.borderBottom = '1px solid #90726a';
			this.main.desc.style.borderLeft = '1px solid #90726a';
			this.main.desc.style.borderRight = '1px solid #90726a';
			this.main.desc.style.borderTop = '1px solid #90726a';*/
		} else {
			this.main.desc.style.background='none';
			this.main.desc.style.marginLeft = this.main.border+'px';
			this.main.desc.style.marginRight = this.main.border+'px';
			this.main.desc.style.paddingLeft = '0px';
			this.main.desc.style.paddingRight = '0px';
			this.main.desc.style.paddingTop = this.main.border+'px';
			this.main.desc.style.paddingBottom = '0px';
			this.main.desc.style.borderBottom = 'none';
			this.main.desc.style.borderLeft = 'none';
			this.main.desc.style.borderRight = 'none';
			this.main.desc.style.borderTop = 'none';
		}

		if (this.main.pos_nav!=undefined && this.main.pos_on_nav)
			this.main.pos_nav.innerHTML = (this.main.pos+1)+'/'+this.main.darab;
		this.main.kep_width = this.width;
		this.main.kep_height = this.height;

		if (this.main.elozokep != undefined)
			this.main.elozokep.style.visibility = 'hidden';

		this.main.view.style.visibility = 'hidden';
		this.main.view2.style.visibility = 'hidden';
		if (this.main.iframe!=undefined)
			this.main.iframe.style.visibility = 'hidden';
		this.main.desc.style.visibility = 'hidden';
		this.style.visibility = 'hidden';

		this.main.leiras_y = 0;
		this.main.viewer_poz();
		this.main.panel_poz();

		this.main.setOpacity(this, 0);

		this.main.desc.style.visibility = 'visible';
		this.style.visibility = 'visible';
		if (this.main.iframe!=undefined)
			this.main.iframe.style.visibility = 'visible';
		this.main.view.style.visibility = 'visible';
		this.main.view2.style.visibility = 'visible';

		this.main.loading = false;
		this.main.preloading = false;

		this.main.indicator.style.visibility = 'hidden';
		this.main.indicator.style.left = parseInt(this.main.view.style.left)+Math.round(400-parseInt(this.main.indicator.width)/2)+'px';
		this.main.indicator.style.left = parseInt(this.main.view.style.left)+'px';
		this.main.indicator.style.left = parseInt(this.main.view.style.left)+Math.round(parseInt(this.main.view.style.width)/2-this.main.indicator.width/2)+'px';
		this.main.indicator.style.top = parseInt(this.main.view.style.top)+Math.round(parseInt(this.main.view.style.height)/2-this.main.indicator.height/2)+'px';
		this.main.indicator.old_scrollLeft = this.main.getScrollLeft();
		this.main.indicator.old_scrollTop = this.main.getScrollTop();

		this.onclick = function(event,e) {
			event = GalleryViewer.getEvent(event);
			var x = this.main.mouseOffsetX(event);
			if (x > 0)
				if (x < this.width/2) {
					this.main.previous();
				} else {
					this.main.next();
				}
		};
		this.onmousemove = function(event) {
			if (this.main.tonnyil!=undefined) {
				clearTimeout(this.main.tonnyil);
				this.main.tonnyil = undefined;
			}
			this.main.monnyil = false;
			var elozo = this.main.elozo.style.visibility;
			var kovetkezo = this.main.kovetkezo.style.visibility;
			var cursor = this.style.cursor;
			if (this.main.loading) {
				elozo = 'hidden';
				kovetkezo = 'hidden';
				cursor = 'default';
			} else {
				event = GalleryViewer.getEvent(event);
				var x = this.main.mouseOffsetX(event);
				if (x > 0)
					if (x < this.width/2) {
						elozo = this.main.pos>0 ? 'visible' : 'hidden';
						kovetkezo = 'hidden';
						cursor = elozo=='visible' ? 'pointer' : 'default';
					} else {
						elozo = 'hidden';
						kovetkezo = this.main.pos+1<this.main.darab ? 'visible' : 'hidden';
						cursor = kovetkezo=='visible' ? 'pointer' : 'default';
					}
			}
			if (this.main.elozo.style.visibility!=elozo)
				this.main.elozo.style.visibility = elozo;
			if (this.main.kovetkezo.style.visibility!=kovetkezo)
				this.main.kovetkezo.style.visibility = kovetkezo;
			if (this.style.cursor!=cursor)
				this.style.cursor = cursor;

			if (this.main.bezar.style.visibility!='visible')
				this.main.bezar.style.visibility = 'visible';
		};
		this.onmouseout = function(event) {
			this.main.tonnyil = setTimeout("if (!GalleryViewer.monnyil) { GalleryViewer.elozo.style.visibility = 'hidden'; GalleryViewer.kovetkezo.style.visibility = 'hidden'; GalleryViewer.bezar.style.visibility = 'hidden'; GalleryViewer.tonnyil = undefined; }", 100);
		};

		if (this.main.elozokep != undefined) {
			this.main.elozokep.onclick = null;
			this.main.elozokep.onmousemove = null;
			this.main.elozokep.onmouseout = null;
			this.main.view.removeChild(this.main.elozokep);
			delete(this.main.elozokep);
			this.main.elozokep = undefined;
		}

		if (this.main.slideshow_on) {
			if (this.main.timeout!=undefined)
				this.main.win.clearTimeout(this.main.timeout);
			if (this.main.pos + 1 < this.main.darab)
				this.main.timeout = this.main.win.setTimeout("GalleryViewer.timer()", this.main.slideshow_wait);
			else {
				this.main.slideshow_stop();
			}
		}

		var tim = new Date();
		this.main.poztim = tim.getTime();
		setTimeout("GalleryViewer.leiras_poz()", this.main.view_delay);

		if (this.main.megjelenes_szamolas && this.main.kodok[this.main.pos]!='' && !this.main.ajaxload)
			this.main.megjelenes_ajax(this.main.kodok[this.main.pos]);
	},
	megjelenes_ajax : function(kod) {
		var xmlHttpReq = false;
		if (window.XMLHttpRequest)
			xmlHttpReq = new XMLHttpRequest();
		// IE
		else if (window.ActiveXObject)
			xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		xmlHttpReq.open("POST", "mod_gallery_ajax.php", true);
		xmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttpReq.onreadystatechange = function() {
			if (xmlHttpReq.readyState == 4) {/*xmlHttpReq.responseText*/}
		}
		xmlHttpReq.send("kod="+kod);
	},
	leiras_poz : function() {
		if (this.open && !this.loading && this.leiras_y < this.desc.offsetHeight) {
			var tim = new Date();
			var step = Math.floor((tim - this.poztim) / this.view_delay);
			if (step > this.view_steps)
				step = this.view_steps;
			if (this.desc.innerHTML != '') {
				this.leiras_y = Math.round(this.desc.offsetHeight * step / this.view_steps);
				this.view.style.height = this.kep.height+this.border*2+this.leiras_y+'px';
				//this.view2.style.height = this.kep.height+this.border*2+this.leiras_y+'px';
				this.desc.style.marginTop = parseInt(this.kep.style.top)+this.kep.height+this.desc.offsetHeight-this.leiras_y+this.border+'px';
			}
			if (step < this.view_steps) {
				this.setOpacity(this.kep, Math.round(step / this.view_steps * 100) / 100);
				setTimeout("GalleryViewer.leiras_poz()", this.view_delay);
			} else {
				if (this.iframe!=undefined)
					this.iframe.style.height = this.kep.height+this.border*2+this.leiras_y+'px';
				this.setOpacity(this.kep, 0.99);
			}
		}
	},
	update_navbar : function() {
		if (this.panel==undefined)
			return;
		var s = this.slideshow_on ? 's' : '';
		var p;
		if (this.darab <= 1) {
			p = '0';
			s = '';
		} else if (this.pos == 0)
			p = '1';
		else if (this.pos + 1 == this.darab) {
			p = '3';
			s = '';
		} else
			p = '2';
		var src = 'art/gallery/toolbar'+p+s+'.png';
		if (this.nav.src!=src)
			this.nav.src=src;
	},
	setSpeed : function(i) {
		this.speed.src = 'art/gallery/speed'+i+'.gif';
		switch (i) {
			case 1 : this.slideshow_wait = 1000; break;
			case 2 : this.slideshow_wait = 2000; break;
			case 3 : this.slideshow_wait = 3000; break;
			case 4 : this.slideshow_wait = 5000; break;
			case 5 : this.slideshow_wait = 7500; break;
		}
		if (this.timeout!=undefined) {
			clearTimeout(this.timeout);
			this.timeout = this.win.setTimeout("GalleryViewer.timer()", this.slideshow_wait);
		}
	},
	first : function() {
		this.slideshow_stop();
		if (this.darab > 0 && this.pos != 0) {
			this.pos = 0;
			this.go();
		}
	},
	previous : function() {
		this.slideshow_stop();
		if (this.pos > 0) {
			this.pos--;
			this.go();
		}
	},
	next : function() {
		this.slideshow_stop();
		if (this.pos + 1 < this.darab) {
			this.pos++;
			this.go();
		}
	},
	last : function() {
		this.slideshow_stop();
		if (this.darab > 0 && this.pos != this.darab-1) {
			this.pos = this.darab-1;
			this.go();
		}
	},
	link : function() {
		this.win.open(this.kep.src, '_blank');
	},
	mailto : function() {
		this.win.location='mailto:?subject='+escape(this.leirasok[this.pos])+'&body='+escape(this.kep.src);
	},
	slideshow_stop : function() {
		if (this.slideshow_on) {
			this.slideshow_on = false;
			if (this.timeout!=undefined) {
				this.win.clearTimeout(this.timeout);
				this.timeout = undefined;
			}
			this.update_navbar();
		}
	},
	slideshow_start : function() {
		if (!this.slideshow_on && this.pos + 1 < this.darab) {
			this.slideshow_on = true;
			if (this.timeout!=undefined)
				this.win.clearTimeout(this.timeout);
			this.timeout = this.win.setTimeout("GalleryViewer.timer()", this.slideshow_wait);
			this.update_navbar();
		}
	},
	slideshow : function() {
		if (this.slideshow_on)
			this.slideshow_stop();
		else
			this.slideshow_start();
	},
	timer : function() {
		this.timeout = undefined;
		if (this.pos + 1 < this.darab) {
			this.pos++;
			this.go();
		}
	},
	close : function() {
		this.open = false;

		this.removeEvent(this.win, "resize", this.myResize);
		this.removeEvent(this.win, "scroll", this.myScroll);
		this.removeEvent(this.win.document, "keydown", this.myHandleKey);

		this.slideshow_stop();

		if (this.tonnyil!=undefined) {
			clearTimeout(this.tonnyil);
			this.tonnyil=undefined;
		}

		this.kep.onload = null;
		this.kep.onclick = null;
		this.kep.onmousemove = null;
		this.kep.onmouseout = null;

		if (this.elozokep != undefined) {
			this.elozokep.onclick = null;
			this.elozokep.onmousemove = null;
			this.elozokep.onmouseout = null;
			this.view.removeChild(this.elozokep);
			delete(this.elozokep);
			this.elozokep = undefined;
		}

		for(var i = 0; i < this.area_length; i++) {
			this.area[i].onclick = null;
			this.map.removeChild(this.area[i]);
			delete(this.area[i]);
		}
		if (this.panel!=undefined) {
			this.panel.removeChild(this.map);
			delete(this.map);
		}
		if (this.nav!=undefined) {
			this.panel.removeChild(this.nav);
			delete(this.nav);
		}
		if (this.pos_nav!=undefined) {
			this.panel.removeChild(this.pos_nav);
			delete(this.pos_nav);
		}
		if (this.speed!=undefined) {
			this.speed.onclick = null;
			this.panel.removeChild(this.speed);
			delete(this.speed);
		}
		if (this.panel!=undefined) {
			document.body.removeChild(this.panel);
			delete(this.panel);
		}
		this.kovetkezo.onmousemove = null;
		this.kovetkezo.onclick = null;
		this.view.removeChild(this.kovetkezo);
		delete(this.kovetkezo);
		this.elozo.onmousemove = null;
		this.elozo.onclick = null;
		this.view.removeChild(this.elozo);
		delete(this.elozo);
		this.bezar.onmousemove = null;
		this.bezar.onmouseover = null;
		this.bezar.onmouseout = null;
		this.bezar.onclick = null;
		this.view.removeChild(this.bezar);
		delete(this.bezar);
		this.view.removeChild(this.desc);
		delete(this.desc);
		if (this.blackbg) {
			this.view.removeChild(this.viewbg);
			delete(this.viewbg);
		}
		document.body.removeChild(this.indicator);
		delete(this.indicator);
		document.body.removeChild(this.view);
		document.body.removeChild(this.view2);
		delete(this.view);
		delete(this.view2);
		if (this.iframe!=undefined) {
			document.body.removeChild(this.iframe);
			delete(this.iframe);
		}
		this.back.onclick = null;
		document.body.removeChild(this.back);
		delete(this.back);

		this.flash_visible();
	},
	flash_hidden : function() {
		var tags=document.getElementsByTagName("div");
		for(var i=0; i<tags.length; i++) {
			if (tags[i].className=='flash' && tags[i].style.visibility!='hidden') {
				if (tags[i].orig_visibility==undefined)
					tags[i].orig_visibility=tags[i].style.visibility;
				tags[i].style.visibility='hidden';
			}
		}
	},
	flash_visible : function() {
		var tags=document.getElementsByTagName("div");
		for(var i=0; i<tags.length; i++)
			if (tags[i].orig_visibility!=undefined) {
				tags[i].style.visibility=tags[i].orig_visibility;
				tags[i].orig_visibility=undefined;
			}
	}
}
Gallery = function() {
	this.kepek = new Array();
	this.leirasok = new Array();
	this.kodok = new Array();
	this.add = function(kep, leiras, kod) {
		this.kepek.push(kep);
		this.leirasok.push(GalleryViewer.disable_alairas ? '' : (leiras!=undefined ? leiras : ''));
		this.kodok.push(kod);
	};
	this.show = function(pos) {
		if (!GalleryViewer.open && this.kepek.length>0) {
			GalleryViewer.kepek = this.kepek;
			GalleryViewer.leirasok = this.leirasok;
			GalleryViewer.kodok = this.kodok;
			GalleryViewer.ajaxload = false;
			GalleryViewer.darab = this.kepek.length;
			GalleryViewer.create(pos);
		}
	};
}
function galleryinit(){
	var children;
	var i, j, id, kep, kod, a, o, x = new Array();
	gallery = new Array();
	var tags=document.getElementsByTagName("a");
	for(i=0; i<tags.length; i++) {
		x = tags[i].id.split('_');
		if (x.length==3 && x[0]=="gallery" && x[2]=="0") {
			id = parseInt(x[1]);
			gallery[id] = new Gallery();
			j = 0;
			while (a=document.getElementById('gallery_'+x[1]+'_'+j)) {
				kep = a.getElementsByTagName("img");
				a.href = "javascript:void(gallery["+id+"].show("+j+"))";
				a.target = '';
				if (a.title && a.title.length>1 && a.title.substr(0, 1)=='#') {
					kod = a.title.substr(1);
					a.title = '';
				} else
					kod = '';
				gallery[id].add(kep[0].getAttribute('longdesc'), kep[0].getAttribute('alt'), kod);
				j++;
			}
		}
		if (tags[i].className=="galleryloader") {
			x = tags[i].title.split('_');
			tags[i].href = "javascript:GalleryViewer.Show("+parseInt(tags[i].title)+", '"+x[1]+"')";
			tags[i].target = '';
			if (typeof(window['gallery_'+x[1]])=="undefined" && x.length>1 && x[2]!=undefined && x[2]!='' && parseInt(x[2])!=0) {
				window['gallery_'+x[1]] = Array();
				window['gallery_'+x[1]][parseInt(tags[i].title)] = x[2];
			}
		}
	}
	var tags=document.getElementsByTagName("ul");
	for(i=0; i<tags.length; i++) {
		if(tags[i].className=="gallery") {
			id = parseInt(tags[i].id.split('_')[1]);
			gallery[id] = new Gallery();
			children = tags[i].getElementsByTagName("li");
			for(j=0; j<children.length; j++) {
				kep = children[j].getElementsByTagName("img");
				a = children[j].getElementsByTagName("a");
				if (kep.length!=0 && a.length!=0) {
					a[0].href = "javascript:void(gallery["+id+"].show("+j+"))";
					a[0].target = '';
					if (a[0].title && a[0].title.length>1 && a[0].title.substr(0, 1)=='#') {
						kod = a[0].title.substr(1);
						a[0].title = '';
					} else
						kod = '';
					gallery[id].add(kep[0].getAttribute('longdesc'), kep[0].getAttribute('alt'), kod);
				}
			}
		}
	}
}
addEvent(window, 'load', galleryinit);
