// JavaScript Document

function GalleryOnLoad(evType, fn) {
	if (typeof window.addEventListener != 'undefined') {
		window.addEventListener(evType, fn, false)
		//alert("GalleryOnLoad1");
	}
	else if (typeof document.addEventListener != 'undefined') {
		//alert("GalleryOnLoad2");
		document.addEventListener(evType, fn, false)
	}
	else if (typeof window.attachEvent != 'undefined') {
		//alert("GalleryOnLoad3; " + fn);
		window.attachEvent("on" + evType, fn)
	}
}

var uagent = window.navigator.userAgent.toLowerCase();
var IE = (uagent.indexOf('msie') != -1) ? true : false;
var images = new Array();
for (var i = 0; i < imgs.length; i++) {
	images[i] = new Image();
	images[i].src = path + "kepek/" + imgs[i];
}

function CW_SlideShow() {
	if (!document.getElementById || !document.getElementsByTagName) return false;
	this.Kep = document.getElementById("SlideShowKep");
	this.path = path;
	this.images = images;
	this.text = text;
	this.szelesseg = szelesseg;
	this.magassag = magassag;
	this.KepCut = null;
	this.Opac = 0.0;
	this.cut = "#444444";
	this.curr = readCookie("CurrentImage");
	this.next = 0;
	this.prev = 0;
	this.time = 10000; // a váltások közötti idő (2 mp)
	//this.proc = false;
	fuagent = window.navigator.userAgent.toLowerCase();
	this.fIEB=(fuagent.indexOf('msie') != -1)?true:false;
	this.timeout = null;

	return true;
}

