$(document).ready(function() {

	start = 0;
	$("#navigation a").hover(function(){
		if($(this).parent().hasClass("aktiv")) { } else {
			$(this).parent().stop().animate({
				backgroundColor: "#8A2328"
			});
			
			//alert($(".slide").css("display"));
			$(".slide").show();
		}
		start = 1;
		
		var page = $(this).parent().parent().attr("id");
		
		slider($(this), page);
		
		
	}, function(){
		if($(this).parent().hasClass("aktiv")) { } else {
			$(this).parent().stop().animate({
				backgroundColor: "#979595"
			});
		}
		start = 0;
	
	});
	
	function slider(element, page) {
		$(".slide").stop();
		$(".slide").children().stop();
		var pos = element.offset();
		var posParent = $("#navigation").offset();
		var links = pos.left-posParent.left;
		var elementBreite = element.width()+4;
		var speed = 700;
		links = links+33;
		
		$(".slide").each(function(i){
			var zufall = Math.floor(Math.random()*elementBreite);
			var zufallDichte = Math.floor(Math.random()*10)/10;
			if(zufallDichte == 0.9) { zufallDichte = 0.8; };
			if(zufallDichte == 0 || zufallDichte == 0.1) { zufallDichte = 0.2; };
		
			if(page == "index") {
				var zufallTop = 0;
				var zufallBreite = Math.floor(Math.random()*15)+4;
				var zufallHoehe = Math.floor(Math.random()*100)+14;
			}
			
			if(page == "leistungen") {
				var zufallTop = Math.floor(Math.random()*100);
				var zufallBreite = Math.floor(Math.random()*30)+10;
				var zufallHoehe = zufallBreite;
			}
			
			if(page == "referenzen") {
				var zufallTop = Math.floor(Math.random()*100);
				var zufallBreite = Math.floor(Math.random()*30)+10;
				var zufallHoehe = zufallBreite;
			}
			
			if(page == "kontakt") {
				zufall = zufall-20;
				var zufallTop = Math.floor(Math.random()*100);
				var zufallBreite = Math.floor(Math.random()*50)+30;
				var zufallHoehe = 14*zufallBreite/50;

			}
			
			if(page == "impressum") {

				var zufallTop = Math.floor(Math.random()*100);
				var zufallBreite = Math.floor(Math.random()*15)+5;
				var zufallHoehe = 30*zufallBreite/15;

			}
			
			
			if(i == 0) {
				$(this).animate({
					top: zufallTop+"px",
					left: links+"px",
					opacity: zufallDichte
				}, speed);
				
				$(this).children().animate({
					
					width: zufallBreite+"px",
					height: zufallHoehe+"px"
					
				}, speed);
				
			} else {
				if(i == $(".slide").length-1) {
					$(this).animate({
						top: zufallTop+"px",
						left: links+elementBreite-zufallBreite+"px",
					
						opacity: zufallDichte
					}, speed);
					$(this).children().animate({
					
						width: zufallBreite+"px",
						height: zufallHoehe+"px"
					}, speed);
				} else { 
					$(this).animate({
						top: zufallTop+"px",
						left: links+zufall+"px",
					
						opacity: zufallDichte
					}, speed);
					
					$(this).children().animate({
					
						width: zufallBreite+"px",
						height: zufallHoehe+"px"
					}, speed);
				}
			}
			
			
		});
	}

	

	
});


function validEmail(email) {
  var strReg = "^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$";
  var regex = new RegExp(strReg);
  return(regex.test(email));
}