﻿var anchor = "";

$(document).ready(function() {

	//make content float
	$(".subpage").css("float","left");
	$("#scrollcontent").css("width","4580px");
	$("#scrollcontent").css("height","369px");
	
	//remove name attribute, so that in jquery mode, default jump is deactivated
	$(".subpage-anchor").removeAttr("name");
	$(".subpage-anchor").pngFix();
	$(".subpage-content").pngFix();
	//in firefox default jump is still active on page load, so reset scroll position of document
	$(document).scrollTop(0);
	$(document).scrollLeft(0);
	//set jumpmark manually for other browsers than ff
	gotoPage(document.location.href, false);
	$("#nl-input-email").click(
		function (event) {
			$("#nl-input-email").css("color","#1A1308");
			if($("#nl-input-email").val() == "Deine E-Mail Adresse..." || $("#nl-input-email").val() == "Ungültige E-Mail" || $("#nl-input-email").val() == "Fehler" || $("#nl-input-email").val() == "Danke"){
				$("#nl-input-email").val("");
			}
		}
	)
	$(".nl-submit-btn").click(
		function (event) {
			event.preventDefault();
			checkNLForm();
		}
	)
});//$(document).ready

$(window).load(function () {
	$("#nav a").click(
		function (event) {
			//event.preventDefault();
			gotoPage(String(event.target), true);
		}
	)
	$("#a-kontakt-foot").click(
		function (event) {
			gotoPage(String(event.target), true);
		}
	)
});//end $(window).load


function gotoPage(url, animate){
	//alert($("#content").scrollLeft());
	if(anchor){
		$("#a-" + anchor).toggleClass("selected");//dehighlight last active
	}
	anchor = url.split("#")[1];
	if(!anchor){
		anchor = String($("#nav a").eq(0).attr("href")).split("#")[1];
	}
	//if(anchor){anchor = anchor.split("?")[0];}
	
	var nextScrollPos = Number($("#sp-" + anchor).index() * 916);
	if(animate){
		$("#content").stop().animate({
			scrollLeft: nextScrollPos
			}, 500, 'swing', function() {
			setLocation(anchor);
		});
	}else{
		$("#content").scrollLeft(nextScrollPos);
	}
	$("#a-" + anchor).toggleClass("selected");//highlight new active
}

function setLocation(anchor){
	//window.location.href = "#" + anchor;
}

function checkNLForm(){
	var email = $("#nl-input-email").val();
	if(email.indexOf("@") > 0 && email.indexOf(".") > 0){
		sendNLForm(email);
	}else{
		$("#nl-input-email").css("color","#ff0000");
		$("#nl-input-email").val("Ungültige E-Mail");
	}
}

function sendNLForm(email){
	$.ajax({
		type: 'POST',
		url: 'save-email-2678930.php',
		context: $("#nl-input-email"),
		data: "email=" + email,
		dataType: 'html',
		success: function(html, textStatus) {
			if(Number(html) == 1){
				$("#nl-input-email").css("color","#008800");
				$(this).val("Danke");
			}else{
				$("#nl-input-email").css("color","#ff0000");
				$(this).val("Fehler");
			}
		},
		error: function(xhr, textStatus, errorThrown) {
			$("#nl-input-email").css("color","#ff0000");
			$(this).val("Fehler");
		}
	});
}

