(function($) {
    $.fn.jExpand = function() {
        var element = this;
        $(element).find("tr:odd").addClass("TableFoodTitle");
        $(element).find("tr:not(.TableFoodTitle)").hide();
        $(element).find("tr:not(.TableFoodTitle)").addClass("TableFoodContent");
        $(element).find("tr:first-child").show();

        $(element).find("tr.TableFoodTitle").hover(
          function() {
              $(this).css({ 'background': '#f6f6f6' });
              $(this).next("tr").css({ 'background': '#f6f6f6' });
          },
          function() {
              $(this).css({ 'background': '#fff' });
              $(this).next("tr").css({ 'background': '#fff' });
          }
        );

        $(element).find("tr.TableFoodContent").hover(
          function() {
              $(this).css({ 'background': '#f6f6f6' });
              $(this).prev("tr").css({ 'background': '#f6f6f6' });
          },
          function() {
              $(this).css({ 'background': '#fff' });
              $(this).prev("tr").css({ 'background': '#fff' });
          }
        );


        $(element).find("tr.TableFoodTitle").click(function() {

            var isVisible = $(this).next("tr").hasClass("VisibleTableFoodTr");
            $(".TableFoodContent").hide();
            $(".TableFoodTitle").find("td").css({ 'border-bottom': 'solid 1px #CECECE' });
            $(".TableFoodTitle").find(".ImageFoodListDownArrow").show();

            if (isVisible) {
                $(this).next("tr").hide();
                $(this).next("tr").removeClass("VisibleTableFoodTr");
            } else {

                $(this).next("tr").show();
                $(this).find("td").css({ 'border-bottom': 'none' });
                $(this).find(".ImageFoodListDownArrow").hide();
                $(this).next("tr").addClass("VisibleTableFoodTr");
            }
        });

    }
})(jQuery); 