/// <reference path="jquery-1.2.6-vsdoc.js">

Shadowbox.loadSkin('classic', 'js/skin'); // use the "classic" skin
Shadowbox.loadLanguage('de-DE', 'js/lang'); // use the English language
Shadowbox.loadPlayer(['img', 'qt', 'iframe'], 'js/player'); // use img and qt players

$(document).ready(function() {
    Shadowbox.init();

    $('a').focus(function() {
        $(this).blur()
    })

    $("#calendar").datepicker({
        beforeShowDay: eventDays,
        onSelect: loadEvent
    });
    $.datepicker.regional['de']


    //GALLERY
    gallery($("#gallery"));
    $('.list .gallery').each(function() {
        gallery($(this));
    })

    //SPECIAL
    $("#tabnavi").tabs();
    //$("#playlist").playlist("FlowPlayerDark.swf", { initialScale: 'fit' }, { loop: true });
    if ($('#player').length > 0) {

        flowplayer("player", "flowplayer-3.2.5.swf", {
            clip: {
                autoPlay: false
            },
            plugins: {
                controls: {
                url: 'flowplayer.controls-3.2.3.swf',
                    timeColor: '#b8292f',
                    progressColor: '#b8292f',
                    bufferColor: '#dddddd'
                }
            }
        }).ipad().playlist("#playlist", {
            loop: false,
            playOnClick: true
        });
    }

    //EVENTS FILTER
    $("#efilter a").click(function(e) {
        e.preventDefault();
        $("#efilter a").removeClass("active");
        var action = $(this).attr('class');

        $(this).addClass("active");

        $("#eblock").load("events.aspx?action=" + action, function() {
            $("#calendar").datepicker({
                beforeShowDay: eventDays,
                onSelect: loadEvent
            });
        });
    });

    //PERSONEN DETAILS

    $(".person div.detail").hide();
    $(".person a.detail").click(function(e) {
        e.preventDefault();

        $(".person div.detail").each(function() {
            if ($(this).css("display") != "none") {
                $("#det-" + id).slideUp();
            }
        });

        id = $(this).attr("href").substr(1);

        if ($("#det-" + id).css("display") == "none") {
            $("#det-" + id).slideDown();
        } else {
            $("#det-" + id).slideUp();
        }
    });


    //FORMULARE

    $("#formular .required input").blur(function() {
        if ($(this).val() == "") {
            $(this).parent().removeClass("ok");
            $(this).parent().addClass("err");
        } else {
            $(this).parent().removeClass("err");
            $(this).parent().addClass("ok");
        }
    })

    //BOOKS

    $('.book .desc').each(function() {
        var h = $(this).height();
        $(this).height(33);
        $('a', this).toggle(
            function(e) {
                $(this).parent().animate({ 'height': h })
            },
            function(e) {
                $(this).parent().animate({ 'height': 33 })
            }
        );
    });


    $(".bezirksmap").click(function(e) {
        var bezid = $(this).attr("id");
        $("#bezirk"+bezid).fadeIn();
    });

    $(".bezirkclose").click(function(e) {
        var bezid = $(this).attr("alt");
        $("#bezirk" + bezid).fadeOut();
    });

    $(".bezirksmap").hover(function(e) { }, function(e) {
        $("#bezirkview").html("W&auml;hlen Sie ihren Bezirk");
    });

    $('.map').maphilight();

})


function eventDays(date) {
    var today = new Date();
    today = new Date(today.getFullYear(), today.getMonth(), today.getDate());  
       
    for (i = 0; i < events.length; i++) {
        if (date.getMonth() == events[i][0] - 1 && date.getDate() == events[i][1] && date.getFullYear() == events[i][2]) {
            return [true, "event", events[i][3]];
        }
    }
    return [true, ""];
}

function loadEvent(date) {
    // alert("load");
    $('.events .col_left').load('events.aspx?edate=' + date);
}

function gallery(target) {

    $(".images", target ).height($(".bg .img", target ).outerHeight() + 10);
    $(".status a", target).click(function(e) {
        e.preventDefault();
        if ($(".images", target).height() == $(".bg .img", target).outerHeight() + 10) {
            $(".images", target).animate({
                height: $(".bg", target).height()
            });
            $(".status a", target).text("Bilder verstecken");
        } else {
            $(".images", target).animate({
                height: $(".bg .img", target).outerHeight() + 10
            });
            $(".status a", target).text("alle Bilder zeigen");
        }
    })

}
