jQuery(document).ready(function() {
    var currUrl = String(window.location);
    var length = currUrl.length;
    var lastSlash = currUrl.lastIndexOf("/", 1);

    HeaderTop_collapse();
    HeaderInfo_collapse();



    // Header-Preparation
    // Collapse-Button effects
    $(".HeaderTopNavi_CollapseButtons_collapsed").click(function() {
        HeaderTop_SlideCollapse();
        HeaderInfo_SlideCollapse();
        $("#HeaderInfoLower_rightNotch").removeClass("HeaderInfoLower_rightNotchUp");
        $("#HeaderInfoLower_rightNotch").addClass("HeaderInfoLower_rightNotchDown");
    });

    // Header: standard-Button effects
    $(".HeaderTopNavi_CollapseButtons_standard").click(function() {
        HeaderTop_SlideOpen();
        HeaderInfo_SlideCollapse();
    });

    //Header: open-Button effects
    $(".HeaderTopNavi_CollapseButtons_open").click(function() {
        HeaderTop_SlideOpen();
        HeaderInfo_SlideOpen();
        $("#HeaderInfoLower_rightNotch").removeClass("HeaderInfoLower_rightNotchDown");
        $("#HeaderInfoLower_rightNotch").addClass("HeaderInfoLower_rightNotchUp");
    });

    // Handling of TagButton State and Functionality
    $(".mainTag").click(function() {
        $(this).toggleClass("mainTagDeact");
        var tag = $(this).text().replace(/\s+/g, '');
        EventListManipulation(tag);
    });


    $(".HeaderInfoLower_rightNotchUp").click(function() {
        if ($(this).hasClass("HeaderInfoLower_rightNotchDown")) {
            HeaderTop_SlideOpen();
            $(this).removeClass("HeaderInfoLower_rightNotchDown");
            $(this).addClass("HeaderInfoLower_rightNotchUp");
        }
        else if ($(this).hasClass("HeaderInfoLower_rightNotchUp")) {
            HeaderTop_SlideCollapse();
            HeaderInfo_SlideCollapse();
            $(this).removeClass("HeaderInfoLower_rightNotchUp");
            $(this).addClass("HeaderInfoLower_rightNotchDown");
        }
    });


    // MouseOver Animation of EventItems
    $('.eventItemContent')
        .each(function(index) {
            var oHeight = $(this).find("._content").height();

            $(this).find("._content").animate({ height: 0, opacity: 0 }, 0);

            $(this).hover(
            function() {
                $(this).stop().find("._content")
                    .animate({ height: oHeight, opacity: 1 }, 400);
            },

            //this is the hover out function, decrease the span
            //back to original size
    function() {
        $(this).find("._content").stop().animate({
            height: 0, opacity: 0
        }, 400);
    });
        });
});

function EventListManipulation(tagName) {
    $("[id$='_grv_blogentrylist']").find(".eventItem").each(function(index) {
        if ($(this).find("[id$='_hyl_mainTag']").text() == tagName) {
            $(this).slideToggle();
        }
    });
}


function HeaderTop_SlideCollapse() {
    $("#HeaderTop").slideUp('slow', function() {
        // Animation complete.
    });
    $(".HeaderTop_logo").fadeOut('slow', function() {
        // Animation complete.
    });
    $(".HeaderTop_text").fadeOut('slow', function() {
        // Animation complete.
    });
}

function HeaderTop_SlideOpen() {
    $("#HeaderTop").slideDown('slow', function() {
        // Animation complete.
    });
    $(".HeaderTop_logo").fadeIn('slow', function() {
        // Animation complete.
    });
    $(".HeaderTop_text").fadeIn('slow', function() {
        // Animation complete.
    });
}
function HeaderInfo_SlideCollapse() {

    $("#HeaderInfo").slideUp('slow', function() {
        // Animation complete.
    });

    $(".HeaderInfo_contentMiddle").animate({ top: -245 }, 'slow');
    $(".HeaderInfo_contentLeft").animate({ top: -245 }, 'slow');
    $(".HeaderInfo_contentRight").animate({ top: -300 }, 'slow');
    $(".HeaderInfo_contentMiddleLower").animate({ top: -48 }, 'slow');
    $(".HeaderInfo_contentRightLower").animate({ top: -48 }, 'slow');
    $(".HeaderInfo_contentLeft").fadeOut('slow', function() {
        // Animation complete.
    });
    $(".HeaderInfo_contentRight").fadeOut('slow', function() {
        // Animation complete.
    });
}
function HeaderInfo_SlideOpen() {
    $("#HeaderInfo").slideDown('slow', function() {
        // Animation complete.
    });
    $(".HeaderInfo_contentLeft").animate({ top: 0 }, 'slow');
    $(".HeaderInfo_contentMiddle").animate({ top: 0 }, 'slow');
    $(".HeaderInfo_contentRight").animate({ top: 0 }, 'slow');
    $(".HeaderInfo_contentMiddleLower").animate({ top: 0 }, 'slow');
    $(".HeaderInfo_contentRightLower").animate({ top: 0 }, 'slow');
    $(".HeaderInfo_contentMiddle").fadeIn('slow', function() {
        // Animation complete.
    });
    $(".HeaderInfo_contentLeft").fadeIn('slow', function() {
        // Animation complete.
    });
    $(".HeaderInfo_contentRight").fadeIn('slow', function() {
        // Animation complete.
    });
}
function HeaderTop_collapse() {
    $("#HeaderTop").slideUp(0, function() {
        // Animation complete.
    });
    $(".HeaderTop_logo").fadeOut(0, function() {
        // Animation complete.
    });
    $(".HeaderTop_text").fadeOut(0, function() {
        // Animation complete.
    });    
}

function HeaderTop_open() {
    $("#HeaderTop").slideDown('slow', 1.0);
    $(".HeaderTop_logo").fadeTo('slow', 1.0);
    $(".HeaderTop_text").fadeTo('slow', 1.0);
}

function HeaderInfo_collapse() {
    $("#HeaderInfo").slideUp(0, function() {
        // Animation complete.
    });
    $(".HeaderInfo_contentMiddle").animate({ top: -245 }, 0);
    $(".HeaderInfo_contentLeft").animate({ top: -245 }, 0);
    $(".HeaderInfo_contentRight").animate({ top: -284 }, 0);
    $(".HeaderInfo_contentMiddleLower").animate({ top: -48 }, 0);
    $(".HeaderInfo_contentRightLower").animate({ top: -48 }, 0);
}

function HeaderInfo_open() {
    $("#HeaderInfo").slideDown();

    $(".HeaderInfo_contentLeft").animate({ top: 0 }, 0);
    $(".HeaderInfo_contentMiddle").animate({ top: 0 }, 0);
    $(".HeaderInfo_contentRight").animate({ top: 0 }, 0);
    $(".HeaderInfo_contentMiddleLower").animate({ top: 0 }, 0);
    $(".HeaderInfo_contentRightLower").animate({ top: 0 }, 0);
    $(".HeaderInfo_contentMiddle").fadeIn('slow', function() {
        // Animation complete.
    });
}

function EventItemContent_collapse() {
    $("[id$='_lblContent']").slideUp(0, function() {
        // Animation complete.
    });
}

