﻿/// <reference path="jquery-1.4.1-vsdoc.js" />

function refreshCufon() {
    if ($.browser.msie && parseInt($.browser.version) == 7)
        Cufon.refresh();
}

$(function () {
    $(".DrinkOption").each(function () {
        var checkBox = $("input", $(this));
        var optionBox = $(".OtherTextBox", $(this));
        var children = $(this).next('.Children');

        if (!checkBox.attr("checked")) {
            children.hide();
            optionBox.hide();
        }
        else {
            children.show();
            optionBox.show();
        }


        var update = function () {
            // hide children if unchecked
            var isChecked = checkBox.attr("checked");
            if (isChecked) {
                // hide all grandchildren before showing parent
                $(".Children", children).hide();
                optionBox.show();
                if (children.find(".DrinkOption").length > 0)
                    children.slideDown('slow', refreshCufon);
                return;
            }

            // uncheck child checkboxes and show
            $("input[type=checkbox]", children)
                    .attr("checked", false)
                    .checkBox('changeCheckStatus', false);
            children.slideUp('slow');
            optionBox.hide();
            $(".OtherTextBox", children).hide();
        };
        checkBox.click(update);
        checkBox.change(update);

    });
});

