var thumbs = [];

document.observe('dom:loaded', function(){
  buildPopup();
  initSamples();
});

/*----------------------------------------------------*/
/* Samples                                            */
/*----------------------------------------------------*/

var initSamples = function() {
  thumbs = $$('div.samples img');
  observeThumbs();
};

var observeThumbs = function() {
  thumbs.each(function(thumb){
    Event.observe(thumb, 'click',function(e){
      Event.stop(e);
      var popup = $('popup');
      var image = new Element('img', { src:this.up('a').href, id:'preview' } );
      Event.observe(image, 'click', function(evt){
        $('popup').hide();
        this.remove();
      });
      popup.update(image);
      popup.show();
    });
  });
};

var buildPopup = function() {
  var popup = new Element('div', { id:"popup", className: 'popup' });
  popup.hide();
  $$('body')[0].insert(popup);
};
