var now = new Date();
var prettyDate = new String;
if (now.getDate() < 10) {
    prettyDate = ('0' + now.getDate() + '.' + (now.getMonth() + 1) + '.' + now.getFullYear());
} else {
    prettyDate = (now.getDate() + '.' + (now.getMonth() + 1) + '.' + now.getFullYear());
}

// JavaScript Document
$(document).ready(function() {

    /* Lightboxen */
    if ($("a.lightbox").length > 0) {
        $('a.lightbox').overlay({
            target: '#gallery',
            expose: {
                maskId: 'exposeMask',
                color: '#533524',
                opacity: 0.95
            }
        }).gallery({
            speed: 800
        });
    }

    /* FADE THINGS */
    $("#placeholder").hover(function() {
    $('#gemaelde').fadeIn('slow');
    });
    $("#gemaelde").hover(function() {
        $('#gemaelde').show();
    }, function() {
        $('#gemaelde').fadeOut('slow');
    });

    //EXTERNES FENSTER ÖFFNEN 
    $("a[rel='external']").click(function(event) {
        window.open($(this).attr("href"));
        event.preventDefault();
    });

    //EXTERNES FENSTER ÖFFNEN
    $("a[rel='ausnahme']").click(function(event) {
        location.replace($(this).attr("href"));
        event.preventDefault();
    });

    $('#date').DatePicker({
        flat: true,
        date: [],
        current: '01.' + (now.getMonth() + 2) + '.' + now.getFullYear(),
        calendars: 3,
        starts: 1,
        mode: 'range',
        onChange: function(formated, dates) {
            $('#DatePickerDate').val(formated);
            var str = formated.toString().split(",");
            if (str[0] == str[1]) {
                $('#Datesubmit').text('Veranstaltungen f' + unescape("%FC") + 'r den ' + str[0] + ' anzeigen oder Enddatum w' + unescape("%E4") + 'hlen');
            } else {
            $('#Datesubmit').text('Veranstaltungen f' + unescape("%FC") + 'r den Zeitraum ' + str[0] + ' bis ' + str[1] + ' anzeigen');
            }
        }
    });

    if ($('#DatePickerDate').length > 0) {
        if ($('#DatePickerDate').val() != '') {
            var str = $('#DatePickerDate').val().split(",");
            $('#date').DatePickerSetDate([str[0], str[1]], 1);
        }
    }

});

