function refreshImages() {
    
	if (mediaGalery[media_type].length > 0) {
	     
		$('div_Thumbs').style.display = '';
		$('div_NoThumbs').style.display = 'none';
		
		if ( mediaGalery[media_type].length > 0) {
			showThumb(0,0); 
		} else {
			hideThumb(0);
		}
		if ( mediaGalery[media_type].length > 1) {
			showThumb(1,1); 
		} else {
			hideThumb(1);
		}
		if ( mediaGalery[media_type].length > 2) {
			showThumb(2,2); 
		} else {
			hideThumb(2);
		}
		if ( mediaGalery[media_type].length > 3) {
			showThumb(3,3); 
		} else {
			hideThumb(3);
		}
		if ( mediaGalery[media_type].length > 4) {
			showThumb(4,4); 
		} else {
			hideThumb(4);
		}
		if ( mediaGalery[media_type].length > 5) {
			showThumb(5,5); 
		} else {
			hideThumb(5);
		}	
	} else {		
		$('div_Thumbs').style.display = 'none';
		$('div_NoThumbs').style.display = '';		
	}
}
function hideThumb(pos) {
	
	cl = $('thumb' + pos)
	if (cl != null) {
		cl.style.display = 'none';
	}
	
	cl = document.getElementById('gallery_thumb_'+pos);
	if ( cl != null ) {
		cl.className='';
		cl.src = liveSite + '/resources/CSS/images/spacer.gif';
		cl.alt = '';
		cl.title = '';
		cl.className = 'hidden';
	}	
	cl = document.getElementById('gallery_thumb_href1_'+pos);
	if ( cl != null ) {
		cl.href="#";
	}	
}

function showThumb(pos,id) {
	
	cl = $('thumb' + pos)
	if (cl != null) {
		cl.style.display = '';
	}
	
	cl = document.getElementById('gallery_thumb_'+pos);
	if ( cl != null ) {
		if (id == currentSelected && gal24 == false ) {
			cl.className = 'topangeboteimg';
		} else {
			cl.className = 'topangeboteimg';
		}
		cl.src = mediaGalery[media_type][id]['smallImage'];
	}
	
	if ( media_type == 5 ){
	    cl1 = document.getElementById('gallery_thumb_href1_'+pos);
	    cl1.href = hrefDocuments[pos]; 
	    cl1.target= "_blank";
            cl1.onclick = function() { }
   	}else{
   		cl1 = document.getElementById('gallery_thumb_href1_'+pos);
	    cl1.href = "javascript:void(0)"; 
	    cl1.target= "";
        cl1.onclick = function() {return showBigImage(pos);}  
   	}
	
	
	if ( gal24 == true ) {
		cl = document.getElementById('gallery_thumb_href1_'+pos);
		if ( cl != null ) {
				cl.href = mediaGalery[media_type][id]['linkToGal'];
		}	
	}
}

