$(document).ready(function(){
	fitBackground();
	fitContent();
	
	$("#lnkLogin").click(function(){
		$("#layerLogin,#login").fadeIn(300);
	});
	
	$("#layerLogin").click(function(){
		$("#layerLogin,#login").fadeOut(300);
	});
	
	$("#gallery img").each(function(){
		var cImg = $(this);
		cImg.click(function(){
			$("#imgGallery").attr("src", cImg.attr("src").replace(/\.jpg/, "_gross.jpg"));
			$("#frmGalleryImage").show();
		});
	});
	
	if ($.cookie("showArrow") != "no") {
		$.cookie("showArrow", "no");
		$("#lnkArrowGutscheine")
		.css("display", "block")
		.css("left", $(window).width())
		.animate({ left: "35px"},{
			duration: 3000,
			specialEasing: {
			  left: 'easeOutBounce'
			},
			complete: function() {
			  $(this).delay(5000).fadeOut(500);
			}});		
	}

	$("#lnkFullscreen").click(function(){
		var cLink = $(this);
		if ($(this).hasClass("active")) {
			$("#content").animate({
				left: "30px"
			}, 750 , function(){
				$("#header").animate({
					top: "0px"
				}, 750, function(){
					cLink.removeClass("active");
				});
			});

		}else{
			$("#content").animate({
				left: "-900px"
			}, 750 , function(){
				$("#header").animate({
					top: "-80px"
				}, 750, function(){
					cLink.addClass("active");
				});
			});

		}
	});
});

$(window).resize(function(){
	fitBackground();
	fitContent();
});

$(window).load(function(){
	fitBackground();
	fitContent();
});

// Srollbar Content
function fitContent(){
	if ($("#innerInnerContent").height() > $(window).height() - 200) {
		$("#innerContent").height($(window).height() - 200);
		$("#innerContent").css("overflow-y","scroll");
	} else {
		$("#innerContent").height("auto");
		$("#innerContent").css("overflow-y","inherit");
	}
}

function loadBigImage(img) {
	$("#gallery").remove();
	$("#innerInnerContent").append($("<div>").attr("id", "gallery").append($("<div>").attr("id", "frmGalleryImage").append($("<img>").attr("src", img))));	
}

// Hintergrund skalieren
function fitBackground(){
	// Bildgröße
	var iWidth = 1140;
	var iHeight = 800;
	var iQuot = iWidth / iHeight;
	// Fenstergröße
	var wHeight = $(window).height();
	var wWidth = $(window).width();
	var wQuot = wWidth / wHeight;

	if (iQuot > wQuot) {
		$("#imgMain").height(wHeight);
		$("#imgMain").width(parseInt(wHeight * iQuot));
	}else{
		$("#imgMain").width(wWidth);
		$("#imgMain").height(parseInt(wWidth / iQuot));
	}

	$("#map_canvas").height(wHeight);
	$("#map_canvas").width(wWidth);

	$.cookie("height",wHeight);
	$.cookie("width",wWidth);
}


// Google Maps
function initialize() {
	var myLatlng = new google.maps.LatLng(50.3503500, 7.5511300);
		  var myOptions = {
		    zoom: 13,
		    center: myLatlng,
		    navigationControl: false,
		    mapTypeId: google.maps.MapTypeId.ROADMAP
		  }
		  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

		  var image = 'beachflag.png';
		  var myLatLng = new google.maps.LatLng(50.3603500, 7.5811300);
		  var beachMarker = new google.maps.Marker({
		      position: myLatLng,
		      map: map
		  });
}

function drawPreview(elem){
	$("#imgGallery").css("border","solid 5px red");
	$("#imgGallery").css("margin","-5px 0 -5px -5px");
	setTimeout('$("#imgGallery").css("border","none");', 2000);
	setTimeout('$("#imgGallery").css("margin","0");', 2000);
	$("#" + $(elem).attr("rel")).html($(elem).val());
}

function email(value) {
        var regExEmail = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");
        return regExEmail.test(value);
    }

function submitForm() {
	var isValid = true;
	var couponText = $("#txtZeile1").val() + 
					 $("#txtZeile2").val() + 
					 $("#txtZeile3").val() + 
					 $("#txtZeile4").val() + 
					 $("#txtZeile5").val() + 
					 $("#txtZeile6").val()
	
	if (couponText == ""){
		alert("Bitte geben Sie einen Gutschein-Text ein!")
		isValid = false;
	}
	
	inputs = new Array ("txtName","txtStrasse","txtOrt","txtTelefon");	
	for (var i = 0; i < inputs.length; i++){	
		var cInput = $("#" + inputs[i]);
		if (cInput.val() == ""){
			cInput.addClass("active");
			isValid = false;
			} else {
			cInput.removeClass("active");
		}
	}
	
	if (!email($("#txtEmail").val())) {
		$("#txtEmail").addClass("active");
		isValid = false;
		}else{
		$("#txtEmail").removeClass("active");
	}
	
	if (isValid){
		document.form1.submit();
	}
	
}


