
var galInterval = 10000; // Zeit in ms zwischen Bildwechsel f�r Gallery
var galDuration = 1800; // Dauer Fade in ms f�r Gallery

$(function() {
	
	if(typeof(galImages) != "undefined" && galImages.length > 0) {
		setInterval("changeImageGallery()", galInterval);
		
		$(galImages).each(function(Key, Image) {
			if (Key == 0)  {
				$("#gallery a:first").replaceWith("<a href='" + Image[0] + "' rel='clearbox[Bild]' title='" + Image[1] + "' onclick='return false'><img src='" 
					+ Image[0] + "&w=287&h=180' style='position: absolute; top: 0px; left: 0px; border:0;' /></a>");
			}
			else {
				$("#gallery").append("<a href='" + Image[0] + "' rel='clearbox[Bild]'  title='" + Image[1] + "' onclick='return false'><img src='" 
					+ Image[0] + "&w=287&h=180' style='position: absolute; top: 0px; left: 0px;  border:0; display: none'  /></a>");
			}
			
			
		});	
		
		$("#gallery").append('<img src="../../themes/default/img/layout/lupe.png" id="lupe" ' 
			+ ' style="position: absolute; top: 100px; left: 268px; z-index: 9999; cursor: pointer">');
			
		$("#lupe").click(function() {

			var tmpCurrent = galCurrent - 1;
			
			if(tmpCurrent < 0)
				tmpCurrent = 0;
			
				$('#gallery').children("a:nth(" + tmpCurrent + ")").click();
		});
	}
});

var galCurrent = 1;
var galPos = 0;

function changeImageGallery() {
	if (galCurrent == galImages.length)
		galCurrent = 0;
		
	$('#gallery').children("a:nth(" + galCurrent + ")").children("img").hide().css("z-index", galPos).fadeIn(galDuration);
		
	galPos++;
	galCurrent++;
}