function showBigImage(pos) {
	foundId = current+pos;
	
	if ( foundId < mediaGalery[media_type].length) {
		
		currentSelected = foundId;

		cl = document.getElementById('image_gallery_cur_image');
		if ( cl != null ) cl.innerHTML = foundId+1;
		cl = document.getElementById('total_medias');
		if ( cl != null ) cl.innerHTML = total_sizes[media_type];
		
		cl = document.getElementById('gallery_thumb_0');
		if ( cl != null ) cl.className = 'topangeboteimg';
		cl = document.getElementById('gallery_thumb_1');
		if ( cl != null ) cl.className = 'topangeboteimg';
		cl = document.getElementById('gallery_thumb_2');
		if ( cl != null ) cl.className = 'topangeboteimg';
		cl = document.getElementById('gallery_thumb_3');
		if ( cl != null ) cl.className = 'topangeboteimg';
		cl = document.getElementById('gallery_thumb_4');
		if ( cl != null ) cl.className = 'topangeboteimg';
		
		cl = document.getElementById('gallery_thumb_'+pos);
		if ( cl != null ) cl.className = 'topangeboteimg';
		cl = document.getElementById('gallery_thumb_href1_'+pos);
		if ( cl != null ) cl.blur();

		if (media_type == 2) { // Video 
			cl = $('div_videoPlayer');
			if (cl != null)
				cl.innerHTML = '<div id="player1" style="float: left;"><embed type="application/x-shockwave-flash" src="' + liveSite + '/resources/videoPlayer/flvplayer.swf" style="" id="mpl" name="mpl" quality="high" allowfullscreen="true" flashvars="file=' + mediaGalery[media_type][foundId]['videoFile'] + '&amp;image=' + mediaGalery[media_type][foundId]['bigImage'] + '&amp;javascriptid=mpl" height="246" width="350"></div><script type="text/javascript">var s1 = new SWFObject("' + liveSite + '/resources/videoPlayer/flvplayer.swf", "mpl", "350", "246", "7");s1.addParam("allowfullscreen", "true");s1.addVariable("file", "' + mediaGalery[media_type][foundId]['videoFile'] + '");s1.addVariable("image", "' + mediaGalery[media_type][foundId]['bigImage'] + ');s1.addVariable("javascriptid","mpl");s1.write("player1");</script>';			
		} else if (media_type == 4) {
			if (mapExists) {
				// load map
				loadMap(xPoint, yPoint, accuracy);
			} else {
				loadMap();
			}
		} else {
			swapImages(mediaGalery[media_type][foundId]['bigImage']);
		}
	} else {
	
		// display default image	
	
		if (media_type == 2 || media_type == 4)
		{
			changeBigImageDiv(1);
		}
	
		swapImages(name_placeholder_image);
	}
	return false;
}

function moveImagesRight(sender) {
	if ( current < mediaGalery[media_type].length-imgsInList ) {

		sender.blur();
		current++;
		showThumb(0,current); 
		showThumb(1,current+1); 
		showThumb(2,current+2); 
		showThumb(3,current+3); 
		showThumb(4,current+4); 
		showThumb(5,current+5);
	}
	correctSideBars();

	return false;
}

function moveImagesLeft(sender) {
	if ( current > 0) {
		sender.blur();
		current--;
		showThumb(0,current); 
		showThumb(1,current+1); 
		showThumb(2,current+2); 
		showThumb(3,current+3); 
		showThumb(4,current+4); 
		showThumb(5,current+5);
	}
	correctSideBars();
	return false;
}
//class="detailsbookmarkbox"
function correctSideBars() {
	bar = document.getElementById('gallery_left_bar');
	if ( bar != null ) {
		if ( current != 0 ){
			bar.innerHTML = leftArrow;
		} else {			
			bar.innerHTML = '';			
		}
	}
	
	bar = document.getElementById('gallery_right_bar');
	if ( bar != null ) {
		if ( current < mediaGalery[media_type].length-imgsInList ){
			bar.innerHTML = rightArrow;
		} else {		
			bar.innerHTML = '';
		}
	}		
}

function startSlideShow() {
	if ( doSlideShow == false ) {
		doSlideShow = true;
		document.getElementById('slide_show').value = "Pause";
		doPlayShow();
	}
	return false;
}

function StopSlideShow() {
	document.getElementById('slide_show').value = "Slide show";
	doSlideShow = false;
	curImageToLoad = false;
}

function startStopSlideShow() {
	if ( doSlideShow == false )	{
		startSlideShow();
	} else {
		StopSlideShow();
	}
	return false;
	
}

function imageLoded() {
	if ( doSlideShow == true ) {
		if ( ie ) {
			document.images.big_image_img.style.filter="revealTrans(duration=1, transition="+Math.floor(Math.random()*13)+")";
	    	document.images.big_image_img.filters.revealTrans.Apply();
	    	document.images.big_image_img.filters.revealTrans.Play();
		}
		document.images.big_image_img.src = curImage.src;
		
		//b_description = document.getElementById('big_image_description');
		//b_title = document.getElementById('big_image_title');
	
		//b_description.innerHTML = curDesc;
		//b_title.innerHTML = curTitle;

		cl = document.getElementById('image_gallery_cur_image');
		if ( cl != null ) cl.innerHTML = curCurrent+1;
		
	}
	curImageToLoad = false;
}


