﻿$(document).ready(function() {

    if ((jQuery.browser.msie) && (jQuery.browser.version <= 7))
    {
        $(".ecbBox input:checkbox").css("margin", "0");
    }

});

function ecbFloat(parent)
{
    if (openedId == "")
    {
        openedId = parent;
        ecbShow(parent);
    }
    else
    {
        if (openedId == parent)
        {
            openedId = "";
            ecbClose(parent);
        }
        else
        {
            ecbClose(openedId);
            openedId = parent;
            ecbShow(parent);
        }
    }
}

var openedId = "";

function ecbShow(id)
{
    $("#" + id).height($("#" + id + "_fl").height());   
    $("#" + id + "_fl").css("position", "absolute").animate({ height: ($("#" + id + "_fl input:checkbox").size()) * 20 + $("#" + id + "_fl .ecbSumary").height() }, "slow");
}

function ecbClose(id)
{
    $("#" + id + "_fl").animate({ height: $("#" + id + "_fl").children(".ecbSumary").height() }, "slow", function() { $("#" + id + "_fl").css("position", "static"); });
}

function ecbCheckboxClick(me)
{
    var filter = "";
    var count = 0;
    $(me).parent().children("input:checkbox").each(function(i)
    {
        if ($(this).attr("checked"))
        {
            filter += $(this).next().html() + ", ";
            count++;
        }

    });

    var parent = $(me).parent().parent().children(".ecbSumary");
    var h = 0;
    if (count % 2 == 0) {
        h = 20 * count / 2;
    }
    else {
        h = 20 * count / 2 + 10;
    }
    if (filter != "")
    {
        parent.children(".showAll").hide();
        parent.children(".showCustom").show().html(filter);
        parent.parent().height(h + $(me).parent().children("input:checkbox").size() * 20);
    }
    else
    {
        parent.children(".showCustom").hide();
        parent.children(".showAll").show();
        h = 20;
    }
    parent.height(h);
    parent.parent().parent().height(h);
    parent.parent().parent().css("margin-bottom", "3px");
    parent.parent().parent().parent().height(h)
}
