function Showcase_Gallery(thumb_holders, categories, category_descriptions) {
  var self = this;
  
  this.categories = categories;
  this.category_descriptions = category_descriptions;
  this.thumb_holders = thumb_holders;
  this.thumbs = this.thumb_holders.eq(0).children('img');
  this.basin_holder = this.root;
  this.basins = this.basin_holder.children();

  this.active_index = 0;
  this.auto_play_on = false;
 
  this.start_up = function() {
    self.active_index = 0;
    self.basin_setup();
    self.basins.eq(self.active_index).bind('reload', self.after_image_load);
    self.basins.eq(self.active_index).trigger('reload');
    self.thumbs.bind('click', self.slide_basin);
    self.thumbs.eq(self.active_index).trigger('click');
    self.categories.bind('click', self.category_switch);
  }
  
  this.basin_setup = function() {
    this.basins = $();
    for (var i = 0; i < self.thumbs.length; i++) {
      var new_basin = new Image();
      new_basin.src = self.thumbs.eq(i).attr('src').replace('thumbs/', '');
      self.basins.push(new_basin);
    }
 }
  
  this.category_switch = function(e) {
    self.thumbs.removeClass('active').removeClass('pending');
    var me = $(e.currentTarget);
    me.addClass('active').siblings().removeClass('active');
    var new_category_iter = me.prevAll().length;
    self.thumb_holders.eq(new_category_iter).addClass('active').siblings().removeClass('active');
    self.category_descriptions.eq(new_category_iter).addClass('active').siblings().removeClass('active');
    self.thumbs = self.thumb_holders.eq(new_category_iter).children();
    self.start_up();
  }
  
  this.after_image_load = function(e) {
    if (!e.currentTarget.complete && typeof e.currentTarget.complete == 'boolean') { $(e.currentTarget).bind('load', self.after_image_load); return false;}
    self.auto_play();
  }
  
  this.auto_play = function() {
    if (self.auto_time) {clearTimeout(self.auto_time);}
    if (self.auto_play_on) {
      self.auto_time = setTimeout(function(){self.basin_switch(self.active_index + 1);}, self.auto_play_ammount);
    }
  }
  
  this.slide_basin = function(e) {
    e.preventDefault();
    var me = $(e.currentTarget);
    if (me.hasClass('active') || me.hasClass('pending')) {return false;}
    if (self.auto_time) {clearTimeout(self.auto_time);}
    self.basin_switch(me.prevAll('img').length);
  }
    
  this.basin_switch = function(new_index) {
    if (new_index >= self.thumbs.length) {new_index = 0;}
    else if (new_index < 0) {new_index = self.thumbs.length - 1}
    self.active_index = new_index;
    self.thumbs.eq(self.active_index).addClass('active').siblings().removeClass('active');
    self.basin_holder.prepend(self.basins.eq(self.active_index).css({opacity : 1}));
    self.basins.eq(self.active_index).bind('reloaded', self.basin_visiual_switch);
    self.basins.eq(self.active_index).trigger('reloaded');
  }

  this.basin_visiual_switch = function(e) {
    if (!e.currentTarget.complete && typeof e.currentTarget.complete == 'boolean') { $(e.currentTarget).bind('load', self.basin_visiual_switch); return false;}
    self.basins.eq(self.active_index).unbind();
    self.thumbs.eq(self.active_index).addClass('pending');
    self.skch(self.basins.eq(self.active_index).siblings(), {opacity : 0}, function(){
      self.thumbs.eq(self.active_index).siblings().removeClass('pending');
      self.basins.eq(self.active_index).siblings().remove();
    }, .8, 'easeOutCubic');
    self.auto_play();
  }

  return this;
}


