﻿$(document).ready(function() {
//    $("#slider").easySlider({
//        auto: true,
//        continuous: true,
//        numeric: true,
//        pause: 10000,
//        prevId: "sliderArrowPrev",
//        nextId: "sliderArrowNext",
//        prevText: "",
//        nextText: ""
//    });

    $(".closeableContainer").css("visibility", "visible");
    $(".closeableContainer .collapsedPanel").hide();

    $(".closeableContainer .buttonControl").click(function() {
        $(".collapsedPanel", $(this).parent().parent()).toggle();
        $(".expandedPanel", $(this).parent().parent()).toggle();
    });

    $(".slider.closeableContainer .buttonExpand").click(function() {
        UISettings.save("IsStartPageSliderBlockCollapsed", "false");
    });

    $(".slider.closeableContainer .buttonCollapse").click(function() {
        UISettings.save("IsStartPageSliderBlockCollapsed", "true");
    });

    $(".steps.closeableContainer .buttonExpand").click(function() {
        UISettings.save("IsStartPageStepsBlockCollapsed", "false");
    });

    $(".steps.closeableContainer .buttonCollapse").click(function() {
        UISettings.save("IsStartPageStepsBlockCollapsed", "true");
    });

    // thanks to Dan from http://blog.pengoworks.com/index.cfm/2009/4/21/Fixing-jQuerys-slideDown-effect-ie-Jumpy-Animation
    function slideToggle(el, bShow) {
        var $el = $(el), height = $el.data("originalHeight"), visible = $el.is(":visible");

        // if the bShow isn't present, get the current visibility and reverse it
        if (arguments.length == 1) bShow = !visible;

        // if the current visiblilty is the same as the requested state, cancel
        if (bShow == visible) return false;

        // get the original height
        if (!height) {
            // get original height
            height = $el.show().height();
            // update the height
            $el.data("originalHeight", height);
            // if the element was hidden, hide it again
            if (!visible) $el.hide().css({ height: 0 });
        }

        // expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
        if (bShow) {
            $el.show().animate({ height: height }, { duration: 500 });
        } else {
            $el.animate({ height: 0 }, { duration: 500, complete: function() {
                $el.hide();
            }
            });
        }
    }

    $(".nomination .expander img").toggle(function() {
        var context = $(this).parent().parent();
        slideToggle($(".body:first", context));
        $(this).attr("src", "/content/images/start/new/expander_expanded_nomination.jpg");

        if ($(".body:first .loading", context).length > 0) {
            var id = $(".body:first", context).attr("id").replace("nomination", "");
            $(".body:first", context).load("/contest/nominationdata/" + id, function() {
                $(".body:first", context)
                    .data("originalHeight", "")
                    .height("auto");
            });
        }
    }, function() {
        slideToggle($(".body:first", $(this).parent().parent()));
        $(this).attr("src", "/content/images/start/new/expander_collapsed_nomination.jpg");
    });

    $(".nomination .expander img").mouseover(function() {
        $(this).attr("src", $(this).attr("src").replace(/\.jpg/, "_over.jpg"));
    });

    $(".nomination .expander img").mouseout(function() {
        $(this).attr("src", $(this).attr("src").replace(/_over\.jpg/, ".jpg"));
    });
});

