$(document).ready(function(){
	
	$('#nav').removeClass('nojs');
	$('#nav li').hover(function(){
		$(this).children('ul').slideDown(200);
	}, function(){
		$(this).children('ul').slideUp(100);
	});

});

$("a[rel=lbStandard]").fancybox({
    'overlayOpacity': 0.5,
    'transitionIn': 'elastic',
    'transitionOut': 'none', 
    'titlePosition': 'over',
    'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
        return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
    }
});

$("a[rel=lbjjBox1]").fancybox({
    'opacity': true,
    'overlayShow': false,
    'transitionIn': 'elastic',
    'transitionOut': 'none',
    'titlePosition': 'over',
    'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
        return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
    }
});

$("a[rel=test]").fancybox({
    'opacity': true,
    'overlayShow': false,
    'transitionIn': 'elastic',
    'transitionOut': 'none',
    'titlePosition': 'over',
    'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
        return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
    }
});

$("a[rel*='lbBox']").fancybox({
    'titlePosition': 'over',
    'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
        return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
    }
});





$("#contactForm").submit(function() {

    if ($("#Vorname").val().length < 1 || $("#Nachname").val().length < 1 || $("#Nachricht").val().length < 9 || !isValidEmailAddress($("#Email").val())) {
        $("#submit_error").show();
        $.fancybox.resize();
        return false;
    }

    $.fancybox.showActivity();

    $.ajax({
        type: "POST",
        cache: false,
        url: "sendform.aspx",
        data: $(this).serializeArray(),
        success: function(data) {


            $("#VornameIcon").attr("src", "./img/icon/invalid.png");
            $("#NachnameIcon").attr("src", "./img/icon/invalid.png");
            $("#EmailIcon").attr("src", "./img/icon/invalid.png");
            $("#NachrichtIcon").attr("src", "./img/icon/invalid.png");

            $.fancybox(data);
        }
    });

    return false;

});






function check4ValidChars(elem, charamount, chkEmail) {
    $("#" + elem).bind("keydown keyup change mouseenter focus mouseleave blur ready", function () {
        if (chkEmail) {
            if (isValidEmailAddress($("#" + elem).val())) {
                $("#" + elem + "Icon").attr("src", "./img/icon/valid.png");
                return true;
            } else {

                $("#" + elem + "Icon").attr("src", "./img/icon/invalid.png");
            }
        }
        else {
            if ($("#" + elem).val().length > charamount) {
                $("#" + elem + "Icon").attr("src", "./img/icon/valid.png");
                return true;
            } else {
                $("#" + elem + "Icon").attr("src", "./img/icon/invalid.png");
            }
        }
    })
}








function isValidEmailAddress(inputvalue) {
    var pattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    return (pattern.test(inputvalue))
}





check4ValidChars("Vorname", 2, false);
check4ValidChars("Nachname", 2, false);
check4ValidChars("Nachricht", 10, false);
check4ValidChars("Email", 0, true);
