var Fader, runLater, trigger_after;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
runLater = function(pause, fn) {
  return setTimeout(fn, pause);
};
$.fn.exists = function() {
  return this.length > 0;
};
$.fn.fader = function(callback, delay) {
  var f, self;
  if (delay == null) {
    delay = Fader.DELAY;
  }
  self = $(this);
  if (self.data('fader')) {
    return self.data('fader');
  } else {
    f = new Fader(self, callback, delay);
    self.data('fader', f);
    return f;
  }
};
Fader = (function() {
  Fader.DELAY = 3000;
  function Fader(container, callback, delay) {
    this.container = container;
    this.callback = callback != null ? callback : false;
    this.delay = delay != null ? delay : Fader.DELAY;
    this.update = __bind(this.update, this);
    this.container.data('fader', this);
    this.id = this.container.attr('id');
    this.images = this.container.find('IMG').hide();
    this.handle = null;
    this.curImage = null;
  }
  Fader.prototype.update = function() {
    this.curImage.fadeOut(500);
    this.curImage = this.curImage.next('img');
    if (this.curImage.exists()) {
      this.curImage.slideFadeIn(300);
      return this.handle = setTimeout(this.update, this.delay);
    } else {
      return this.onComplete();
    }
  };
  Fader.prototype.start = function() {
    this.images.hide();
    this.curImage = this.images.first();
    this.curImage.slideFadeIn(300);
    return this.handle = setTimeout(this.update, this.delay);
  };
  Fader.prototype.onComplete = function() {
    if (this.callback) {
      return this.callback(this);
    }
  };
  Fader.prototype.stop = function() {
    return clearTimeout(this.handle);
  };
  return Fader;
})();
trigger_after = function(times, fn) {
  var count;
  count = 0;
  return function() {
    count += 1;
    if (count === times) {
      fn(count, times);
      return count = 0;
    }
  };
};
$.fn.showCollection = function() {
  var callback, self;
  self = $(this);
  callback = trigger_after(2, function() {
    return runLater(500, function() {
      return $.hideCollections(true);
    });
  });
  $(this).show();
  $('#Overlay').fadeIn(1000);
  runLater(1000, function() {
    return self.find('.col1').fader(callback).start();
  });
  return runLater(1000 + (Fader.DELAY / 2), function() {
    return self.find('.col2').fader(callback).start();
  });
};
$.hideCollections = function(fade) {
  if (fade == null) {
    fade = false;
  }
  if (fade) {
    $('#Overlay').fadeOut(1000);
    return runLater(1000, function() {
      return $('.Collection').hide();
    });
  } else {
    $('#Overlay').hide();
    return $('.Collection').hide();
  }
};
$(function() {
  $('#CollectionPager').html('See previous collections from <a id="col2008" href="#2008">2008</a> or <a id="col2009" href="#2009">2009</a>.');
  $('#col2008').bind('click', function(e) {
    e.preventDefault();
    return $('#Collection2008').showCollection();
  });
  $('#col2009').bind('click', function(e) {
    e.preventDefault();
    return $('#Collection2009').showCollection();
  });
  $('a.close').bind('click', function(e) {
    e.preventDefault();
    return $.hideCollections();
  });
  return $('a.close').hide();
});
