(function($){

$.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};
$.easing.easeInOutQuint = function (x, t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
	return c/2*((t-=2)*t*t*t*t + 2) + b;
};

var ns = 'SlideShow';

window[ns] = function ( options ) {

  this.options  = options || {};

  this.root     = $(this.options.root);
  this.box      = $(this.options.box);
  this.item     = $(this.options.item);
  this.prev     = $(this.options.prev);
  this.next     = $(this.options.next);

  this.enable  = this.box.length && this.item.length ? true : false;
  if ( ! this.enable ) return;
  if ( this.size <= 1 ) return;
  
  this.index   = 0;
  this.size    = this.item.length;

  this.observe();
};

window[ns].prototype = {
  
  observe: function () {
    this.prev.click( $.proxy( this.go_prev, this ) );
    this.next.click( $.proxy( this.go_next, this ) );
  },

  go: function ( index ) {
    var offset = this.item.eq(index).position();
    var offsetdata = { left: -offset.left, top: -offset.top };
    var $this = this;

    this.box.animate(offsetdata, {
//        duration: this.duration,
        easing:   "easeInOutQuint"
      });

  },
  
  is_last: function () {
    return this.index + 1 >= this.size;
  },
  
  is_first: function () {
    return this.index - 1 < 0;
  },
  
  go_prev: function ( event ) {
    if ( this.is_first() ) {
      this.index = this.size - 1;
    } else {
      this.index--;
    }
    this.go( this.index );
  },
  
  go_next: function ( event ) {
    if ( this.is_last() ) {
      this.index = 0;
    } else {
      this.index++;
    }
    this.go( this.index );
  }
  
}


})(jQuery);
