	function function_exists_f_gallery(fName)
	{
		pObj = window;
		return (typeof pObj[fName] == 'function') ? true : false;
	}
	// überprüfen, ob wichtige functionen existiren. wenn nicht, dann werder sie erstellt
	// start ->
	
	if(!function_exists_f_gallery("$"))
	{
		// function $(id) { return document.getElementById(id); }
	}
	if(!function_exists_f_gallery("in_array"))
	{
		function in_array(str, arr)
		{
			for(a in arr)
			{
				if(str == arr[a]) return true;
			}
			return false;
		}
	}
	if(!function_exists_f_gallery("array_key"))
	{
		function array_key(str, arr)
		{
			for(b in arr)
			{
				if(str == arr[b]) return b;
			}
			return false;
		}
	}
	if(!function_exists_f_gallery("strrchr"))
	{
		function strrchr(chr ,stri)
		{
			return stri.substr(stri.lastIndexOf(chr));
		}
	}
	if(!function_exists_f_gallery("galleryConfigIncluded")) alert("Die Galerie kann nicht geladen werden, da die Config Datei 'va_js_gallery.config.js' nichtg eingbunden ist!");
	
	
	// ...
	// <- ende
	
	function popup_fade2black()
	{
		var bg=$('fade2black');
		var opacity;
		if(bg)
		{
			if(bg.style.opacity)
			{
				opacity=bg.style.opacity*100;
				// alert("opacity");
			}
			if(bg.filters)
			{
				opacity=bg.filters['alpha'].opacity;
				// alert("alpha");
			}
			if(opacity<bg_opacity)
			{
				var new_opacity=opacity+(bg_opacity/fade_steps);
				if(bg.style.opacity)	bg.style.opacity=new_opacity/100;
				if(bg.filters)			bg.filters['alpha'].opacity=new_opacity;
				window.setTimeout('popup_fade2black()',(fade_duration/fade_steps));
			}
			else
			{
				popup_2_show.style.display='';
			}
		}
	}	
	
	function popup_fade2white()
	{
		var bg=$('fade2black');
		var opacity;
		if(bg)
		{
			if(bg.style.opacity) opacity=bg.style.opacity*100;
			if(bg.filters) 		 opacity=bg.filters['alpha'].opacity;
			if(opacity>0) 
			{
				var new_opacity=opacity-(bg_opacity/fade_steps);
				if(bg.style.opacity)	bg.style.opacity=new_opacity/100;
				if(bg.filters)			bg.filters['alpha'].opacity=new_opacity;
				window.setTimeout('popup_fade2white()',5);
			}
			else 
			{
				bg.style.display='none';
			}
		}
	}
	var scrolledY = false;
	var gallery_images = new Array();
	function getGalleryImages(images)
	{
		// images = document.images;
		
		for(i=0; i<images.length; i++)
		{
			if(images[i].tagName.toUpperCase() == "IMG" || images[i].tagName.toUpperCase() == "A")
			{
				startsearchat = 0;
				if(images[i].tagName.toUpperCase() == "IMG")
				{
					xrel = images[i].alt;
					startsearchat_pre = xrel.indexOf("[");
					if(startsearchat_pre != -1) startsearchat = startsearchat_pre -7;
				}
				else xrel = images[i].rel;
				if(xrel && xrel.substr(startsearchat, 7) == "gallery")
				{
					// alert("7,1: "+xrel.substr(7, 1)+" | -1:"+xrel.substr(xrel.length-1, 1));
					if(xrel.substr(startsearchat+7, 1) == "[" && xrel.substr(xrel.length-1, 1) == "]")
					{
						xgallery = xrel.substring(startsearchat+8, parseInt(xrel.length)-1);
						// alert(xgallery);
						if(!gallery_images[xgallery]) gallery_images[xgallery] = new Array();
						xcnt = gallery_images[xgallery].length;
						gallery_images[xgallery][xcnt] = images[i];
						gallery_images[xgallery][xcnt].imgnr = xcnt;
						gallery_images[xgallery][xcnt].gallery = xgallery;
						images[i].onclick = new Function("show_image(gallery_images['"+xgallery+"']["+xcnt+"]); this.blur(); return false;");
						if(images[i].tagName.toUpperCase() == "IMG")
						{
							isrc = images[i].src;
							isrc = isrc.replace("http://" + window.location.hostname + base_href, "");
							gallery_images[xgallery][xcnt].imgurl = isrc;
							images[i].alt = images[i].alt.substr(0, (images[i].alt.length - (9+xgallery.length)));
							// images[i].src="/image.php?src="+images[i].src.replace("http://"+window.location.host+"/", "")+"&w=150&h=150";
							// images[i].src="/image.php?src="+images[i].src+"&w=150&h=150";
							images[i].src=path_thumbnail.replace(/{image}/, isrc);
							images[i].style.cursor = "pointer";
						}
						else
						{
							isrc = images[i].href;
							isrc = isrc.replace("http://" + window.location.hostname + base_href, "");
							gallery_images[xgallery][xcnt].imgurl = isrc;
						}
					}
					else
					{
						if(!gallery_images["no_rel"]) gallery_images["no_rel"] = new Array();
						xcnt = gallery_images["no_rel"].length;
						gallery_images["no_rel"][xcnt] = images[i];
						gallery_images["no_rel"][xcnt].imgnr = 0;
						gallery_images["no_rel"][xcnt].gallery = false;
						
						images[i].onclick = new Function("show_image(gallery_images['no_rel']["+xcnt+"]); this.blur(); return false;");
						if(images[i].tagName.toUpperCase() == "IMG")
						{
							isrc = images[i].src;
							isrc = isrc.replace("http://" + window.location.hostname + base_href, "");
							gallery_images["no_rel"][xcnt].imgurl = isrc;
							images[i].alt = images[i].alt.substr(0, (images[i].alt.length-15));
							// images[i].src="/image.php?src="+images[i].src.replace("http://"+window.location.host+"/", "")+"&w=150&h=150";
							// images[i].src="/image.php?src="+images[i].src+"&w=150&h=150";
							images[i].src=path_thumbnail.replace(/{image}/, isrc);
							images[i].style.cursor = "pointer";
						}
						else
						{
							isrc = images[i].href;
							isrc = isrc.replace("http://" + window.location.hostname + base_href, "");
							gallery_images["no_rel"][xcnt].imgurl = isrc;
						}
					}
				}
			}
		}
		// alert(gallery_images);
	}
	function getBoxPreviewImages(ximage)
	{
		if(preview_images_in_box == false) return "";
		var out = "";
		for(var b=(ximage.imgnr - preview_images_in_box); b<=(ximage.imgnr+preview_images_in_box); b++)
		{
			// alert(b)
			if(!gallery_images[ximage.gallery][b]) continue;
			if(b<0) continue;
			pimg_act = "";
			if(b == ximage.imgnr) pimg_act = "active_box_preview_image";
			out += '<a href="#" onclick="show_image(gallery_images[\''+ximage.gallery+'\']['+b+']); return false;"><img src="{path_preview_image}" border="0" class="'+pimg_act+'"></a>&nbsp;';
			
			prepcacements = new Object();
			prepcacements["path_preview_image"]		= path_preview_image;
			prepcacements["image"]					= gallery_images[ximage.gallery][b].imgurl;
			
			for(rkey in prepcacements)
			{
				repl = eval("/\{"+rkey+"\}/gi");
				out = out.replace(repl, prepcacements[rkey]);
			}
			delete(prepcacements);
			
		}
		return out;
	}
	
	function show_image(ximage)
	{
		img_src = ximage.imgurl;
		prev = "";
		next_i = "";
		xgal = ximage.gallery;
		img_key = false;
		if(xgal != false && xgal != 0)
		{
			img_key = ximage.imgnr;
			if(parseInt(img_key) > 0 && img_key != false)
			{
				// prev = '<a href="#" onclick="show_image(gallery_images[\''+xgal+'\']['+(parseInt(img_key)-1)+']); return false;"><img src="'+base_href+'VAImageBox/prev.png" alt="'+text_Zurueck+'" border="0"></a>';
				prev = '<a href="#" onclick="show_image(gallery_images[\''+xgal+'\']['+(parseInt(img_key)-1)+']); return false;"><img src="/tp/VAImageBox/prev.png" alt="'+text_Zurueck+'" border="0"></a>';
			}
			if(parseInt(img_key) < parseInt(gallery_images[xgal].length)-1 && (img_key != false || img_key == "0"))
			{
				// next_i = '<a href="#" onclick="show_image(gallery_images[\''+xgal+'\']['+(parseInt(img_key)+1)+']); return false;"><img src="'+base_href+'VAImageBox/next.png" alt="'+text_Weiter+'" border="0"></a>';
				next_i = '<a href="#" onclick="show_image(gallery_images[\''+xgal+'\']['+(parseInt(img_key)+1)+']); return false;"><img src="/tp/VAImageBox/next.png" alt="'+text_Weiter+'" border="0"></a>';
			}
			// if(prev != "" && next_i != "") prev += '|';
		}
		$("fade2black").style.display = "";
		if(scrolledY == false)
		{
			if(window.pageYOffset) scrolledY = window.pageYOffset;
			else if(document.body.scrollTop) scrolledY = document.body.scrollTop;
			else if(document.documentElement.scrollTop) scrolledY = document.documentElement.scrollTop;
			else scrolledY = 0;
			// alert(scrolledY);
		}
		else window.scrollTo(0, scrolledY);
		set_fade2black_position_IE_lt_v6(scrolledY);
		
		// load html from config
		xhtml = ihtml;
		
		//
		xrepcacements = new Object();
		xrepcacements["path_image"]				= path_image;
		xrepcacements["preview_images"]			= getBoxPreviewImages(ximage);
		xrepcacements["innerCSSclass"]			= innerCSSclass;
		xrepcacements["loading_image"]			= loading_image;
		xrepcacements["margin_top"]				= (parseInt(scrolledY) + margin_top);
		xrepcacements["title"]					= (ximage.title != "") ? '' + ximage.title : '';
		xrepcacements["imgurl"]					= ximage.imgurl;
		xrepcacements["imgname"]				= strrchr("/", ximage.imgurl).substr(1);
		xrepcacements["prev"]					= prev;
		xrepcacements["image_width"]			= image_width;
		xrepcacements["image_height"]			= image_height;
		xrepcacements["preview_img_width"]		= preview_img_width;
		xrepcacements["preview_img_height"]		= preview_img_height;
		xrepcacements["galinfo"]				= (xgal) ? text_Bild+' '+(ximage.imgnr + 1)+" "+text_von+" "+(gallery_images[xgal].length) : '';
		xrepcacements["next"]					= next_i;
		xrepcacements["text_Close"]				= text_Close;
		xrepcacements["image"]					= img_src;
		
		for(rkey in xrepcacements)
		{
			repl = eval("/\{"+rkey+"\}/gi");
			xhtml = xhtml.replace(repl, xrepcacements[rkey]);
		}
		delete(xrepcacements);
		//
		
		$("blocker").innerHTML = xhtml;
		// $("gallery_image").src="/image.php?src="+img_src;
		// $("gallery_image").src=path_image.replace(/{image}/, img_src);
		is_loaded();
		popup_2_show = $('blocker');
		popup_fade2black();
	}
	function show_ajax(url)
	{
		$("fade2black").style.display = "";
		if(scrolledY == false)
		{
			if(window.pageYOffset) scrolledY = window.pageYOffset;
			else if(document.body.scrollTop) scrolledY = document.body.scrollTop;
			else if(document.documentElement.scrollTop) scrolledY = document.documentElement.scrollTop;
			else scrolledY = 0;
			// alert(scrolledY);
		}
		else window.scrollTo(0, scrolledY);
		set_fade2black_position_IE_lt_v6(scrolledY);
		
		// load html from config
		xhtml = ahtml;
		
			//
		xrepcacements = new Object();
		xrepcacements["innerCSSclass"]	= innerCSSclass;
		xrepcacements["loading_image"]	= loading_image;
		xrepcacements["margin_top"]		= (parseInt(scrolledY) + margin_top);
		xrepcacements["text_Close"]		= text_Close;
		
		for(rkey in xrepcacements)
		{
			repl = eval("/\{"+rkey+"\}/gi");
			xhtml = xhtml.replace(repl, xrepcacements[rkey]);
		}
		delete(xrepcacements);
		//
		
		$("blocker").innerHTML = xhtml;
		//
		if(url != false) loadPage(url, "gallery_ajax");
		is_loaded();
		//
		popup_2_show = $('blocker');
		popup_fade2black();
	}
	
	function is_loaded()
	{
		if($("gallery_image"))
		{
			ximg = $("gallery_image");
			if(ximg.complete == true)
			{
				// $("gallery_image_box").style.backgroundImage="none";
				ximg.style.display = "";
			}
			else
			{
				window.setTimeout("is_loaded()", 100);
			}
		}
		else if($("gallery_ajax"))
		{
			if($("gallery_ajax").innerHTML != "")
			{
				$("gallery_ajax").style.backgroundImage="none";
			}
			else
			{
				window.setTimeout("is_loaded()", 100);
			}
		}
		// else alert("no status available.");
	}
	function close_gallery()
	{
		$("blocker").innerHTML = "";
		$("blocker").style.display = "none";
		popup_fade2white();
		window.scrollTo(0, scrolledY);
		scrolledY = false;
		show_dropdowns();
	}
	
	function gallery_keyEvents(ev)
	{
		if($("blocker").style.display != "none")
		{
			if(!ev)
			{
				ev = window.event;
			}
			kk = ev.keyCode;
			// alert(kk);
			// alert(ev.ctrlKey);
			/*if(ev.ctrlKey == true && kk == 82)
			{
				
			}
			else */if(kk == 27) // escape
			{
				close_gallery();
				return false;
			}
			else if(kk == 37) // arrow right
			{
				// alert(xgal);
				if($("gallery_image"))
				{
					if(xgal != false && img_key != false && parseInt(img_key) > 0)
					{
						show_image(gallery_images[xgal][parseInt(img_key)-1]);
					}
				}
				return false;
			}
			else if(kk == 39) // arrow left
			{
				if($("gallery_image"))
				{
					if(xgal != false && (img_key != false || img_key == "0") && parseInt(img_key) < parseInt(gallery_images[xgal].length)-1)
					{
						show_image(gallery_images[xgal][parseInt(img_key)+1]);
					}
				}
				return false;
			}

		}
	}
	
	function set_fade2black_position_IE_lt_v6(y_pos)
	{
		low_ie = false;
		for(vers=3;vers<7;vers++)
		{
			if(navigator.userAgent.indexOf('MSIE '+vers)>0)
			{
				low_ie = true;
				break;
			}
		}
		if(low_ie == true)
		{
			$("fade2black").style.position = "absolute";
			// $("fade2black").style.top = y_pos+"px";
			$("fade2black").style.top = "0px";
			body_height = document.body.offsetHeight;
			window_height = document.body.clientHeight;
			fade2black_height = (window_height>body_height) ? window_height : body_height;
			$("fade2black").style.height = (fade2black_height)+"px";
			hide_dropdowns();
		}
	}
	var dropdowns = new Array();
	function hide_dropdowns()
	{
		if(dropdowns.length<1) dropdowns = new Array();
		if(dropdowns.length<1)
		{
			alldropdowns = document.getElementsByTagName("select");
			cnt = 0;
			for(d=0; d<alldropdowns.length; d++)
			{
				if(alldropdowns[d].style.visibility != "hidden")
				{
					dropdowns[cnt] = alldropdowns[d];
					cnt++;
				}
			}
			for(d=0; d<dropdowns.length; d++)
			{
				dropdowns[d].style.visibility = "hidden";
			}
		}
	}
	function show_dropdowns()
	{
		for(d=0; d<dropdowns.length; d++)
			{
				dropdowns[d].style.visibility = "visible";
			}
			dropdowns = new Array();
	}
	var blind_gallery_images = new Array();
	function addBlindImage(imgsrc, title, xgallery)
	{
		if(!blind_gallery_images[xgallery]) blind_gallery_images[xgallery] = new Array();
		xcnt = blind_gallery_images[xgallery].length;
		blind_gallery_images[xgallery][xcnt] = new Object();
		blind_gallery_images[xgallery][xcnt].imgurl = imgsrc;
		// blind_gallery_images[xgallery][xcnt].imgnr = xcnt; // FEHLER DARF ERST BEI initGallery() REIN
		blind_gallery_images[xgallery][xcnt].gallery = xgallery;
		blind_gallery_images[xgallery][xcnt].title = title;
	}
	function search4items()
	{
		
		gallery_images = new Object();
		//
		imgs = document.getElementsByTagName("img");
		lnks = document.getElementsByTagName("a");
		getGalleryImages(imgs);
		getGalleryImages(lnks);
		//
		// alert("blind");
		for(g in blind_gallery_images)
		{
			for(i in blind_gallery_images[g])
			{
				if(!gallery_images[g]) gallery_images[g] = new Array();
				xcnt = gallery_images[g].length;
				// alert(blind_gallery_images[g][i]);
				gallery_images[g][parseInt(xcnt)] = blind_gallery_images[g][i];
				gallery_images[g][xcnt].imgnr = xcnt;
				// alert(gallery_images[g][xcnt].imgurl + " ?= " + blind_gallery_images[g][i].imgurl);
			}
		}	
	}
	function initGallery()
	{
		body_el = document.getElementsByTagName("body")[0];
		//
		body_el.appendChild(fade2black);
		//
		body_el.appendChild(blocker);
		//
		/*
		imgs = document.getElementsByTagName("img");
		lnks = document.getElementsByTagName("a");
		getGalleryImages(imgs);
		getGalleryImages(lnks);
		//
		//if(blind_gallery_images.length > 0)
		{
			// alert("blind");
			for(g in blind_gallery_images)
			{
				for(i in blind_gallery_images[g])
				{
					if(!gallery_images[g]) gallery_images[g] = new Array();
					xcnt = gallery_images[g].length;
					// alert(blind_gallery_images[g][i]);
					gallery_images[g][parseInt(xcnt)] = blind_gallery_images[g][i];
					gallery_images[g][xcnt].imgnr = xcnt;
					// alert(gallery_images[g][xcnt].imgurl + " ?= " + blind_gallery_images[g][i].imgurl);
				}
			}
		}
		*/
		search4items();
		document.onkeydown = gallery_keyEvents;
	}
