
$(document).ready(function() {
	
	// text an untere pos verschieben
	textposition ();
	
	// xml def btn blendet gal ein
	$("img#galBtn").click(function() {
		
		$("div#overlay").fadeIn("fast", function () {
				$("body").css("overflow-y", "hidden");
				window.scrollTo(0, 0);
				$("div#gallery").fadeIn("slow");
			});
	});
	
	// close btn blendet gal aus
	$("div.close").click(function() {
		$("body").css("overflow-y", "scroll");
		$("div#gallery").fadeOut("slow", function () {
			$("div#overlay").fadeOut("fast");
		});
	});
		
	// btn aktionen zuweisen
	$("img#galLeft").click(function() {
		var thumbslideML = parseInt($("#gallery div.thumbnailBox div.thumbslide").css("marginLeft"));
		var thumbnailLC = parseInt($("div.thumbnail:last-child").css("marginLeft"));
		if (thumbslideML > -1*(thumbnailLC+(-(772+55)))) {
			$("#gallery div.thumbnailBox div.thumbslide").animate({marginLeft: '-=772px'}, 1000);
		}
	});
	
	$("img#galRight").click(function() {
		if (parseInt($("#gallery div.thumbnailBox div.thumbslide").css("marginLeft")) < 0) {
			$("#gallery div.thumbnailBox div.thumbslide").animate({marginLeft: '+=772px'}, 1000);
		}
	});
	
	// thumbnails bildwechsel
	
	$("div.thumbnail").click(function() {
		var newImg = $(this).attr("title");
		var imgTxt = $(this).children("span").html();
		
		$("#gallery").css("background-image", "url(../../img/gallerys/"+newImg+")");
		$("#gallery div.beschreibung").html(imgTxt);
		
		if (imgTxt != "") {
			$("#gallery div.beschreibung").css("display", "block");
			textposition ();
		} else {
			$("#gallery div.beschreibung").css("display", "none");
		}
	});

});

function textposition () {
	var imgText = ($("#gallery div.beschreibung").height())+14;
	$("div#gallery div.beschreibung").css("margin-top", (520-imgText));
	}
