// JavaScript Document

$(document).ready(function()
{		
	function setSlideshow() {
		var childCounter = 0;
		var childsArray = new Array();
		var current = 0;
		
		$(".slideshow > .slideshow_image").each(function(){
			childsArray[childCounter] = $(this);
			childCounter = childCounter + 1;
		});
		
		if (childCounter>1) {
			$(".slideshow > .slideshow_image:not(:first)").hide();
			$(".slideshow").append("<div class='slideshow_prev'><div class='slideshow_prev_background'></div><div class='slideshow_prev_button'>&lt;</div></div>");
			$(".slideshow").append("<div class='slideshow_next'><div class='slideshow_next_background'></div><div class='slideshow_next_button'>&gt;</div></div>");
			//$(".slideshow_next").hide();
			//slideshow_interval = setTimeout(slideshow, 5000);
			$(".slideshow_prev").css({cursor: "pointer"}).hide();
			$(".slideshow_prev").find(".slideshow_prev_background").css({opacity: 0.5});
			$(".slideshow_prev").hover(function(){
				$(this).find(".slideshow_prev_background").css({opacity: 1});									
			},function(){
				$(this).find(".slideshow_prev_background").css({opacity: 0.5});	
			});
			$(".slideshow_next").css({cursor: "pointer"}).hide();
			$(".slideshow_next").find(".slideshow_next_background").css({opacity: 0.5});
			$(".slideshow_next").hover(function(){
				$(this).find(".slideshow_next_background").css({opacity: 1});										
			},function(){
				$(this).find(".slideshow_next_background").css({opacity: 0.5});	
			});
			//$(".slideshow_next_background").css({opacity: 0.75});
			/*$(".textpic_slideshow").hover(function(){
					$(".slideshow_next").show();						   
			}, function(){
				$(".slideshow_next").hide();	
			});*/
			
			$(".slideshow_prev").click(function() {
				if (current-1>=0) {
					childsArray[current].fadeOut("def");
					current--;
					childsArray[current].fadeIn("def");
				} else {
					childsArray[current].fadeOut("def");
					current = childsArray.length-1;
					childsArray[current].fadeIn("def");
				}
			});
			
			$(".slideshow_next").click(function() {
				if (current+1<childsArray.length) {
					childsArray[current].fadeOut("def");
					current++;
					childsArray[current].fadeIn("def");
				} else {
					childsArray[current].fadeOut("def");
					current = 0;
					childsArray[current].fadeIn("def");
				}
			});
			
			/*$(".slideshow").click(function(){
				if($(this).next().not(".slideshow_next").attr("class")!=undefined) {
					$(this).fadeOut("def");
					$(this).next().fadeIn("def");
				} else {
					$(this).fadeOut("def");
					$(".textpic_slideshow > .slideshow:first").fadeIn("def");
				}		   
			});*/
		}
		
		$(window).load(function(){
			$(".slideshow .loading").remove();
			$(".slideshow > .slideshow_image:first").show();
			$(".slideshow_next").show();
			$(".slideshow_prev").show();
		});
	}

	/* actions */
	
	var mailformplus = $("#kontaktformular").validate({
		rules: {
			Vorname: "required",
			Nachname: "required",
			"E-Mail-Adresse": "required email",
			Nachricht: "required",
			"Telefon-Nr": "number"
		},
		messages: {
			Vorname: "Bitte geben Sie Ihren Vornamen ein.",
			Nachname: "Bitte geben Sie Ihren Nachnamen ein.",
			"E-Mail-Adresse": {
				required: "Bitte geben Sie Ihre E-Mail-Adresse ein.",
				email: "Ihre Eingabe muss vom Format name@meinedomain.de sein."
			},
			Nachricht: "Bitte geben Sie eine Nachricht ein.",
			"Telefon-Nr": {
				number: "Sie d&uuml;rfen nur Zahlen eingeben."	
			}
		},
		//errorLabelContainer: "#messageBox",
		//wrapper: "li",
		errorPlacement: function(error, element) {
     		error.appendTo(element.parent("td").find(".messageBox"));
		},
		errorClass: "invalid"
	});
	
	var oldColor = "#9c9d9d";
	var highlightColor = "#ff0000";
	
	$(".contact_text, .contact_textarea").focus(function(){
		$(this).css({borderColor: highlightColor});													 
	});
	
	$(".contact_text, .contact_textarea").blur(function(){
		$(this).css({borderColor: oldColor});													
	});
	
	$(".printlink").click(function(){
		var target = $(this).attr("href");
		var myWindow = window.open(target, "Druckversion", "width=600, height=400, scrollbars=yes");
			
		return false;							   
	});
	
	setSlideshow();
});
