// custom easing called "custom" 
/*
$.easing.custom = function(x, t, b, c, d) {
    var s = 1.50158;
    if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
    return c / 2 * ((t -= 2) * t * (((s *= (0.525)) + 1) * t + s) + 2) + b;
}
*/

$(document).ready(function () {

    $('#footer').css("display", "none")
    $('#navigation').css("display", "none")
    $('#content').css("display", "none")

    setTimeout(function () {
        $('#overhead').animate({ left: '-=268' }, 1000, function () {
        });
    }, 800)
    setTimeout(function () {
        $('#overhead').animate({ left: '+=268' }, 1000, function () {
            $('#overhead').hover(function () {
                $(this).animate({ left: '-=268' }, 1000);
            },
                function () {
                    $(this).animate({ left: '+=268' }, 1000);
                });
        });
    }, 4500)

    if ($("#map").length > 0) {
        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map"));
            var x = map.getMapTypes();
            map.setMapType(x[2]);
            map.setCenter(new GLatLng(46.533000, 14.132795), 15);
            var point = new GLatLng(46.532052, 14.132795);
            map.addOverlay(new GMarker(point));
            map.setUIToDefault();
        }
    }

    /* fade ins */
    setTimeout(function () {
        $('#footer').fadeIn();
    }, 50);

    setTimeout(function () {
        $('#navigation').fadeIn();
    }, 100);

    setTimeout(function () {
        $('#content').fadeIn();
    }, 300);

    $('#infinite').cycle({
        fx: 'fade',
        speed: 1000,
        next: '#infinite'
    });

    $("#buttons a img").hover(function () {
        $(this).animate({ opacity: 0.50 }, 200);
    }, function () {
        $(this).animate({ opacity: 1 }, 200);
    });

    $("a.slideshowitem img").hover(function () {
        $(this).animate({ opacity: 0.20 }, 200);
    }, function () {
        $(this).animate({ opacity: 1 }, 200);
    });

    $("a.articleimg img").hover(function () {
        $(this).animate({ opacity: 0.20 }, 200);
    }, function () {
        $(this).animate({ opacity: 1 }, 200);
    });

    $("#media_fotos ul li a.img").hover(function () {
        $(this).animate({ opacity: 0.20 }, 200);
    }, function () {
        $(this).animate({ opacity: 1 }, 200);
    });

    $(".videobutton").hover(function () {
        $(this).animate({ opacity: 0.20 }, 200);
    }, function () {
        $(this).animate({ opacity: 1 }, 200);
    });


    /* Autoscroll */
    // $("#infinite").scrollable({ size: 1, easing: 'custom', speed: 1300 }).autoscroll(5000, { autoplay: true }).circular();

    /* Bildunterschriften erstellen */
    $('#content img.art').each(function () {
        var alttext = $(this).attr('alt');
        $(this).wrap('<div class="aside">').after('<span>' + alttext + '</span>');
    });


    //Datepicker
    //Delete Date Config for using english format
    Date.abbrDayNames = ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'];
    Date.abbrMonthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'];
    Date.monthNames = ['Januar', 'Februar', 'M' + unescape("%E4") + 'rz', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
    Date.firstDayOfWeek = 1;
    Date.format = 'dd.mm.yyyy';
    $('input.datepicker').datePicker({ clickInput: true });

    /* Lightboxen */
    if ($("a.lightbox").length > 0) {
        $('a.lightbox').overlay({
            target: '#gallery',
            expose: {
                maskId: 'exposeMask',
                color: '#533524',
                opacity: 0.95
            }
        }).gallery({
            speed: 800
        });
    }

    if ($(".videoIFrame a").length > 0) {
        $('.videoIFrame a').overlay({
            target: '#video',
            expose: {
                maskId: 'exposeMask',
                color: '#533524',
                opacity: 0.90
            },
            onLoad: function (event, index) {
                jwplayer("videoFrame").remove();
                var addToIframe = this.getTrigger().attr("href");
                if (addToIframe.indexOf('embed') == 0) {
                    var htmlStr = $("#" + addToIframe).html();
                    $("#videoFrame").html(htmlStr);
                } else {
                    jwplayer("videoFrame").setup({ flashplayer: "player/player.swf", file: addToIframe, 'skin': 'player/skins/bekle.zip', 'width': '650', 'height': '395' });
                }
            }
        });
    }


    // Form validierung
    $("#anfrage").validate({
        submitHandler: function (form) {
            form.submit();
        },
        rules: {
            fname: "required",
            femail: {
                required: true,
                email: true
            }
        },
        messages: {
            fname: "Geben Sie bitte Ihren Namen ein",
            femail: "Geben Sie bitte eine korrekte E-Mail-Adresse ein"
        }
    });

    $('#fanreise').change(function () {
        var ankomst = new Date($('#fanreise').val().substring(6, 10), $('#fanreise').val().substring(3, 5), $('#fanreise').val().substring(0, 2));
        var abkomst = new Date($('#fabreise').val().substring(6, 10), $('#fabreise').val().substring(3, 5), $('#fabreise').val().substring(0, 2));
        var one_day = 1000 * 60 * 60 * 24
        if ($(this).val() != "" && $('#fanreise').val() != "") { $('#fnaechte').val(Math.ceil((abkomst.getTime() - ankomst.getTime()) / (one_day))) };
    });

    $('#fabreise').change(function () {
        var ankomst = new Date($('#fanreise').val().substring(6, 10), $('#fanreise').val().substring(3, 5), $('#fanreise').val().substring(0, 2));
        var abkomst = new Date($('#fabreise').val().substring(6, 10), $('#fabreise').val().substring(3, 5), $('#fabreise').val().substring(0, 2));
        var one_day = 1000 * 60 * 60 * 24
        if ($(this).val() != "" && $('#fanreise').val() != "") { $('#fnaechte').val(Math.ceil((abkomst.getTime() - ankomst.getTime()) / (one_day))) };
    });

    $('#fkinderalter').keydown(function (event) {
        if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 32) {
            if (event.keyCode == 32) { $('#fkinderalter').val($('#fkinderalter').val() + ',') }
        }
        else {
            if (event.keyCode < 48 || (event.keyCode > 57 && event.keyCode < 96) || event.keyCode > 105) { event.preventDefault(); }
        }
    });


    $('#fmessage').focus(function () {
        if ($(this).val() == $(this).attr("title") + "...") { $(this).val("") };
    });

    $('#fmessage').blur(function () {
        if ($(this).val() == "") { $(this).val($(this).attr("title") + "...") };
    });

    $('#kmessage').focus(function () {
        if ($(this).val() == $(this).attr("title") + "...") { $(this).val("") };
    });

    $('#kmessage').blur(function () {
        if ($(this).val() == "") { $(this).val($(this).attr("title") + "...") };
    });

    //Startseite Video einblenden

    $('#video h2').click(function () {
        $('#innerVideo').slideToggle('slow');
    });



});
