(function() {
  var Accordion, Lightbox, Pages, activateAccordionPanel, gotoLightboxIndex, gotoNextLightboxItem, gotoPrevLightboxItem, hideMoreText, inHoverAccordionPanel, onCloseLightbox, outHoverAccordionPanel, setupAccordion, setupLightbox, showLightbox, showMoreText, updateLightboxNav;
  Accordion = {
    panels: null,
    active: null
  };
  setupAccordion = function() {
    Accordion.panels = $('#home-nav .panel');
    Accordion.active = $('#home-nav .active');
    Accordion.panels.bind('click', activateAccordionPanel);
    Accordion.panels.bind('mouseenter', inHoverAccordionPanel);
    return Accordion.panels.bind('mouseleave', outHoverAccordionPanel);
  };
  inHoverAccordionPanel = function(e) {
    return !$(this).hasClass('active') ? $(this).animate({
      width: '+=10'
    }, 200) : null;
  };
  outHoverAccordionPanel = function(e) {
    return !$(this).hasClass('active') ? $(this).animate({
      width: '-=10'
    }, 200) : null;
  };
  activateAccordionPanel = function(e) {
    e.preventDefault();
    if ($('#home-nav').hasClass('init')) {
      $('#home-nav h2, #home-nav h3, #home-nav a').delay(200).fadeIn();
      Accordion.panels.not(this).delay(15).animate({
        width: 92,
        queue: false
      }, 500, function() {
        return $('#home-nav').removeClass('init');
      });
    }
    $(this).unbind('click mouseleave mouseenter');
    if (Accordion.active) {
      Accordion.active.delay(15).animate({
        width: 92,
        queue: false
      }, 500, function() {
        $(this).removeClass('active');
        $(this).bind('click', activateAccordionPanel);
        $(this).bind('mouseleave', outHoverAccordionPanel);
        return $(this).bind('mouseenter', inHoverAccordionPanel);
      });
    }
    Accordion.active = $(this);
    return Accordion.active.animate({
      width: 480,
      queue: false
    }, 500, function() {
      return Accordion.active.addClass('active');
    });
  };
  showMoreText = function(e) {
    e.preventDefault();
    $(this).fadeOut();
    $('.more').slideDown();
    return $('.hide-more').show();
  };
  hideMoreText = function(e) {
    e.preventDefault();
    $(this).hide();
    $('.more').slideUp();
    return $('.show-more').fadeIn();
  };
  Lightbox = {
    current: 0,
    total: 1,
    images: [],
    el: null,
    instance: null
  };
  setupLightbox = function() {
    Lightbox.el = $("#lightbox").overlay({
      fixed: false,
      mask: {
        color: '#a7a59f',
        loadSpeed: 200,
        opacity: 0.9
      },
      load: false,
      onClose: onCloseLightbox
    });
    Lightbox.instance = Lightbox.el.overlay();
    $('#images a').each(function(index) {
      Lightbox.images.push($(this).attr('href'));
      return $(this).bind('click', {
        index: index
      }, showLightbox);
    });
    $('.view-button').bind('click', {
      index: 0
    }, showLightbox);
    $('.next', Lightbox.el).bind('click', gotoNextLightboxItem);
    $('.prev', Lightbox.el).bind('click', gotoPrevLightboxItem);
    Lightbox.total = Lightbox.images.length;
    return $('.total', Lightbox.el).text(Lightbox.total);
  };
  showLightbox = function(e) {
    e.preventDefault();
    gotoLightboxIndex(e.data.index);
    return Lightbox.instance.load();
  };
  onCloseLightbox = function(e) {
    $('#lightbox-content, #lightbox-nav').hide();
    return $('#lightbox-loading').show();
  };
  gotoLightboxIndex = function(index) {
    if (index >= Lightbox.total) {
      index = 0;
    } else if (index < 0) {
      index = Lightbox.total - 1;
    }
    Lightbox.current = index;
    $('#lightbox-content').load(Lightbox.images[index] + " #load", function() {
      $('#lightbox-loading').hide();
      return $('#lightbox-content, #lightbox-nav').show();
    });
    return updateLightboxNav();
  };
  gotoNextLightboxItem = function(e) {
    e.preventDefault();
    return gotoLightboxIndex(Lightbox.current + 1);
  };
  gotoPrevLightboxItem = function(e) {
    e.preventDefault();
    return gotoLightboxIndex(Lightbox.current - 1);
  };
  updateLightboxNav = function() {
    return $('.current', Lightbox.el).text(Lightbox.current + 1);
  };
  Pages = {
    home: function() {
      return setupAccordion();
    },
    theme: function() {
      $('.show-more').bind('click', showMoreText);
      $('.hide-more').bind('click', hideMoreText);
      return setupLightbox();
    }
  };
  $(document).ready(function() {
    return Pages[page] ? Pages[page]() : null;
  });
})();

