$(document).ready(function() {
	//Subnavigation
	$("ul#nav li").hover(function() {
		$(".subnav", this).fadeIn("fast");
		$(this).addClass("aktivjs");
	}, function() {
		$(".subnav", this).hide();
		$(this).removeClass("aktivjs");
	});

	$("#emotion").append('<div id="route"><form name="link2map" target="_blank" action="http://maps.google.de/maps"><input type="text" value="Route berechnen: Strasse Nr, PLZ Ort" name="saddr" id="route-addr" class="inputfield" /><input type="hidden" value="Meersburgerstraße 6, 88090 Immenstaad am Bodensee" name="daddr" /><input type="submit" value="" name="send" id="route-send" /></form></div>');
	
	//FadeIn Effekts Footer Box
	$('#content .cmslogos a, .submit, .slider').hover(function() {
		$(this).animate({
			opacity : '1'
		}, {
			queue : false,
			duration : 300
		});
	}, function() {
		$(this).animate({
			opacity : '0.4'
		}, {
			queue : false,
			duration : 300
		});
	});
	
	// Formular Footer Box
	$(".inputfield").focus(function() {
		$(this).css("background", "#fbf9f9").fadeIn();
		if (this.value == this.defaultValue) {
			this.value = '';
		}
	});
	$(".inputfield").blur(function() {
		$(this).css("background", "#595959");
		if ($(this).attr("id") == "route-addr") {
			$(this).css("background", "#fff");
		}
		if (this.value == '') {
			this.value = this.defaultValue;
		}
	});

	jQuery.validator.addMethod("defaultInvalid", function(value, element) {
		switch (element.value) {
		case "Name":
			if (element.name == "name")
				return false;
			break;
		case "E-Mail":
			if (element.name == "mailaddress")
				return false;
			break;
		case "Nachricht":
			if (element.name == "nachricht")
				return false;
			break;
		default:
			return true;
			break;

		}
	});

	$("#contact").validate({
		rules : {
			name : {
				required : true,
				defaultInvalid : true,
				minlength : 3
			},
			mailaddress : {
				required : true,
				defaultInvalid : true,
				email : true
			},
			nachricht : {
				required : true,
				defaultInvalid : true
			}
		},
		messages : {
			name : {
				required : "",
				defaultInvalid : "",
				minlength : ""
			},
			mailaddress : {
				required : "",
				defaultInvalid : "",
				email : ""
			},
			nachricht : {
				required : "",
				defaultInvalid : ""
			}
		},
		submitHandler: function(form) {
			
			var data = $("#contact").serialize();

			$.ajax({  
			  type: "POST",  
			  url: "http://www.harrweber.de/fileadmin/template/main/inc/process.php",  
			  data: data,  
			  success: function() {  
			    $('#contact').html("<div id='message'></div>");  
			    $('#message').html("<h2>Kontaktformular wurde erfolgreich abgeschickt!</h2>")  
			    .append("<p>Wir werden schnellst möglichst mit Ihnen Kontakt aufnehmen.</p>")  
			    .hide()  
			    .fadeIn(1500, function() {  
			      $('#message');  
			    });  
			  }  
			});  
		}
	});
	
	//Slider Footer Box
	$(".paging").show();
	$(".paging a:first").addClass("active");
		
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;

	$(".image_reel").css({'width' : imageReelWidth});
	
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1;
		var image_reelPosition = triggerID * imageWidth;

		$(".paging a").removeClass('active');
		$active.addClass('active');

		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	rotateSwitch = function(){		
		play = setInterval(function(){
			$active = $('.paging a.active').next();
			if ( $active.length === 0) {
				$active = $('.paging a:first');
			}
			rotate();
		}, 7000);
	};
	
	rotateSwitch();
	
	$(".image_reel a").hover(function() {
		clearInterval(play);
	}, function() {
		rotateSwitch();
	});	
	
	$(".paging a").click(function() {	
		$active = $(this);
		clearInterval(play);
		rotate();
		rotateSwitch();
		return false;
	});
});



