$(function() {
	$("#gallerySelect").sSelect();

	$("#gallerySelect").change(function () {
		location.href = $("#gallerySelect option:selected").val();
	});

	$("a[rel=gallerySmallLink]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'inside',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
			titleOut = "";
			if (title != bildbezeichnung)
				titleOut = title;
						
			return '<span id="fancybox-title-inside">' + bildbezeichnung + ' ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + titleOut + '</span>';
		}
	});
	
	if ((jQuery.browser.version >= 7 && $.browser.msie) || !$.browser.msie) {
		$(".img169x114").each(function() {		// Bilder mit Rahmen erzeugen
			imgSrc = $(this).attr("src");
			$(this).attr("src", "./img/imageRahmen_169x114.png").css("background-image", 'url("' + imgSrc + '")').removeAttr("height").removeAttr("width").attr("width", "190").attr("height", "132");
		});
		$(".img52x52").each(function() {		// Bilder mit Rahmen erzeugen
			imgSrc = $(this).attr("src");
			$(this).attr("src", "./img/imageRahmen_52x52.png").css("background-image", 'url("' + imgSrc + '")').removeAttr("height").removeAttr("width").attr("width", "81").attr("height", "76");
		});
	}
	
	if (jQuery.browser.version < 7 && $.browser.msie) {
		$("#pageTitelbild").pngFix();
	}
	
});

function gallerySmallNavigate(direction) {		// 1 = next, 0 = prev
	anzahlBilder = parseFloat($(".gallerySmallUL li").size());
	liWidth = parseFloat($(".gallerySmallUL li").css("width").replace(/px$/, ""));
	liPadding = parseFloat($(".gallerySmallUL li").css("padding-left").replace(/px$/, "")) +  parseFloat($(".gallerySmallUL li").css("padding-right").replace(/px$/, ""));

	curLeft = parseFloat($(".gallerySmallUL").css("left").replace(/px$/, ""));
	maxWidth = parseFloat($(".gallerySmall").css("width").replace(/px$/, ""));
	minLeft = anzahlBilder * (liWidth + liPadding) * -1;
	maxLeft = 0;

	if (direction == 1) {
		if (curLeft-maxWidth > minLeft) {
			$(".gallerySmallUL").animate({"left": "-="+maxWidth+"px"}, "slow");
		}
	}
	else {
		if (curLeft+maxWidth <= maxLeft) {
			$(".gallerySmallUL").animate({"left": "+="+maxWidth+"px"}, "slow");
		}
	}
}

function navigateNews(direction) {
	var left = parseInt($('#newsAreaScroll').css('left'));
	
	if (direction == "prev") {
		$("#newsAreaScroll").animate({"left": "+=400px"});
		left += 400;
	}
	else {
		$("#newsAreaScroll").animate({"left": "-=400px"});
		left -= 400;
	}
	
	if (left >= 0)
		$("#newsButtonPrev").hide();
	else
		$("#newsButtonPrev").show();
	
	
	if (left <= (newsCnt-2) * (-400) )
		$("#newsButtonNext").hide();
	else
		$("#newsButtonNext").show();
}
		
