/******************************************************************************************
 * Copyright by Spätzlefresser - All rights reserved.
 * Autor: Bernd Lutz Websolutions ( http://www.berndlutz.com )
 * Letzte Änderung: 24.08.2009
 *****************************************************************************************/


var SlideShow = {
	
	num: 0,
	n: 0,
	
	
	init: function()
	{
		this.num = $("#photo-list li").length;
		
		if ( this.images == 1 )
		{
			$("#photo-list, p.nav").remove();
		}
		
		else
		{
			$("#photo-list a").click(this.select);
			$(".nav .next").click(this.next);
			$(".nav .prev").click(this.previous);
			
			$("#photo-list a:first").addClass("active");
			
			SlideShow.setNav();
		}
	},
	
	
	set: function(n)
	{
		SlideShow.n = n;
		var img = $("#photo-list img").get(n);
		
		$("#big-img").attr("src", img.src.replace(/\/thumbnails/, ""));
		$("#img-info").html($(img).attr("alt"));

		$("#photo-list a").removeClass();
		$(img.parentNode).addClass("active");
		
		SlideShow.setNav();
	},
	
	
	next: function(e)
	{
		e.preventDefault();
		SlideShow.set(SlideShow.n + 1);
	},
	
	
	previous: function(e)
	{
		e.preventDefault();
		SlideShow.set(SlideShow.n - 1);
	},
	
	
	select: function(e)
	{
		e.preventDefault();
		SlideShow.set($(this).parent("li").prevAll().length);
	},
	
	setNav: function()
	{
		$(".nav .next, .nav .prev").show();
		
		if ( SlideShow.n == 0 )
			$(".nav .prev").hide();
		
		if ( SlideShow.n + 1 == SlideShow.num )
			$(".nav .next").hide();
	}
};


function fontReplacement()
{
	if ( !window.CSSFontFaceRule || navigator.userAgent.match(/(Firefox\/([12]\.[\d]|3\.[0-4])|Chrome\/[12])/) )
	{
		var h = [
			"#col-1 h3",
			"#col-2 h3",
			"#col-3 h3",
			"#next-dates",
			"#news-kochbuch",
			"#band #sidebar h3",
			"#kochbuch #sidebar h3"
		];
		
		for ( var i = 0; i < h.length; i++ )
		{
			$(h[i]).css({
				"width": "220px",
				"height": "30px",
				"text-indent": "-3000px",
				"background": "url(/css/img/font_replacement.gif) no-repeat -"+(i*220)+"px 0"
			});
		}
	}
}



$(document).ready(function()
{
	// Bilder statt @font-face
	fontReplacement();
	
	if ( document.getElementById("big-img") )
	{
		SlideShow.init();
	}
	
	// Newsletter
	var inputText = $("#infobox #email").val();
	
	if ( inputText )
	{
		$("#infobox #email").focus(function()
		{
			if ( $(this).val() == inputText )
				$(this).val("");
		});
		
		$("#infobox #email").blur(function()
		{
			if ( $(this).val() == "" )
				$(this).val(inputText);
		});
	}
	
	// Gästebuch
	$("#g-form").hide();
	$("#toggle-g-form").click(function(e)
	{
		e.preventDefault();
		$("#g-form").toggle();
	});
});