var curImage = new Image();
curImage.onload = imageLoded;
var curImageToLoad = false;
var curDesc = '';
var curTitle = '';
var curCurrent = 0;

function swapInSlideShow(str,desc,title,curr) {
	curImageToLoad = true;
	curImage.src = str;
	curTitle = title;
	curCurrent = curr;
}

function swapImages(str) {
	document.images.big_image_img.src = str;
	if ((str == name_placeholder_image) || (bigImageWithoutURL)) {
		$('big_image_url').href = '#';
		$('big_image_url').onclick = '';
	} else {
		$('big_image_url').href = '';
		$('big_image_url').onclick = openInNewWindow;
	}
}

function doPlayShow() {
	if ( doSlideShow == true ) {
		if ( curImageToLoad == false ) {
			currentSelected++;
			if ( currentSelected >= mediaGalery.length ) {
				currentSelected = 0;
			}
	    	swapInSlideShow(
	    		mediaGalery[currentSelected]['fullImage'],
	    		mediaGalery[currentSelected]['title'],
	    		currentSelected
	    		);
		}
		setTimeout('doPlayShow()',slideShowDelay);
	}
}
 
function activateTab(tabID) {
	$(tabID).style.color = '#E6005C';
	$(tabID).style.background = 'url(' + liveSite + '/resources/CSS/images/bg_detailsbookmarkaktive.gif) repeat-x left top';
	$(tabID).blur();
}

function setTabInactive(tabID) {
	$(tabID).style.color = '';
	$(tabID).style.background = 'url(' + liveSite + '/resources/CSS/images/bg_detailsbookmarkpunkt.gif) repeat-x left top';
	$(tabID).blur();
}