CW_SlideShow.prototype = {
	
	init : function() {
		this.curr = ((this.curr == null) || (this.curr == "undefined")) ? 0 : this.curr;
		this.next = ((this.curr == null) || (this.curr == "undefined")) ? 0 : eval(this.curr + 1);
		this.prev = ((this.curr == null) || (this.curr == "undefined")) ? (this.images.length - 1) : eval(this.curr - 1);
		
		if (this.fIEB==true) {
			this.swap();
		}
		else {
			obj = document.getElementById("SlideShowKep");
			//obj.style.backgroundImage = "url(" + this.path + "images/slideshow.png)"; // Az első kép helyett a logoót töltjük be
			obj.style.backgroundImage = "url(" + this.path + "/gallery_kiskep.php?kepnev=images/slideshow.png&szelesseg=" + this.szelesseg + "&magassag=" + this.magassag + ")"; // Az első kép helyett a logoót töltjük be
			
			div = document.createElement('DIV');
			div.setAttribute("id", "SlideShowCut");
			//alert(this.text[this.kovetkezo()]);
			kovetkezo = this.kovetkezo();
			div.style.backgroundImage = "url(" + this.path + "/gallery_kiskep.php?kepnev=" + this.images[kovetkezo].src + "&szelesseg=" + this.szelesseg + "&magassag=" + this.magassag + ")";
			div.title = this.text[kovetkezo];
			div.style.opacity = 0.0;
			div.onmouseover = function() {KepOver()};
			div.onmouseout = function() {KepOut()};
			this.KepCut = div;
			obj.parentNode.appendChild(this.KepCut);
			
			my = this;
			setTimeout("my.show()", 200); // Az első képet hamarabb váltjuk mint ahogy a this.time meghatározza, mert az a logó: SlideShow felirat
			//setTimeout("my.show()", this.time);
		}
	},
	
	kovetkezo : function() {
		this.curr++;
		if (this.curr > (this.images.length - 1)) this.curr = 0;
		
		this.prev = eval(this.curr - 1);
		if (this.prev > (this.images.length - 1)) this.prev = 0;
		if (this.prev < 0) this.prev = (this.images.length - 1);
		
		this.next = eval(this.curr + 1);
		if (this.next > (this.images.length - 1)) this.next = 0;
		
		result = this.curr;
		return result;
	},
	
	elozo : function() {
		this.curr--;
		if (this.curr < 0) this.curr = (this.images.length - 1);
		
		this.prev = eval(this.curr - 1);
		if (this.prev < 0) this.prev = (this.images.length - 1);
		
		this.next = eval(this.curr + 1);
		if (this.next < 0) this.next = (this.images.length - 1);
		if (this.next > (this.images.length - 1)) this.next = 0;
		
		result = this.curr;
		return result;
	},
	
	swap : function(irany) { // IE slideshow
		my = this;
		this.Kep.filters[0].Apply();
		this.Kep.style.backgroundImage = "url(" + this.path + "/gallery_kiskep.php?kepnev=" + this.images[this.curr].src + "&szelesseg=" + this.szelesseg + "&magassag=" + this.magassag + ")";
		this.Kep.title = this.text[this.curr];
		this.kovetkezo();
		
		this.Kep.filters[0].Play();
		createCookie("CurrentImage",this.curr,7);
		this.timeout = setTimeout("my.swap()", this.time);
	},
	
	show : function() { // FF slideshow
		my = this;
		my.swapff();
		createCookie("CurrentImage",this.curr,7);
		this.timeout = setTimeout("my.show()", this.time);
	},
	
	swapff : function() {
		my = this;
		//alert(this.Opac);
		if (this.Opac < 1.0) {
			this.Opac += 0.05;
			this.Kep.style.opacity = 1 - this.Opac;
			this.KepCut.style.opacity = this.Opac;
			setTimeout("my.swapff()", 70);
		}
		else {
			this.csere();
		}
	},
	
	csere : function(irany) {
		var kovetkezo = (irany == "vissza") ? this.elozo() : this.kovetkezo();
		
		if ((irany != null) && (irany != "undefined")) {
			clearTimeout(this.timeout);
			this.Kep.style.backgroundImage = "url(" + this.path + "/gallery_kiskep.php?kepnev=" + this.images[this.curr].src + "&szelesseg=" + this.szelesseg + "&magassag=" + this.magassag + ")";
			if (this.fIEB==true) {
				this.Kep.title = this.text[this.curr];
			}
			else {
				this.KepCut.title = this.text[this.curr];
			}
		}
		else {
			this.Kep.style.opacity = 1.0;
			this.Kep.style.backgroundImage = this.KepCut.style.backgroundImage;
			
			this.Opac = 0.0;
			this.KepCut.style.opacity = this.Opac;
			
			//" + this.path + "/gallery_kiskep.php?kepnev=" + this.images[this.curr].src + "&szelesseg=489&magassag=166
			this.KepCut.style.backgroundImage = "url(" + this.path + "/gallery_kiskep.php?kepnev=" + this.images[this.curr].src + "&szelesseg=" + this.szelesseg + "&magassag=" + this.magassag + ")";
			this.KepCut.title = this.text[this.prev];
		}
	},
	
	elore : function() {
		this.csere("elore");
	},
	
	vissza : function() {
		this.csere("vissza");
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function KepOver() {
	NextOver();
	PrevOver();
}
                         
function KepOut() {
	NextOut();
	PrevOut();
}

function PrevOver() {
	//alert("prevover");
	prev = document.getElementById("SlideShowPrev").style;
	changeOpacity(prev, 100);
}

function NextOver() {
	//alert("nextover");
	next = document.getElementById("SlideShowNext").style;
	changeOpacity(next, 100);
}

function PrevOut() {
	prev = document.getElementById("SlideShowPrev").style;
	op = (IE) ? 50 : 10;
	changeOpacity(prev, op);
}

function NextOut() {
	next = document.getElementById("SlideShowNext").style;
	op = (IE) ? 50 : 10;
	changeOpacity(next, op);
}

function changeOpacity(obj, opacity) {
	obj.opacity = (opacity / 100);
    obj.MozOpacity = (opacity / 100);
    obj.KhtmlOpacity = (opacity / 100);
    //obj.filters.alpha.opacity = opacity;
    obj.filter = "alpha(opacity=" + opacity + ")";
}

var slideshow;
function isLoad() {
	//alert("isLoad");
	slideshow = new CW_SlideShow();
	slideshow.init();
}

GalleryOnLoad('load', isLoad);




