function Slider_zoom(set_container) {
  var self = this;
  var _active_index = -1;
  var _direction = _porportion_size_change = 1;
  var _zoomed = false;
  var _initial_small_widths = _initial_large_widths = new Array();
  var _set_container = set_container;
  var _set_container_height = _set_container.height() + 100;
  
  this.basin_holder = this.root.children('div');
  this.basin_wrapper = this.basin_holder.children();
  this.basins = this.basin_wrapper.children();
  this.arrows = this.root.children('img.arrow');
  
  this.start_up = function() {
    self.arrows.bind('click', self.slide_basins);
    self.basin_holder.bind('click', self.basin_zoom_in);
    
    self.basins.eq(self.basins.length - 1).bind('reload', self.after_image_load);
    self.basins.eq(self.basins.length - 1).trigger('reload');
  }
  
  this.get_initial_widths = function() {
    var temp_basin = null;
    for (var i = 0; i < self.basins.length; i++) {
      temp_basin = self.basins.eq(i);
      _initial_small_widths[i] = temp_basin.width();
    }
  }
  
  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.get_initial_widths();
    _set_container_height = _set_container.height();
    self.arrows.eq(1).trigger('click');
  }

  this.index_auto_advance = function() {
    _active_index += _direction;
    if (_active_index >= self.basins.length) { _active_index = 0; }
    if (_active_index < 0) { _active_index = self.basins.length-1; }
  }
  
  this.set_container_height = function(new_height) {
    if (_set_container_height < new_height - 200) {
      _set_container.css({
        height : new_height - 200
      });
    }
  }
  
  this.basin_zoom_in = function(e) {
    if (_active_index != $(e.target).prevAll().length) {
      _active_index = $(e.target).prevAll().length;
      self.visual_slide();
      var badTime = setTimeout(function() {self.basin_zoom_in(e)}, 660);
      return false;
    }
    _zoomed = true;
    var new_size = self.get_real_basin_size(_active_index);
    _porportion_size_change = new_size.heighter / 250;
    self.set_container_height(new_size.heighter);
    self.basin_holder.unbind('click', self.basin_zoom_in);
    self.basin_holder.bind('click', self.basin_zoom_out);
    self.skch(self.basin_holder, {
      left : -new_size.widther/2 + 185,
      top : -200,
      height : new_size.heighter,
      width : new_size.widther
    }, null, 0.5, 'easeOutCubic');
    var new_left_value = (self.basin_wrapper.position().left - 5);
    new_left_value += _active_index * 20;
    new_left_value *= _porportion_size_change;
    new_left_value -= _active_index * 20;
    self.skch(self.basin_wrapper, {
      left : new_left_value
    }, null, 0.5, 'easeOutCubic');
    self.skch(self.arrows, {
      top : -220,
      left : '115%'
    }, null, 0.5, 'easeOutCubic');
  }
  
  this.basin_zoom_out = function(e) {
    _zoomed = false;
    _porportion_size_change = self.basin_holder.height() / 250;
    self.basin_holder.unbind('click', self.basin_zoom_out);
    self.basin_holder.bind('click', self.basin_zoom_in);
    _set_container.css({
      height : _set_container_height + 200
    });
    self.skch(self.basin_holder, {
      left : 15,
      top : 0,
      height : 250
    }, null, 0.5, 'easeOutCubic');
    var new_left_value = (self.basin_wrapper.position().left - 5);
    new_left_value += _active_index * 20;
    new_left_value /= _porportion_size_change;
    new_left_value -= _active_index * 20;
    self.skch(self.basin_wrapper, {
      left : new_left_value
    }, null, 0.5, 'easeOutCubic');
    self.skch(self.arrows, {
      top : -20,
      left : '100%'
    }, null, 0.5, 'easeOutCubic');
    self.set_holder_width();
  }

  this.slide_basins = function(e) {
    if(e.currentTarget.className.match('right')) {
      _direction = 1;
    } else {
      _direction = -1;
    }
    self.index_auto_advance();
    self.visual_slide();
  }
  
  this.visual_slide = function() {
    if (_zoomed) {
      var temp_new_size = self.get_real_basin_size(_active_index);
      _porportion_size_change = self.basin_holder.height()/temp_new_size.heighter;
      self.skch(self.basin_holder, {
        left : -temp_new_size.widther/2 + 185,
        height : temp_new_size.heighter,
        width : temp_new_size.widther
      });
      self.set_container_height(temp_new_size.heighter);
    } else {
      _porportion_size_change = 1;
      self.set_holder_width();
    }
    
    var new_left_value = self.basins.eq(_active_index).position().left;
    new_left_value -= _active_index * 20;
    new_left_value /= _porportion_size_change;
    new_left_value += _active_index * 20;
    self.skch(self.basin_wrapper, {left : -new_left_value });
  }
  
  this.set_holder_width = function() {
    var new_holder_width = 0;
    var next_active_basin_width = 0;
    var iter = _active_index;

    while ((new_holder_width + next_active_basin_width) < 700 && iter < self.basins.length) {
      next_active_basin_width = _initial_small_widths[iter++] + 20;
      new_holder_width += next_active_basin_width;
      next_active_basin_width = _initial_small_widths[iter] + 20;
    }
    new_holder_width -= 15;
    self.skch(self.basin_holder, {width : new_holder_width});
  }
  
  this.get_real_basin_size = function(iter) {
    var temp_size_object = new Object();
    self.basins.eq(iter).css('height', 'auto');
    temp_size_object.heighter = self.basins.eq(iter).height();
    temp_size_object.widther = self.basins.eq(iter).width();
    self.basins.eq(iter).css('height', '100%');
    return temp_size_object;
  }
  
  return this;
}

function Window_size() {
  this.widther = 0;
  this.heighter = 0;
  
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    this.widther = window.innerWidth;
    this.heighter = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    this.widther = document.documentElement.clientWidth;
    this.heighter = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    this.widther = document.body.clientWidth;
    this.heighter = document.body.clientHeight;
  }
  
  return this;
}
