
// Viewing module 'kiv' --------------------------------------------------------------------

function kiv_module(){
	
	/* -------------------------------- variables ----------------------------------- */

	var cur_gallery = -1;
	var cur_pic = -1;
	var preloading;
	var breakpreloading = 0;
	var cur_load = 0;
	var windowX;
	var windowY;
	var oversizeX = 0;
	var oversizeY = 0;
	var posX;
	var posY;
	var previewing = 0;
	var ss = -1;
	var stop = 0;
    var flipped = 2;
	
	/* -------------------------------- getElementById function --------------------- */
	
	function $(id){
		return document.getElementById(id);
	}

	/* -------------------------------- constructor/descturctor --------------------- */

	this.constr = function(params){
		window.addEventListener('resize', viewdim, false);
        viewdim();    
		var node;
		if(!$("kiv_picdiv")){
			node = document.createElement("div");
			node.id = "kiv_picdiv";
			node.style.position = "fixed";
			node.style.zIndex = 1000;
			node.style.background = "#ffffff";
            node.style.padding = "0px";
			node.style.display = "none";
            node.style.overflow = "hidden";
			document.body.appendChild(node);
		}
        
        if(!$("kiv_comdiv")){
			node = document.createElement("div");
			node.id = "kiv_comdiv";
			node.style.position = "fixed";
			node.style.zIndex = 1000;
			node.style.background = "#ffffff";
            node.style.padding = "10px";
			node.style.display = "none";
            node.style.overflow = "hidden";
            node.style.font = "12px Tahoma, sans-serif";
            node.style.color = "#000000";
            fw.dropshadow(node, 1);
			document.body.appendChild(node);
		}
        
        if(!$("kiv_inshadow")){
			node = document.createElement("div");
			node.id = "kiv_inshadow";
			node.style.position = "relative";
			node.style.left = "0%";
            node.style.top = "0%";
			node.style.zIndex = 1000;
			node.style.background = "none";
            node.style.padding = "0px";
            node.style.border = "0.5px solid #ffffff";
            node.style.width = "0px";
            node.style.height = "0px";
			node.style.display = "none";
            node.style.overflow = "hidden";
            node.style.cursor = "pointer";
            node.onclick = function(){
            	 kiv.goon(1);
            }
            fw.dropshadow(node, 3);
			$("kiv_picdiv").appendChild(node);
		}
        if(!$("kiv_closebutton")){
            var tbcontent = "<img src='ki_base/ki_nav_close.png' style='cursor:pointer; border:0px; margin:0px 2px 0px 2px; padding-top:2px; display:inline;' onclick=\"kiv.closeImage();\" onmouseover=\"this.style.padding = '0px 0px 2px 0px';\" onmouseout=\"this.style.padding = '2px 0px 0px 0px';\" title='Bez&aacute;r' />";
            node = document.createElement("div");
            node.id = "kiv_closebutton";
            node.style.position = "absolute";
            node.style.top = "0px";
            node.style.right = "0px";
            node.style.background = "#ffffff";
            node.style.zIndex = 10000;
            node.style.padding = "1px 1px 3px 1px";
            node.style.lineHeight = "12px";
            fw.dropshadow(node, 1);
            node.innerHTML = tbcontent;
            $("kiv_inshadow").appendChild(node);
        }
		        if(!$("kiv_help")){
            var nodeh = document.createElement("div");
            nodeh.id = "kiv_help";
            nodeh.style.color = "#000000";
            nodeh.style.font = "12px Tahoma, sans-serif";
            nodeh.style.position = "absolute";
                        nodeh.style.left = "4px";                    
                        nodeh.style.bottom = "4px";
            nodeh.style.lineHeight = "19px";
            nodeh.style.textAlign = "left";
            nodeh.style.zIndex = "10";
            if(ss == 1)nodeh.style.display = "none";
            var infosymbol = "<img src='ki_base/ki_nav_info.png' style='border:0px; vertical-align:bottom; display:inline;'  />";
            var infocontent = "Mozgasd az egeret a k&eacute;p sz&eacute;l&eacute;re, hogy l&aacute;sd az elÅ‘zÅ‘/k&ouml;vetkezÅ‘ k&eacute;pet!";
            infocontent = infocontent.replace("[mouse]", "<img src='ki_base/ki_mouse_help.png' style='vertical-align:middle; padding:0px 2px 0px 2px;'  />");
            nodeh.innerHTML = infosymbol;
            fw.addevent( nodeh, "mouseover", function(){
                nodeh.style.width = "250px";
                nodeh.style.padding = "4px";
                nodeh.style.background = "#ffffff";
                nodeh.style.border = "2px solid #000000";
                nodeh.innerHTML = infocontent;
                fw.fade(nodeh, 100);
            } );
            fw.addevent( nodeh, "mouseout", function(){
                nodeh.style.width = "auto";
                nodeh.style.padding = "0px";
                nodeh.style.background = "none";
                nodeh.style.border = "0px";
                nodeh.innerHTML = infosymbol;
                fw.fade(nodeh, 51);
            } );                
            $("kiv_inshadow").appendChild(nodeh);
            setTimeout( function(){
                if(nodeh && ss != 1 && nodeh.style.width != "250px" && nodeh.style.display != "none")fw.fade(nodeh, 51);
            }, 5000);
		}
		        
                if(!$("kiv_gpspic")){
            var tbcontent = "<img src='ki_base/ki_nav_globe.png' style='cursor:pointer; border:0px; margin:0px 2px 0px 2px; padding-top:2px; display:inline;' onclick=\"kiv.opengps();\" onmouseover=\"this.style.padding = '0px 0px 2px 0px';\" onmouseout=\"this.style.padding = '2px 0px 0px 0px';\" title='Show location on map' />";
            node = document.createElement("div");
            node.id = "kiv_gpspic";
            node.style.position = "absolute";
            node.style.top = "0px";
            node.style.left = "0px";
            node.style.background = "#ffffff";
            node.style.zIndex = 10000;
            node.style.padding = "1px 1px 3px 1px";
            node.style.lineHeight = "12px";
            fw.dropshadow(node, 1);
            node.style.display = "none";
            node.innerHTML = tbcontent;
            $("kiv_inshadow").appendChild(node);
        }
                
        
		if(!$("kiv_loading")){
			node = document.createElement("img");
			node.id = "kiv_loading";
			            node.style.margin = "0px";
			node.style.marginLeft = "-8px";
			node.style.marginTop = "-8px";
			node.style.position = "fixed";
			node.style.top = "50%";
			node.style.left = "50%";
			node.style.zIndex = 10000;
			node.src = "ki_base/ki_loading.gif";
            node.style.padding = "0px";
            node.style.border = "0px";
			node.style.display = "none";
			document.body.appendChild(node);
		}
        if(!$("kiv_prevdiv")){
			node = document.createElement("div");
			node.id = "kiv_prevdiv";
			node.style.position = "fixed";
			node.style.zIndex = 10000;
			node.style.background = "#ffffff";
			node.style.padding = "4px 2px 4px 2px";
			node.style.height = "100px";
			node.style.overflow = "hidden";
			node.style.display = "none";
            fw.dropshadow(node, 1);
			document.body.appendChild(node);
		}
                if(!$("kiv_wowdiv")){
			node = document.createElement("div");
			node.id = "kiv_wowdiv";
			node.style.position = "fixed";
			node.style.zIndex = 1001;
            node.style.padding = "0px";
			node.style.display = "none";
                        node.style.padding = "0.5px";
			node.style.background = "#ffffff";            
            			document.body.appendChild(node);
		}
                        		if(!$("kiv_share")){
			node = document.createElement("div");
			node.id = "kiv_share";
            node.style.width = "280";
            node.style.position = "fixed";
            node.style.top = windowY + "px";
	        node.style.left = "50%";
            node.style.marginLeft = "-145px";
            node.style.background = "#ffffff";
                        node.style.border = "2px solid #000000";                        
			node.style.zIndex = 1000;
            node.style.padding = "3px 3px 30px 3px";
            node.style.overflow = "hidden";
            node.style.lineHeight = "12px";
			node.style.display = "none";
            var tbcontent = "<img src='ki_base/ki_nav_link.png' style='border:0px; margin:0px 2px 0px 0px; padding:0px; vertical-align:top; display:inline;' title='Link' />";
            node.innerHTML = tbcontent + "<input type='text' readonly='readonly' onclick='this.select()' style='width:254px; height:17px; padding:1px; line-height:17px; margin:0px; background-color:#fff; font-size:12px; font-weight:normal; color:#000; border:1px solid #000;' />";
			document.body.appendChild(node);
		}
		        fw.shadebody(1);
		  		if(!$("kiv_tb")){
            var breite = 20;
			var tbcontent = "<img src='ki_base/ki_nav_close.png' style='cursor:pointer; border:0px; margin:0px 2px 0px 2px; padding-top:2px; display:inline;' onclick=\"kiv.closeImage();\" onmouseover=\"this.style.padding = '0px 0px 2px 0px';\" onmouseout=\"this.style.padding = '2px 0px 0px 0px';\" title='Bez&aacute;r' />";
			                        breite += 24;
            tbcontent += "<img src='ki_base/ki_nav_download.png' style='cursor:pointer; border:0px; margin:0px 2px 0px 2px; padding-top:2px; display:inline;' onclick=\"kiv.download();\" onmouseover=\"this.style.padding = '0px 0px 2px 0px';\" onmouseout=\"this.style.padding = '2px 0px 0px 0px';\" title='Teljes m&eacute;retÅ± k&eacute;p let&ouml;lt&eacute;se' />";
                        if(kib.pics[params[0]].length > 1){
				breite += 24;				tbcontent += "<img id='ssbutton' src='ki_base/ki_nav_play.png' style='cursor:pointer; border:0px; margin:0px 2px 0px 2px; padding-top:2px; display:inline;' onclick=\"kiv.slideshow();\" onmouseover=\"this.style.padding = '0px 0px 2px 0px';\" onmouseout=\"this.style.padding = '2px 0px 0px 0px';\" title='Automatikus lej&aacute;tsz&aacute;s' />";
				breite += 48;				tbcontent += "<img src='ki_base/ki_nav_prev.png' style='cursor:pointer; border:0px; margin:0px 2px 0px 2px; padding-top:2px; display:inline;' onclick=\"kiv.goon(-1);\" onmouseover=\"this.style.padding = '0px 0px 2px 0px';\" onmouseout=\"this.style.padding = '2px 0px 0px 0px';\" title='ElÅ‘zÅ‘ k&eacute;p' />";
				tbcontent += "<img src='ki_base/ki_nav_next.png' style='cursor:pointer; border:0px; margin:0px 2px 0px 2px; padding-top:2px; display:inline;' onclick=\"kiv.goon(1);\" onmouseover=\"this.style.padding = '0px 0px 2px 0px';\" onmouseout=\"this.style.padding = '2px 0px 0px 0px';\" title='K&ouml;vetkezÅ‘ k&eacute;p' />";
			}
			node = document.createElement("div");
			node.id = "kiv_tb";
			node.style.position = "fixed";
			node.style.top = "-40px";
	        node.style.left = "50%";
            node.style.marginLeft = -(breite+10)/2+"px";
            node.style.background = "#ffffff";
                        node.style.border = "2px solid #000000";                        
			node.style.zIndex = 10000;
            node.style.padding = "20px 3px 3px 3px";
            node.style.lineHeight = "12px";
			node.style.display = "none";
			node.innerHTML = tbcontent;
			document.body.appendChild(node);
		}
				document.addEventListener('keypress', taste, false);
		        kiv.getImage(params[0], params[1]);
	}
	
	this.destr = function(){
		document.body.removeChild($("kiv_picdiv"));
        document.body.removeChild($("kiv_comdiv"));
		        document.body.removeChild($("kiv_tb"));
        		document.body.removeChild($("kiv_loading"));
		document.body.removeChild($("kiv_prevdiv"));
        document.body.removeChild($("kiv_wowdiv"));        document.body.removeChild($("kiv_share"));		window.removeEventListener('resize', viewdim, false);
		document.removeEventListener('keypress', taste, false);
	}
	
	/* -------------------------------- methodes ------------------------------------ */

	
	function viewdim(){
    	if(window.innerHeight){
        	windowX = window.innerWidth;
			windowY = window.innerHeight;
        } else if(document.documentElement && document.documentElement.clientHeight){ // Explorer 6 Strict Mode
			windowX = document.documentElement.clientWidth;
			windowY = document.documentElement.clientHeight;
		} else if (document.body){ // other Explorers
			windowX = document.body.clientWidth;
        	windowY = document.body.clientHeight;
		}
        if($("kiv_share"))$("kiv_share").style.top = windowY + "px";
        if($("kiv_comdiv")){
            var com_div = $("kiv_comdiv");
            var sizes = fw.getDim($("kiv_picdiv"), 1);
            var comm_x = com_div.offsetWidth;
            var comm_y = com_div.offsetHeight;
            if(comm_x > sizes[0]){
                comm_x = sizes[0];                
                com_div.style.width = (sizes[0] - 2*10) + "px";
                comm_y = com_div.offsetHeight;                
            }
            	
            var x_pos = $("kiv_picdiv").offsetLeft;
            var y_pos = $("kiv_picdiv").offsetHeight + $("kiv_picdiv").offsetTop + 5;
            if(y_pos + comm_y > windowY){
    			y_pos -= comm_y + 10;
                if(comm_x != sizes[0])x_pos += 5;            }
                        com_div.style.left = x_pos + "px";
            com_div.style.top = y_pos + "px";
        }
	}

	function preloadgallery(){
		if(breakpreloading == 1)return;
		var files = kib.pics[cur_gallery].length;
		cur_load = cur_pic + 1;
		if(cur_load == files)return;
		var loaded = 0;
		while(preloading[cur_load] != null){
			cur_load++;
			loaded++;
			if(loaded == files){
				return;
			}
			if(cur_load == files || cur_load - cur_pic > 3)return;
		}
        preloading[cur_load] = document.createElement('img');
		preloading[cur_load].onload = function(){
			preloadgallery();
		};
		var picsize = calcpicsize(cur_load);
		if(picsize[0] != kib.pics[cur_gallery][cur_load].x){
			preloading[cur_load].src = "ki_base/ki_makepic.php?fullimg=1&file=" + kib.dirs[cur_gallery] + "/" + encodeURIComponent(kib.pics[cur_gallery][cur_load].file) + "&width=" + picsize[0] + "&height=" + picsize[1];
		} else {
			preloading[cur_load].src = "ki_galleries/" + kib.dirs[cur_gallery] + "/" + kib.pics[cur_gallery][cur_load].file;
		}
	}

	this.getImage = function(gallerynumber, picnumber){
		if(stop == 1)return;
		var firsttoshow = 0;
		if(cur_gallery == -1){
			firsttoshow = 1;
			preloading = new Array(kib.pics[gallerynumber].length);
		}
        if($("kib_helpbox")){
        	kib.hidehelp();
        }
        document.removeEventListener('mousemove', mousemoved, false);
        if($("kiv_vcomments_form")){
        	$("kiv_picdiv").removeChild($("kiv_vcomments_form"));
        	if($("kiv_vcomments_list"))$("kiv_picdiv").removeChild($("kiv_vcomments_list"));
        }
        kiv.removewow();        fw.fade("kiv_gpspic", 0);		if(gallerynumber == -1)gallerynumber = cur_gallery;
		breakpreloading = 1;
		preloading[cur_load] = null;
		cur_gallery = gallerynumber;
		cur_pic = picnumber;
		var picsize = calcpicsize(picnumber);
				var params = "?reldir=&gallery=" + kib.dirs[cur_gallery] + "&file=" + encodeURIComponent(kib.pics[cur_gallery][cur_pic].file) + "&x=" + picsize[0] + "&y=" + picsize[1];
		fw.getHTTP("ki_base/ki_fullimg.php" + params, kiv.gotImage, Array(picsize, firsttoshow, 0));
	}
	
	this.gotImage = function(responseText, params){
		if(stop == 1)return;
		var picdiv = $("kiv_picdiv");
        var inshad = $("kiv_inshadow");
		var picdivsize = params[0];
		var firsttoshow = params[1];
		if(params[2] == 0){ // Bild wird geladen
			picdivsize[0] += 1;
			picdivsize[1] += 1;
            
			if(firsttoshow == 1){ // Einfügen/Warten von onload beim ersten Öffnen
            
				picdiv.style.top = "50%";
				picdiv.style.left = "50%";
				picdiv.style.width = "0px";
				picdiv.style.height = "1px";
				picdiv.style.display = "block";
                
                var node = document.createElement("div");
                node.innerHTML = responseText;
                var temp = node.childNodes.length;
                for(var i = 0; i < temp; i++){
                    picdiv.appendChild(node.childNodes[0]);
                }

				var thepic = $("thepicture");
                thepic.onload = function(){
                    if(kiv != null && thepic == $("thepicture"))kiv.gotImage("", Array(picdivsize, firsttoshow, 1));
                };
                thepic.src = thepic.alt;
                setTimeout( function(){ if(kiv != null && thepic != null){if(thepic.alt != "" && !thepic.complete){fw.fade("kiv_loading", 100, Array(function(){$("kiv_loading").src = "ki_base/ki_loading.gif";}));$("kiv_picdiv").style.zIndex = 99;}} }, 750);
                
			} else { // Einfügen/Warten von onload beim Weiterklicken
            	
                for(var i = 0; i < picdiv.childNodes.length; i++){
                    var objid = picdiv.childNodes[i].id;
                                                            if(objid == "kiv_gps"){ picdiv.removeChild(picdiv.childNodes[i]);i--;continue; }
                                                                                if(objid == "thecomment"){ picdiv.removeChild(picdiv.childNodes[i]);i--;continue; }
                    if(objid == "thepicture"){ picdiv.childNodes[i].id = "oldpic"; }
                }
                
                fw.fade("kiv_comdiv", 0);
                
                var node = document.createElement("div");
                node.innerHTML = responseText;
                var temp = node.childNodes.length;
                for(var i = 0; i < temp; i++){
                    picdiv.appendChild(node.childNodes[0]);
                }
                var thepic = $("thepicture");
                thepic.onload = function(){
                    if(kiv != null && thepic == $("thepicture"))kiv.gotImage("", Array(picdivsize, firsttoshow, 1));
                };
                thepic.src = thepic.alt;
                setTimeout( function(){ if(kiv != null && thepic != null){if(thepic.alt != "" && !thepic.complete){fw.fade("kiv_loading", 100, Array(function(){$("kiv_loading").src = "ki_base/ki_loading.gif";}));$("kiv_picdiv").style.zIndex = 99;}} }, 750);

 
			}
            
		} else { // Bild wurde geladen -> Bild anzeigen
        
            $("kiv_loading").style.display = "none";
			if(previewing == 0){
            	$("kiv_picdiv").style.zIndex = 1000;
                $("kiv_comdiv").style.zIndex = 1000;
			}
	        preloading[cur_pic] = 1;
            breakpreloading = 0;
       		preloadgallery();

                        var shareadd = location.search;
            if(shareadd.indexOf('kit_code=') != -1)
            	shareadd = shareadd.substr(0, shareadd.indexOf('kit_code=')-1);
            if(shareadd.indexOf('?') == -1)
            	shareadd = "?" + shareadd;
            else
            	shareadd += "&";
            var slash = "";
            if(location.pathname.substr(0, 1) != "/")slash = "/";
			shareadd = "http://" + location.hostname + slash + location.pathname + shareadd + "kit_code=" + cur_gallery+"_"+cur_pic + location.hash;
            $("kiv_share").childNodes[1].value = shareadd;
                        
			var thepic = $("thepicture");
            if(thepic != null){
                thepic.alt = "";
				thepic.style.display = "none";
				thepic.style.visibility = "visible";
            }
            flipped = 0;
            
			if(firsttoshow == 1){ // Bild wurde geladen -> Bild anzeigen beim ersten Öffnen
                
				fw.resize( picdiv, 2, picdivsize[0], 1, Array( function(){
                	
                    fw.resize( picdiv, 2, picdivsize[0], picdivsize[1], Array( function(){ 
                        inshad.style.width = picdivsize[0] - 2*0.5 + "px";
                        inshad.style.height = picdivsize[1] - 2*0.5 + "px";
                        inshad.style.display = "block";
                        fw.dropshadow(picdiv, 1);
                        fw.fade("thepicture", 100, Array( function(){
                        
                                                        fw.move("kiv_tb", 3, 0, -20);
                            $("kiv_tb").setAttribute("contr", "stay");
                            setTimeout( function() {
                                if($("kiv_tb"))$("kiv_tb").setAttribute("contr", "");
                            }, 5000);
                                                                                    fw.move("kiv_share", 3, 0, windowY - 29);
                            $("kiv_share").setAttribute("contr", "stay");
                            setTimeout( function() {
                                if($("kiv_share"))$("kiv_share").setAttribute("contr", "");
                            }, 5000);
                                                        viewdim();
                            showcomment();
                            checkgps();
                            checkvcomment();
                            var focme = $("focusme");
                            if(focme){
	                            kib.showhelp(focme, 4, 2);
							}
                            document.addEventListener('mousemove', mousemoved, false);
                                                        if(ss == 1)setTimeout( function(){if(kiv != null){if(ss == 1){ss = 2;kiv.goon(1);}}} , 4000);
                            
                        } ));
                    } ));
				} ));
                
			} else { // Bild wurde geladen -> Bild anzeigen beim Weiterklicken
				
                fw.fade("oldpic", 0, Array( function(){
					var picdiv = $("kiv_picdiv");
					for(var i = 0; i < picdiv.childNodes.length; i++){
                    	var objid = picdiv.childNodes[i].id;
						if(objid == "oldpic"){ picdiv.removeChild(picdiv.childNodes[i]);i--; }
					}
				} ));
                
				fw.fade("thepicture", 100, Array( function(){
	                inshad.style.display = "block";
                	fw.resize( inshad, 1, picdivsize[0] - 2*0.5, picdivsize[1] - 2*0.5 );
                    fw.resize( picdiv, 2, picdivsize[0], picdivsize[1], Array( function(){
                        showcomment();
                        checkgps();
                        checkvcomment();                    
                        if(previewing == 0){
                            document.addEventListener('mousemove', mousemoved, false);
                        }
                                                if(ss != 1)fw.fade("kiv_help", 51);                        if(ss == 1)setTimeout( function(){if(kiv != null){if(ss == 1){ss = 2;kiv.goon(1);}}} , 4000);
                    } ));
				} ));
			}
		}
	}
    
    function checkgps(){
    	    	if(stop == 1 || ss == 1)return;
        if(!$("kiv_gps"))return;
        var coordinates = $("kiv_gps").value;
        if(coordinates != "0,0"){
        	fw.fade("kiv_gpspic", 100);
        } else {
        	        }
            }
    
    
	    
    this.opengps = function(){
    	if($("kiv_gps")){
        	if($("kiv_gps").value != "0,0"){
            	var coordinates = $("kiv_gps").value;
                var filename = kib.pics[cur_gallery][cur_pic].file;
				filename = filename.substr(0, filename.length-4);
                window.open("http://maps.google.com/?q=" + filename + "@" + coordinates);
            }
        }
    }
        
    function checkvcomment(){
    	    }    
	
        this.removewow = function(){
	    var wowdiv = $("kiv_wowdiv");
		wowdiv.innerHTML = "";
        wowdiv.style.display = "none";
        fw.dropshadow(wowdiv, 0);
	        }
        
	function mousemoved(aEvent) {
    	if(stop == 1)return;
		aEvent = aEvent ? aEvent : window.event;
		var x = aEvent.clientX ? aEvent.clientX : aEvent.pageX;
		var y = aEvent.clientY ? aEvent.clientY : aEvent.pageY;

				var tb = $("kiv_tb");
        if(y > windowY * 0.33 || x > (windowX/2+200) || x < (windowX/2-200)){
        	if(tb.getAttribute("contr") == ""){
            	fw.move(tb, 3, 0, -60);
                tb.setAttribute("contr", "open");
			}
        } else {
        	if(tb.getAttribute("contr") == "open"){
                fw.move(tb, 3, 20, -20);
                tb.setAttribute("contr", "");
			}
        }
		        
				var sh = $("kiv_share");
        if(y < windowY - 150 || x > (windowX/2+300) || x < (windowX/2-300)){
        	if(sh.getAttribute("contr") == ""){
            	            	fw.move(sh, 3, 0, windowY);
                sh.setAttribute("contr", "open");
			}
        } else {
        	if(sh.getAttribute("contr") == "open"){
                fw.move(sh, 3, 20, windowY - 29);
                sh.setAttribute("contr", "");
			}
        }
		
		if(!x)x = 1;        
		if(ss == 1)return;

		var dim = fw.getDim($("kiv_picdiv"));
		var wowdiv = $("kiv_wowdiv");

		        if(windowX - dim[0] >= 0.33*windowX){ // Bild bedeckt max 2/3 des Bildschirmplatzes
            if(x > (windowX + dim[0])*0.5 && cur_pic != kib.pics[cur_gallery].length-1){
                if(y > (windowY-dim[1])*0.5 && y < (windowY+dim[1])*0.5){
                    if(!wowdiv.firstChild){
                        var picsize = calcpicsize(cur_pic+1);
                        var picsrc = "";
                        if(picsize[0] != kib.pics[cur_gallery][cur_pic+1].x){
                            picsrc = "ki_base/ki_makepic.php?fullimg=1&file=" + kib.dirs[cur_gallery] + "/" + encodeURIComponent(kib.pics[cur_gallery][cur_pic+1].file) + "&width=" + picsize[0] + "&height=" + picsize[1];
                        } else {
                            picsrc = "ki_galleries/" + kib.dirs[cur_gallery] + "/" + kib.pics[cur_gallery][cur_pic+1].file;
                        }
                        wowdiv.style.zIndex = 10000;
                        wowdiv.innerHTML = "<img src='"+picsrc+"' style='vertical-align:middle; visibility:hidden; cursor:pointer;' onload=\"this.style.visibility='visible'\" onclick='kiv.goon(1);' /><div id='kiv_wowdiv_inshadow' style='position:absolute; left:0%; top:0%; background:none; padding:0px; border:0.5px solid #ffffff; cursor:pointer;' onclick='kiv.goon(1);'></div>";
                        wowdiv.style.left = (windowX + dim[0])*0.5 - 30 + "px";
                        fw.dropshadow("kiv_wowdiv_inshadow", 3);
                        fw.dropshadow(wowdiv, 1);
                        fw.fade(wowdiv, 100);
                    }
                    var obj = kib.pics[cur_gallery][cur_pic+1];
                    var breite = x - (windowX + dim[0])*0.5 + 50;
                    var hoehe = (obj.y/obj.x)*breite;
                    var maxh = dim[1]*0.66;
                    if(hoehe > maxh){
                        hoehe = maxh;
                        breite = (obj.x/obj.y)*hoehe;
                    }
                    var pic = wowdiv.firstChild;
                    pic.style.width = breite + "px";
                    pic.style.height = hoehe + "px";
                    wowdiv.style.top = y + "px";                    
                    wowdiv.style.marginTop = -0.5*(hoehe+0.5*2) + "px";
                    var inshad = $("kiv_wowdiv_inshadow");
                    inshad.style.width = breite + "px";
                    inshad.style.height = hoehe + "px";
                }
            } else if(x < (windowX - dim[0])*0.5 && cur_pic != 0){
                if(y > (windowY-dim[1])*0.5 && y < (windowY+dim[1])*0.5){
                    if(!wowdiv.firstChild){
                        var picsize = calcpicsize(cur_pic-1);
                        var picsrc = "";
                        if(picsize[0] != kib.pics[cur_gallery][cur_pic-1].x){
                            picsrc = "ki_base/ki_makepic.php?fullimg=1&file=" + kib.dirs[cur_gallery] + "/" + encodeURIComponent(kib.pics[cur_gallery][cur_pic-1].file) + "&width=" + picsize[0] + "&height=" + picsize[1];
                        } else {
                            picsrc = "ki_galleries/" + kib.dirs[cur_gallery] + "/" + kib.pics[cur_gallery][cur_pic-1].file;
                        }
                        wowdiv.style.zIndex = 999;
                        wowdiv.innerHTML = "<img src='"+picsrc+"' style='vertical-align:middle; visibility:hidden; cursor:pointer;' onload=\"this.style.visibility='visible'\" onclick='kiv.goon(-1);' /><div id='kiv_wowdiv_inshadow' style='position:absolute; left:0%; top:0%; background:none; padding:0px; border:0.5px solid #ffffff; cursor:pointer;' onclick='kiv.goon(-1);'></div>";
                        fw.dropshadow("kiv_wowdiv_inshadow", 3);
                        fw.dropshadow(wowdiv, 1);
                        fw.fade(wowdiv, 100);
                    }
                    var obj = kib.pics[cur_gallery][cur_pic-1];
                    var breite = (windowX - dim[0])*0.5 - x + 50;
                    var hoehe = (obj.y/obj.x)*breite;
                    var maxh = dim[1]*0.66;
                    if(hoehe > maxh){
                        hoehe = maxh;
                        breite = (obj.x/obj.y)*hoehe;
                    }
                    var pic = wowdiv.firstChild;
                    pic.style.width = breite + "px";
                    pic.style.height = hoehe + "px";
                    wowdiv.style.left = (windowX - dim[0])*0.5 + 30 - breite - 0.5*2 + "px";
                    wowdiv.style.top = y + "px";                    
                    wowdiv.style.marginTop = -0.5*(hoehe+0.5*2) + "px";
                    var inshad = $("kiv_wowdiv_inshadow");
                    inshad.style.width = breite + "px";
                    inshad.style.height = hoehe + "px";
                }
            } else {
                if(wowdiv.firstChild){
                    kiv.removewow();
                }
            }
		}
        
		        if(windowX - dim[0] < 200)return; // Mindestens 100 Pixel Platz zu jeder Seite
		if(x > windowX - 40 && cur_pic != kib.pics[cur_gallery].length-1){
                        if(wowdiv.firstChild){
                fw.dropshadow(wowdiv, 0);
                fw.fade(wowdiv, 0, Array( function(){
                    wowdiv.innerHTML = "";
                } ));
            }
            			document.removeEventListener('mousemove', mousemoved, false);
			previewing = 1;
			var prevdiv = $("kiv_prevdiv");
			prevdiv.style.top = y - 54 + "px";
			prevdiv.style.left = windowX + 500 + "px";
			prevdiv.style.width = "20px";
			$("kiv_picdiv").style.zIndex = 99;
            $("kiv_comdiv").style.zIndex = 99;
            prevdiv.style.display = "block";
			fw.move(prevdiv, 2, windowX - 20, 0, Array( function(){
				var params = "?reldir=&gallery=" + kib.dirs[cur_gallery] + "&file=" + encodeURIComponent(kib.pics[cur_gallery][cur_pic].file) + "&topic=1";
				fw.getHTTP("ki_base/ki_preview.php" + params, kiv.showpreview, 1);
				$('fw_blend').addEventListener('mousemove', closepreview, false);
			} ));
		} else if(x < 40 && cur_pic != 0){
        	        	if(wowdiv.firstChild){
                fw.dropshadow(wowdiv, 0);
                fw.fade(wowdiv, 0, Array( function(){
                	wowdiv.innerHTML = "";
                } ));
            }
            			document.removeEventListener('mousemove', mousemoved, false);
			previewing = 1;
			var prevdiv = $("kiv_prevdiv");
			prevdiv.style.top = y - 54 + "px";
			prevdiv.style.left = "-500px";
			prevdiv.style.width = "20px";
			$("kiv_picdiv").style.zIndex = 99;
            $("kiv_comdiv").style.zIndex = 99;
            prevdiv.style.display = "block";
			fw.move(prevdiv, 2, 0, 0, Array( function(){
				var params = "?reldir=&gallery=" + kib.dirs[cur_gallery] + "&file=" + encodeURIComponent(kib.pics[cur_gallery][cur_pic].file) + "&topic=-1";
				fw.getHTTP("ki_base/ki_preview.php" + params, kiv.showpreview, -1);
				$('fw_blend').addEventListener('mousemove', closepreview, false);
			} ));
		}
		        
	}
	
	this.showpreview = function(responseText, topic){
		if(stop == 1 || previewing == 0)return;
		var prevdiv = $("kiv_prevdiv");
		prevdiv.innerHTML = responseText;
		var gesbreite = $("gesbreite").value;
		if(topic == 1){
			prevdiv.style.width = gesbreite + "px";
			fw.move(prevdiv, 2, windowX - gesbreite - 4, 0);
		} else {
			prevdiv.style.left = -1*gesbreite + 20 + "px";
			prevdiv.style.width = gesbreite + "px";
			fw.move(prevdiv, 2, 0, 0);
		}	
	}
	
	function closepreview(aEvent){
		if(stop == 1)return;
		aEvent = aEvent ? aEvent : window.event;
		var x = aEvent.clientX ? aEvent.clientX : aEvent.pageX;
		var y = aEvent.clientY ? aEvent.clientY : aEvent.pageY;

		if(x > windowX - 40 || x < 40)return;
               
		$('fw_blend').removeEventListener('mousemove', closepreview, false);
		previewing = 0;
		var prevdiv = $("kiv_prevdiv");
		if($("kiv_loading").style.display == "none"){
        	$("kiv_picdiv").style.zIndex = 1000;
            $("kiv_comdiv").style.zIndex = 1000;
		}
		if(parseInt(prevdiv.style.left) > 0){
			fw.move(prevdiv, 2, windowX, 0, Array( function(){
				prevdiv.innerHTML = "";
				prevdiv.style.display = "none";
				document.addEventListener('mousemove', mousemoved, false);
			} ));
		} else {
			fw.move(prevdiv, 2, -prevdiv.offsetWidth, 0, Array( function(){
				prevdiv.innerHTML = "";
				prevdiv.style.display = "none";
				document.addEventListener('mousemove', mousemoved, false);
			
			} ));
		}
	}
	
	function showcomment(){
		if(stop == 1)return;
        var com_div = $("kiv_comdiv");
        var sizes = fw.getDim($("kiv_picdiv"), 1);
		if($("thecomment")){
			com_div.style.visibility = "hidden";
            com_div.style.display = "block";
            com_div.style.width = "auto";
            com_div.style.left = "0px";
            
			var commstring = $("thecomment").innerHTML;
			                        com_div.innerHTML = commstring;

            var comm_x = com_div.offsetWidth;
            var comm_y = com_div.offsetHeight;
            
            if(comm_x > sizes[0]){
                comm_x = sizes[0];                
                com_div.style.width = (sizes[0] - 2*10) + "px";
                comm_y = com_div.offsetHeight;                
            }
            
            	
            var x_pos = $("kiv_picdiv").offsetLeft;
            var y_pos = $("kiv_picdiv").offsetHeight + $("kiv_picdiv").offsetTop + 5;
            if(y_pos + comm_y > windowY){
    			y_pos -= comm_y + 10;
                if(comm_x != sizes[0])x_pos += 5;            }
                        
            com_div.style.left = x_pos + "px";
            com_div.style.top = y_pos + "px";
            com_div.style.display = "none";
            com_div.style.visibility = "visible";
            fw.fade(com_div, 100);
            
            var focme = $("focusme");
            if(focme){
            	focme.focus();
			}
        }

	}
	
	function calcpicsize(fileno){
		var picx = kib.pics[cur_gallery][fileno].x;
		var picy = kib.pics[cur_gallery][fileno].y;
		var winx = picx + 1;
		var winy = picy + 1;
				var xlimiter = 10000;
		var ylimiter = 0.75;
        if(xlimiter < 1)xlimiter = parseInt(10000*windowX);
        if(ylimiter < 1)ylimiter = parseInt(0.75*windowY);
				if(xlimiter > windowX)xlimiter = windowX - 20;
		if(ylimiter > windowY)ylimiter = windowY - 34;	
				if(winy > ylimiter || winx > xlimiter){
			var k;
			if( (picx / picy) > 1){
				k = picy / picx;
				picx = xlimiter-1;
				picy = k*picx;
				if(picy > ylimiter-1){
					picy = ylimiter-1;
					picx = (1/k) * picy;
				}
			} else {
				k = picx / picy;
				picy = ylimiter-1;
				picx = k*picy;
				if(picx > xlimiter-1){
					picx = xlimiter-1;
					picy = (1/k) * picx;
				}
			}
			picx = Math.round(picx);
			picy = Math.round(picy);
		}
				return new Array(picx, picy);
	}
	
	this.slideshow = function(){
    	if(stop == 1)return;
		if(ss == 2)ss = 1;
        ss *= -1;
		var sspic = $("ssbutton");
		if(ss == 1){
			            sspic.src = "ki_base/ki_nav_stop.png";
                        sspic.title = "Stop slideshow";
			$("kiv_help").style.display = "none";            ss = 2;
			kiv.goon(1);
		} else {
						sspic.src = "ki_base/ki_nav_play.png";
                        sspic.title = "Automatikus lejÃ¡tszÃ¡s";
			fw.fade("kiv_help", 51);		}
	}
    
    this.sshelp = function(val){
    	ss = val;
    }
	
	this.goon = function(topic){
    	if(stop == 1 || ss == 1)return;
        if(ss == 2)ss = 1;
		if(topic > 0){
			if(cur_pic + topic <= kib.pics[cur_gallery].length-1){
				kiv.getImage(cur_gallery, cur_pic+topic);
			} else {
				kiv.getImage(cur_gallery, (cur_pic+topic)-kib.pics[cur_gallery].length);
			}
		} else {
			if(cur_pic + topic >= 0){
				kiv.getImage(cur_gallery, cur_pic+topic);
			} else {
				kiv.getImage(cur_gallery, kib.pics[cur_gallery].length+(cur_pic+topic));
			}
		}
	}
	
	this.closeImage = function(){
		stop = 1;
        if($("kib_helpbox")){
        	kib.hidehelp();
        }
		document.removeEventListener('mousemove', mousemoved, false);
        kiv.removewow();       	if(window.stop !== undefined){
             window.stop();
        }else if(document.execCommand !== undefined){
             document.execCommand("Stop", false);
        }
		var picdiv = $("kiv_picdiv");
		        if($("kiv_vcomments_form"))$("kiv_picdiv").removeChild($("kiv_vcomments_form"));
        if($("kiv_vcomments_list"))$("kiv_picdiv").removeChild($("kiv_vcomments_list"));
        fw.fade("kiv_share", 0);
        fw.fade("kiv_closebutton", 0);
        fw.fade("kiv_help", 0);
        fw.fade("kiv_gpspic", 0);
        fw.fade("kiv_prevdiv", 0);
        fw.fade("kiv_tb", 0);
        fw.fade("kiv_inshadow", 0);
        
        fw.fade("kiv_comdiv", 0, Array( function() {
            fw.fade("thepicture", 0, Array( fw.resize, picdiv, 2, parseInt(picdiv.style.width), 1, Array( fw.resize, picdiv, 2, 0, 1, Array( function(){fw.removejs("kiv");if(typeof(kie_module) == "function"){$("kie_maindiv").style.zIndex = 1000;$("kie_tb").style.display = "block";}else{if(typeof(kis_module) != "function")fw.shadebody(0);}} ))));
        } ));

	}

	function preventDefaultAction(aEvent) {	
		        aEvent.stopPropagation(); 
        				aEvent.preventDefault();
					}
	
	function taste(aEvent) {
		aEvent = aEvent ? aEvent : window.event;
        var keyCode = aEvent.keyCode;
        var charCode = aEvent.charCode ? aEvent.charCode : 0;
        if(keyCode == 27){
			kiv.closeImage();
			preventDefaultAction(aEvent);
			return false;
		}
		if(stop == 1 || flipped != 0)return;
				if(keyCode == 19 || keyCode == 32 || charCode == 32){
			if(kib.pics[cur_gallery].length > 1)kiv.slideshow($("ssbutton"));
			preventDefaultAction(aEvent);
			return false;
		}
		if(ss == 1)return false;
						if(keyCode == 33 || keyCode == 36){
			kiv.goon(-1);
			preventDefaultAction(aEvent);
			return false;
		}
		if(keyCode == 34 || keyCode == 35){
			kiv.goon(1);
			preventDefaultAction(aEvent);
			return false;
		}
		if(keyCode == 38){
						preventDefaultAction(aEvent);
			return false;
		}
		if(keyCode == 40){
						preventDefaultAction(aEvent);
			return false;
		}
		if(keyCode == 37){
						kiv.goon(-1);
						preventDefaultAction(aEvent);
			return false;
		}
		if(keyCode == 39){
						kiv.goon(1);
						preventDefaultAction(aEvent);
			return false;
		}
	}
    
    
	this.download = function(){
       	var node = document.createElement("form");
        node.action = "ki_base/ki_download.php";
        node.method = "post";
        node.innerHTML = "<input type='hidden' name='file' value='" + kib.pics[cur_gallery][cur_pic].file + "' /><input type='hidden' name='gallery' value='" + kib.dirs[cur_gallery] + "' />";
        document.body.appendChild(node);
		node.submit();
		document.body.removeChild(node);
    }
}