function loadGallery (imgid,pfad,imgAr,imgBeschreibung,firstimg){
	window.addEvent('domready', function() {
		var el = $(imgid);
		preloadIMG ();
		imgcount = firstimg;
		counter (firstimg);
		
		// onclick next
		/*$('next').addEvent('click', function(e) {
			// You often will need to stop propagation of the event
			e.stop();
			el.setOpacity(0);
			counter ("next");
		})
		// onclick preview
		$('pre').addEvent('click', function(e) {
			// You often will need to stop propagation of the event
			e.stop();
			el.setOpacity(0);
			counter ("pre");
		});*/
		// onclick thumb
		$$('#thumb a').each(function(div){
			aname = div.id;
			$(aname).addEvent('click', function(e){
				var id = this.id.substr(3);
				e.stop();
				el.setOpacity(0);
				counter (id);
			});
		});
		// bild austauschen und faden
		function showimg (){
			el.src = pfad+imgAr[imgcount];
			el.fade(1);
		}
		// array position ermitteln
		function counter (todo){
			switch (todo){
				case "next":
					imgcount ++;
					if (imgcount > imgAr.length-1){
						imgcount = 0;
					}
					break;
				case "pre":
					imgcount --;
					if (imgcount < 0){
						imgcount = imgAr.length-1;
					}
					break;
				default:
					imgcount = Number(todo);
			}
			isimg ();
			return imgcount;
		}
		// text
		function isimg (){
			//$('isimg').innerHTML = (imgcount+1)+"/"+imgAr.length;
			showimg ();
		}
		// alle bilder preloaden und thumb erstellen
		// alle bilder preloaden und thumb erstellen
		function preloadIMG (){
			var thumb = "";
			for (i=0; i < imgAr.length; i++) {
				var img = new Image();
				img.src = pfad+imgAr[i];
				thumb += "<a href='#' id='img"+i+"' class='bild_"+i+"'><img src=\"images/transparent.gif\" width=16 height=9 border=0>";
				
				if(imgBeschreibung[i]!=""){
				thumb += "<div class='bild_tooltip' id='bild_tooltip_"+i+"'>"+imgBeschreibung[i]+"</div>";
				}
				
				thumb += "</a>";
			}
			$('thumb').innerHTML = thumb+"";
			return true;
		}
		
		
	});
	
}
