//
// Module pattern:
// http://yuiblog.com/blog/2007/06/12/module-pattern
//
var APP = (function($, window, document, undefined) {
  // Expose contents of APP.
  return {
    go: function() {
      for (var i in APP.init) {
        APP.init[i]();
      }
    },
    init: {
      light_table_hover: function() {
        APP.init.light_table_hover.zoomUrls = {};
        $('#light_table').find('.list').find('a').each(function(index){
          $('<div class="zoom" />').prependTo($(this));
          APP.init.light_table_hover.zoomUrls[index] = $(this).attr('href');
        }).mouseenter(function(){
          $(this).find('.zoom').show();
        }).mouseleave(function(){
          $(this).find('.zoom').fadeOut();
        }).click(function(){
          $(this).fancybox({
            openEffect  : 'none',
            closeEffect : 'none'
          });
          return false;
        });
        APP.fullscreen.init();
      }
    },
    fullscreen: {
      init: function(catalog) {
       // console.log(APP.init.light_table_hover.zoomUrls);
       $('#fullscreen').click(function(){
          var g = $('#gallery');
          g.show();
          $('html').addClass('lock');

          for(var i in APP.init.light_table_hover.zoomUrls){
            $('<img />').attr({
              src: APP.init.light_table_hover.zoomUrls[i]
            }).appendTo(g);

          };

         return false;
       });

       $('#exit_fullscreen').click(function(){
         $('#gallery').hide();
         $('html').removeClass('lock');
       })
      }
    }
  };
})(this.jQuery, this, this.document);

//
// Automatically calls all functions in APP.init
//
this.jQuery(document).ready(function() {
  APP.go();
});
