/// <reference path="jquery-1.5-vsdoc.js" />
$(document).ready(function ()
{
    initQuickAccess();

    initFAQ();

    initResizeBlocks();  

    initFancybox();
});

$(window).load(function ()
{
    initFixImgOriginal();
});

// FAQ-Liste Ein-Ausblend-Effekt 
function initFAQ()
{
    $(".faq-open").css("display", "block");
    $(".question").css("margin", "-18px 0 0 23px");

    $(".faq-item p").hide();

    $(".faq-open").click(function ()
    {
        $(this).parent().parent().find("p").show();
        $(this).parent().find(".faq-close").css("display", "block");
        $(this).parent().find(".faq-open").hide();
    });

    $(".faq-close").click(function ()
    {
        $(this).parent().parent().find("p").hide();
        $(this).parent().find(".faq-close").hide();
        $(this).parent().find(".faq-open").css("display", "block");
    });
}

// Funktion Schnelleinstieg Slide-Effekt
function initQuickAccess()
{
    $("#quick-access-button-open, #quick-access-button-close").css("display", "inline");
    $("#quick-access-wrapper").css("display", "none");
    $("#quick-access-wrapper").fadeIn("slow");
    $("#quick-access-button-open").click(function ()
    {
        $("#quick-access-wrapper").fadeIn("slow");

    });

    $("#quick-access-button-close").click(function ()
    {
        $("#quick-access-wrapper").fadeOut("slow");
    });
}

//Funktion öffne Popup
function openPopup(url, height, width)
{
    var windowX = window.open(url, 'newWindow', 'status=no,toolbar=no,scrollbars=no,titlebar=no,menubar=no,resizable=yes,width='+width+',height='+height+',directories=no,location=no');
    windowX.focus();
    return false;
}

// Funktion zum Anpassen der Höhen der Überschriften von Teaser-Blöcken
function initResizeBlocks()
{
    $(".block:has('.publications-2, .researchprograms-2, .teaser-2, .press-2')").each(function ()
    {
        var headlines = $(this).find(".publications-2-headline, .researchprograms-2-headline, .teaser-2-headline, .press-2-headline");
        if (headlines.length == 2)
        {
            var heightLeftCell = $(headlines[0]).height();
            var heightRightCell = $(headlines[1]).height();

            if (heightLeftCell > heightRightCell)
            {
                $(headlines[1]).height(heightLeftCell);
            }
            else if (heightLeftCell < heightRightCell)
            {
                $(headlines[0]).height(heightRightCell);
            }
        }
    });
}

// Bei Bildern mit Originalgröße wird je nach Breite des Bildes der Text neben das Bild gesetzt
function initFixImgOriginal()
{
    $(".img-original").find("img:first").each(function ()
    {
        var imgWidth = $(this).width();
        if (imgWidth <= 476)
        {
            $(this).parent().css({"float":"left", "margin-right":"18px", "margin-bottom":"3px"});
            $(this).parent().parent().append("<div class='fixfloat'>&nbsp;</div>");
        }
    });
}


// Funtkion Initialisieren der Fancybox
function initFancybox()
{
    var fancyBoxEntries = $("a[rel=fancybox],a.img-zoom");
    if (fancyBoxEntries.length > 0)
    {
        fancyBoxEntries.fancybox({
            'showNavArrows': false,
            'showCloseButton': false,
            'titlePosition': 'inside',
            'titleFormat': function (title, currentArray, currentIndex, currentOpts)
            {
                var fancyboxNavLeft = "<a href='javascript:void(0);' class='prev' onclick='$.fancybox.prev();'><span></span></a>";
                var fancyboxNavRight = "<a href='javascript:void(0);' class='next' onclick='$.fancybox.next();'><span></span></a>";
                var fancyboxClose = "<a href='javascript:void(0);' class='close' onclick='$.fancybox.close();'><span></span></a>";

                if (currentIndex == 0)
                {
                    fancyboxNavLeft = "";
                }
                if (currentIndex == currentArray.length - 1)
                {
                    fancyboxNavRight = "";
                }

                return "<div id='fancybox-title-over'>Foto " + (currentIndex + 1) + " von " + currentArray.length + (title.length ? " <br /> " + title : "") + "</div>"
                        + fancyboxNavLeft + fancyboxNavRight + fancyboxClose;
            }
        });
    }
}
