function triggerAreaCodeBlock(area, state) {
    eval(area.find('code.' + state).html());
}
function GetParentByClass(obj, strclass) {
    var t = jQuery(obj);
    while (!t.hasClass(strclass)) { t = t.parent(); }
    return t.get();
}
function expandArea(button, area) {
    var standIn = jQuery('<div/>').css('height', area.height()).addClass('StandIn');
    area.after(standIn);
    area.find('.ExpanderButton').slideUp(200);
    area.css({ display: "block", position: "absolute", top: area.data('orgTop'), zIndex: 20000 })
                                .animate({ right: '240px', top: '0', width: '440px' }, 1000, function () {
                                    area.find('.' + button.rel).show(500);
                                    area.addClass('Expanded');
                                });
    standIn.hide(500);
    AddOverlay();
}
function AddOverlay() {
    if (jQuery.browser.msie && jQuery.browser.version == '6.0') {
        jQuery('.CD_Expandable').bind('click', function (event) {
            event.stopPropagation();
        });
        jQuery('body').bind('click', function () {
            contraptArea();
            jQuery('body').unbind('click');
            jQuery('.CD_Expandable').unbind('click');
        });
    }
    else {
        jQuery("<div/>").attr('id', 'MD_Overlay').addClass('MD_OverlayBG').hide().prependTo(jQuery('.CD_TwoColumnRight')).fadeTo(500, 0.75).click(function () { contraptArea(); });
    }
}
function RemoveOverlay() {
    jQuery('#MD_Overlay').fadeOut(500, function () { jQuery(this).remove(); });
}
function contraptArea() {
    var area = jQuery('.Expanded');
    triggerAreaCodeBlock(area, 'PreClose');
    jQuery('.StandIn').show(500);
    area.animate({ right: '0', top: area.data('orgTop'), width: area.data('orgWidth') }, 1000, function () {
        triggerAreaCodeBlock(area, 'PostClose');
        jQuery('.StandIn').remove();
        RemoveOverlay();
        area.removeClass('Expanded');
        area.css("position", "relative").css('top', '0').css('z-index', '');
    });
}
jQuery(document).ready(function () {
    jQuery('.CD_Expandable').each(function (i) {
        this.id = "Expander_" + i;
        var obj = jQuery(this);
        obj.data("orgTop", obj.position().top);
        obj.data("orgWidth", jQuery(this).width());
    });
    jQuery(".ExpanderButton").click(function () {
        var obj = GetParentByClass(this, "CD_Expandable");
        expandArea(this, jQuery(obj));
        this.blur();
        return false;
    });
});
