/*
 * Controls the menu javascript
 */
(function($) {
  $.extend($.fn, {
    topMenuButton: function(options) {
      return this.each(function() {
        $(this).click(function() {
          var button = $(this);
          var id = button.attr('id');
          var contentId = id.substring(0, id.length - 4) + "Content";
          var content = $("#"+contentId);
          var parent = content.parent();
          parent.children('div').hide();
          button.siblings('li.active').removeClass('active');
          button.addClass('active');
          content.show();
          if (content.is('.not-loaded')) {
            content.loadGalleryThumbnails(options);
          }
        });
      });
    },
    leftMenuButton: function() {
      return this.each(function() {
        $(this).click(function() {
          var button = $(this);
          var id = button.attr('id');
  
          var type = id.substring(0, id.length - 4);
          var contentId = "#" + type + "Content";
          var menuId = "#" +  type + "TopMenu";
  
          $("#contentArea").children('div').hide();
          $("#topMenuArea").children('div').hide();
          var current = $("div.left-menu-active");
          current.removeClass('left-menu-active');
          button.addClass('left-menu-active');
          var content = $(contentId);
          var menu = $(menuId);

          content.show();
          if (menu.size() > 0) {
            menu.show();
            var li = $('div ul li', menu);
            var divs = content.children('div');
            if (li.size() == divs.size()) {
              $(li.get(0)).trigger('click');
            } else {
              li.removeClass('active');
              divs.hide();
              $(divs.get(0)).show();
            }
          }
        });
      });
    }
  });
})(jQuery);