function setMediaType(tab, type) {
	var tab1, tab2, tab3;

	if (tab == 'Tab1') {
		$('tab1_1').innerHTML = search_left_active;
		$('tab1_2').className = 'box_buttonactive';
		$('tab1_2').innerHTML = '<div class="box_buttonactive_text" id="TTab1">' + text1 + '</div>';
		$('tab1_3').innerHTML = search_right_active;

		$('tab2_1').innerHTML = '';
		$('tab2_2').className = 'box_buttoninactive';
		$('tab2_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab2"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab2\', 2);">' + text2 + '</a></div>';
		$('tab2_3').innerHTML = search_right_inactive;
		
		$('tab3_1').innerHTML = '';
		$('tab3_2').className = 'box_buttoninactive';
		$('tab3_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab3"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab3\', 3);">' + text3 + '</a></div>';
		$('tab3_3').innerHTML = search_right_inactive;
		
		$('tab4_1').innerHTML = '';
		$('tab4_2').className = 'box_buttoninactive';
		$('tab4_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab4"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab4\', 4);">' + text4 + '</a></div>';
		$('tab4_3').innerHTML = search_right_inactive;		
		
		$('tab6_1').innerHTML = '';
		$('tab6_2').className = 'box_buttoninactive';
		$('tab6_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab6"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab6\', 5);">' + text6 + '</a></div>';
		$('tab6_3').innerHTML = search_right_inactive;
				
	}

	if (tab == 'Tab2') {
		$('tab1_1').innerHTML = search_left_inactive;
		$('tab1_2').className = 'box_buttoninactive';
		$('tab1_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab1"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab1\', 1);">' + text1 + '</a></div>';
		$('tab1_3').innerHTML = '';

		$('tab2_1').innerHTML = search_left_active;
		$('tab2_2').className = 'box_buttonactive';
		$('tab2_2').innerHTML = '<div class="box_buttonactive_text" id="TTab2">' + text2 + '</div>';
		$('tab2_3').innerHTML = search_right_active;
		
		$('tab3_1').innerHTML = '';
		$('tab3_2').className = 'box_buttoninactive';
		$('tab3_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab3"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab3\', 3);">' + text3 + '</a></div>';
		$('tab3_3').innerHTML = search_right_inactive;
		
		$('tab4_1').innerHTML = '';
		$('tab4_2').className = 'box_buttoninactive';
		$('tab4_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab4"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab4\', 4);">' + text4 + '</a></div>';
		$('tab4_3').innerHTML = search_right_inactive;				
		
		$('tab6_1').innerHTML = '';
		$('tab6_2').className = 'box_buttoninactive';
		$('tab6_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab6"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab6\', 5);">' + text6 + '</a></div>';
		$('tab6_3').innerHTML = search_right_inactive;		
						
	}	
	
	if (tab == 'Tab3') {
		$('tab1_1').innerHTML = search_left_inactive;
		$('tab1_2').className = 'box_buttoninactive';
		$('tab1_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab1"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab1\', 1);">' + text1 + '</a></div>';
		$('tab1_3').innerHTML = search_right_inactive;

		$('tab2_1').innerHTML = '';
		$('tab2_2').className = 'box_buttoninactive';
		$('tab2_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab2"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab2\', 2);">' + text2 + '</a></div>';
		$('tab2_3').innerHTML = '';
		
		$('tab3_1').innerHTML = search_left_active;
		$('tab3_2').className = 'box_buttonactive';
		$('tab3_2').innerHTML = '<div class="box_buttonactive_text" id="TTab3">' + text3 + '</div>';
		$('tab3_3').innerHTML = search_right_active;
		
		$('tab4_1').innerHTML = '';
		$('tab4_2').className = 'box_buttoninactive';
		$('tab4_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab4"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab4\', 4);">' + text4 + '</a></div>';
		$('tab4_3').innerHTML = search_right_inactive;				
		
		$('tab6_1').innerHTML = '';
		$('tab6_2').className = 'box_buttoninactive';
		$('tab6_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab6"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab6\', 5);">' + text6 + '</a></div>';
		$('tab6_3').innerHTML = search_right_inactive;
						
	}		
	
	if (tab == 'Tab4') {
		$('tab1_1').innerHTML = search_left_inactive;
		$('tab1_2').className = 'box_buttoninactive';
		$('tab1_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab1"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab1\', 1);">' + text1 + '</a></div>';
		$('tab1_3').innerHTML = search_right_inactive;

		$('tab2_1').innerHTML = '';
		$('tab2_2').className = 'box_buttoninactive';
		$('tab2_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab2"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab2\', 2);">' + text2 + '</a></div>';
		$('tab2_3').innerHTML = search_right_inactive;
		
		$('tab3_1').innerHTML = '';
		$('tab3_2').className = 'box_buttoninactive';
		$('tab3_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab3"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab3\', 3);">' + text3 + '</a></div>';
		$('tab3_3').innerHTML = '';
		
		$('tab4_1').innerHTML = search_left_active;
		$('tab4_2').className = 'box_buttonactive';
		$('tab4_2').innerHTML = '<div class="box_buttonactive_text" id="TTab4">' + text4 + '</div>';
		$('tab4_3').innerHTML = search_right_active;				
		
		$('tab6_1').innerHTML = '';
		$('tab6_2').className = 'box_buttoninactive';
		$('tab6_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab6"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab6\', 5);">' + text6 + '</a></div>';
		$('tab6_3').innerHTML = search_right_inactive;
						
	}		

	if (tab == 'Tab6') {
		$('tab1_1').innerHTML = search_left_inactive;
		$('tab1_2').className = 'box_buttoninactive';
		$('tab1_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab1"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab1\', 1);">' + text1 + '</a></div>';
		$('tab1_3').innerHTML = search_right_inactive;

		$('tab2_1').innerHTML = '';
		$('tab2_2').className = 'box_buttoninactive';
		$('tab2_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab2"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab2\', 2);">' + text2 + '</a></div>';
		$('tab2_3').innerHTML = search_right_inactive;
		
		$('tab3_1').innerHTML = '';
		$('tab3_2').className = 'box_buttoninactive';
		$('tab3_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab3"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab3\', 3);">' + text3 + '</a></div>';
		$('tab3_3').innerHTML = '';
		
		$('tab4_1').innerHTML = '';
		$('tab4_2').className = 'box_buttoninactive';
		$('tab4_2').innerHTML = '<div class="box_buttoninactive_text" id="TTab4"><a href="javascript:void(0)" class="boxnavioben" onclick="return setMediaType(\'Tab4\', 4);">' + text4 + '</a></div>';
		$('tab4_3').innerHTML = search_right_inactive;
		
		$('tab6_1').innerHTML = search_left_active;
		$('tab6_2').className = 'box_buttonactive';
		$('tab6_2').innerHTML = '<div class="box_buttonactive_text" id="TTab6">' + text6 + '</div>';
		$('tab6_3').innerHTML = search_right_active;
		
	}		


	media_type = type;
	current = 0;
	currentSelected = 0;
	correctSideBars();
	refreshImages();				
		
	changeBigImageDiv(type);
	showBigImage(0);
}

function changeBigImageDiv(type) {
	if (type == 2) { // Video
		$('div_imageContainer').style.display = 'none';
		$('div_videoPlayer').style.display = '';
		$('div_Map').style.display = 'none';
	} else if (type == 4) {
		$('div_imageContainer').style.display = 'none';
		$('div_videoPlayer').style.display = 'none';
		$('div_Map').style.display = '';
	}	
	else {
		$('div_imageContainer').style.display = '';
		$('div_videoPlayer').style.display = 'none';
		$('div_Map').style.display = 'none';		
	}	
}

function goNext() {
	if (currentSelected + 1 < mediaGalery.length) {
		currentSelected = currentSelected + 1;
		swapImages(mediaGalery[currentSelected]['fullImage']);
	}
	return false;
}

function goPrevious() {
	if (currentSelected > 0) {
		currentSelected = currentSelected - 1;
		swapImages(mediaGalery[currentSelected]['fullImage']);
	}
	return false;
}

// Opens full image size in new window
function openInNewWindow() {
	var theURL = ((window.location.href.lastIndexOf('#')==window.location.href.length-1) ? window.location.href.substring(0,window.location.href.length-1)  : window.location.href)  + '/viewType:1/imageId:' + mediaGalery[media_type][currentSelected]['id'] + '/currentMedia:' + currentSelected;
	var features = 'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=1, width=830, height=686';

	window.open(theURL, '', features);
	return false;
}

function loadMap(xCoodrinate, yCoordinate, accuracy) {

	// check if all required perameters are provided
	if (xCoodrinate && yCoordinate && accuracy) {
		// load the google map
	
		$('div_Map').innerHTML = '<div id="map" style="width: 350px; height: 246px"></div>';
	
		var lat = yCoordinate;
		var lon = xCoodrinate;
		var accuracy = accuracy;
		var acc_text="";
		
		if (accuracy !=""){
			switch (accuracy){
				case 7:
				case 6:
    					acc_text ="<table><tr><td>Vom gewählten Objekt ist keine Hausnummer bekannt. Deshalb erscheint in der Karte die Strasse als Mittelpunkt des Bildes.</td></tr></table>";
  				break; 
  				
  				case 4:
  				case 5:
    					acc_text ="<table><tr><td>Vom gewählten Objekt ist nur der Ortsname bekannt. Deshalb erscheint in der Karte die Ortschaft als Mittelpunkt des Bildes.</td></tr></table>";
  				break; 
			}
		}	
		
		if (GBrowserIsCompatible()) {
			var map = new GMap2($("map"));
			point = new GLatLng(lat,lon);
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			
			map.enableScrollWheelZoom();
			map.setCenter(point, 15);
			map.setMapType(G_HYBRID_MAP);

			marker = new GMarker(point);
			map.addOverlay(marker);
			if (acc_text !=""){
				marker.openInfoWindowHtml(acc_text,{maxWidth:250});
			}
		}
	
		GEvent.addListener(map, "infowindowclose", function() {
          map.setCenter(point, 15);		
        });
		
	} else {
		// load the placeholder
		$('div_Map').innerHTML = placeholder_image;
	}
}

