function Header_widgets() {
  var self = this;
  this.widgeters = this.root.children().children();
  this.widget_links = this.widgeters.children('a');
  
  this.active_hover = null;
  this.active_click = null;
  
  this.start_up = function() {
    self.widget_links.bind('mouseover', self.aminate_over);
    self.root.bind('mouseleave', self.aminate_out);
    self.widget_links.bind('click', self.show_tip)
    self.widgeters.children('div').children('h4').children('img').bind('click', self.hide_tip)
  }
  
  this.show_tip = function(e) {
    if (self.active_click) {
		self.sketcher.draw(self.active_click, {opacity: 0, top : 120}, function() { 
			$(this).css('display', 'none');
		});
    }
	if (navigator.appName == "Microsoft Internet Explorer") {
		self.active_click = $(e.currentTarget).siblings('div').css({
			filter: 'filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0)', 
			filter: 'alpha(opacity = 0)', 
			display : 'block',
			top : 120});
			
		self.active_click.animate({
			filter: 'filter:progid:DXImageTransform.Microsoft.Alpha(opacity=1)',
			filter: 'alpha(opacity = 1)',
			top: 30
		}, 1000);
		
		//self.active_click.siblings('a').trigger('mouseover');
	}
		self.active_click = $(e.currentTarget).siblings('div').css({opacity: 0, display : 'block', top : 120});
		//self.sketcher.draw(self.active_click, {opacity: 1, top : 30});
		self.active_click.animate({
			opacity: 1,
			top: 30
			}, 1000 );
		
		self.active_click.siblings('a').trigger('mouseover');
  }
  
  this.hide_tip = function(e) {
    self.sketcher.draw(self.active_click, {opacity: 0, top : 120}, function() { 
      $(this).css('display', 'none');
    });
    self.active_click = null;
  }
  
  this.aminate_over = function(e) {
    var new_active = $(e.currentTarget).children();
    var old_active = self.active_hover;
    self.active_hover = new_active;
    if (old_active) {
      self.sketcher.draw(old_active.eq(0), {opacity: 1}, function(){}, .35, 'easeInCubic');
      self.sketcher.draw(old_active.eq(1), {opacity: 0}, function(){}, .35, 'easeInCubic');
    }
    self.sketcher.draw(new_active.eq(0), {opacity: 0}, function(){}, .35, 'easeInCubic');
    self.sketcher.draw(new_active.eq(1), {opacity: 1}, function(){}, .35, 'easeInCubic');
  }
  
  this.aminate_out = function(e) {
    if (self.active_hover) {
      self.sketcher.draw(self.active_hover.eq(0), {opacity: 1}, function(){}, .35, 'easeInCubic');
      self.sketcher.draw(self.active_hover.eq(1), {opacity: 0}, function(){}, .35, 'easeInCubic');
      self.active_hover = null;
    }
  }
  
  return this;
}

function Footer_widgets() {
  var self = this;
  this.widgeters = this.root;
  this.widget_links = this.widgeters.siblings('img');
  
  for (var i = 0; i < this.widgeters.length; i++) {
    this.widgeters.eq(i).show().css({top: -this.widgeters.eq(i).outerHeight(true)}).hide();
  }
  
  this.active_hover = null;
  this.active_click = null;
  
  this.start_up = function() {
    self.widget_links.bind('click', self.show_tip)
    self.widgeters.children('h4').children('img').bind('click', self.hide_tip);
  }
  
  this.show_tip = function(e) {
    if (self.active_click) {
      self.sketcher.draw(self.active_click, {opacity: 0}, function() { 
        $(this).css('display', 'none');
      });
    }
    self.active_click = $(e.currentTarget).siblings('div').css({opacity : 0, display : 'block'});
    self.sketcher.draw(self.active_click, {opacity: 1});
  }
  
  this.hide_tip = function(e) {
    self.sketcher.draw(self.active_click, {opacity: 0}, function() { 
      $(this).css('display', 'none');
    });
    self.active_click = null;
  }
  
  this.aminate_over = function(e) {
    var new_active = $(e.currentTarget).children();
    var old_active = self.active_hover;
    self.active_hover = new_active;
    if (old_active) {
      self.sketcher.draw(old_active.eq(0), {opacity: 1}, function(){}, .35, 'easeInCubic');
      self.sketcher.draw(old_active.eq(1), {opacity: 0}, function(){}, .35, 'easeInCubic');
    }
    self.sketcher.draw(new_active.eq(0), {opacity: 0}, function(){}, .35, 'easeInCubic');
    self.sketcher.draw(new_active.eq(1), {opacity: 1}, function(){}, .35, 'easeInCubic');
  }
  
  this.aminate_out = function(e) {
    if (self.active_hover) {
      self.sketcher.draw(self.active_hover.eq(0), {opacity: 1}, function(){}, .35, 'easeInCubic');
      self.sketcher.draw(self.active_hover.eq(1), {opacity: 0}, function(){}, .35, 'easeInCubic');
      self.active_hover = null;
    }
  }
  
  return this;
}

function Text_input_default_vaule_switch() {
  var self = this;
  this.input_text = this.root;
  this.default_value = this.root.val().toString();
  
  this.start_up = function() {
    self.input_text.bind('focus', self.set_visible_value)
    self.input_text.bind('blur', self.reset_visible_value)
  }

  this.reset_visible_value = function() {
    if (self.input_text.val() == ' ' || self.input_text.val() == '') {
      self.input_text.val(self.default_value);
    }
  }
  
  this.set_visible_value = function() {
    if (self.input_text.val() == self.default_value) {
      self.input_text.val('');
    }
  }
  
  return this;
}

function Button_pusher() {
  var self = this;
  this.buttons = this.root;
  this.start_up = function() { 
    for (var i = 0; i < self.buttons.length; i++) {
      self.button_style(self.buttons.eq(i));
    }
  }
  
  this.button_style = function(button) {
    if (button.children().length < 1) {
      button.html('<span>&nbsp;</span><strong>' + button.html() + '</strong>').addClass('submit');
      // possible ie fix..
      // button.width(button.width());
    }
  }
  
  return this;
}

function Sidebar_designer_navigation() {
  var self = this;
  this.designer_chooser = this.root.find('select');
  
  this.start_up = function() {
    self.designer_chooser.bind('change', self.designer_choice);
  }
  
  this.designer_choice = function(e) {
    document.location = self.root.attr('action') + '/' + e.currentTarget.options[e.currentTarget.selectedIndex].value;
  }
  
  return this;
}

// Use this to load a new URL when you want to ensure that the address will be
// loaded over HTTP instead of, for example, HTTPS.
//
// Currently this function only accepts absolute paths.
var redirect_over_http = function(path) {
		window.location = 'http://' + window.location.host + path;
};

function Submit_order_total_modification() {
  var self = this;
	this.modification_submit = this.root.find('input.submit');
	this.get_url = "/cart/total";
  this.order_total_adjustment        = this.root.find('#order_total_adjustment'),
  this.order_total_adjustment_type   = this.root.find('#order_total_adjustment_type'),
  this.shipping_cost_adjustment      = this.root.find('#shipping_cost_adjustment'),
  this.shipping_cost_adjustment_type = this.root.find('#shipping_cost_adjustment_type');
  
  this.start_up = function() {
    self.modification_submit.bind('click', self.modify_order_total);
  }
  
  this.modify_order_total = function(e) {
		var parameters = []
	  if (self.order_total_adjustment.val()) {
	    parameters.push("order_total_adjustment=" + self.order_total_adjustment.val());
	    parameters.push("order_total_adjustment_type=" + self.order_total_adjustment_type.val());
	  }
	  if (self.shipping_cost_adjustment.val()) {
	    parameters.push("shipping_cost_adjustment=" + self.shipping_cost_adjustment.val());
	    parameters.push("shipping_cost_adjustment_type=" + self.shipping_cost_adjustment_type.val());
	  }
		redirect_over_http(self.get_url + '?' + parameters.join('&'));
  }
  
  return this;
}

function Sidebar_labels() {
  var self = this;
  this.label_holder = this.root;
  this.label_filter = this.label_holder.children('form');
  this.label_button = this.label_holder.children('h3');
  this.start_up = function() {
    self.label_filter.bind('submit', self.get_labels);
    self.label_button.bind('click', self.open_labels);
  }
  
  this.get_labels = function(e) {
    e.preventDefault;
    if (self.label_filter.find('input#query').val().match(/what are you looking for?/i)) {
      self.label_filter.find('input#query').val('')
    }
    return true;
  }
  this.open_labels = function(e) {
    self.label_button.unbind('click', self.open_labels);
    self.label_button.bind('click', self.close_labels);
    self.label_button.children('a').html('[click to close]')
    self.sketcher.draw(self.label_holder.addClass('open'), {
      height: 750
    }, null, 1, 'easeInQuad');
    if (self.label_holder.siblings('#side_extender')) {
      self.sketcher.draw(self.label_holder.siblings('#side_extender'), {
        height: self.label_holder.siblings('#side_extender').height() - 660
      }, null, 1, 'easeInQuad');
    }
  }
  this.close_labels = function(e) {
    self.label_button.unbind('click', self.close_labels);
    self.label_button.bind('click', self.open_labels);
    self.label_button.children('a').html('[click to expand]')
    self.sketcher.draw(self.label_holder, {
      height: 90
    }, function() {self.label_holder.removeClass('open')}, 1);
    if (self.label_holder.siblings('#side_extender')) {
      self.sketcher.draw(self.label_holder.siblings('#side_extender'), {
        height: self.label_holder.siblings('#side_extender').height() + 660
      }, null, 1);
    }
  }
  
  return this;
}

function Sidebar_expander(bodier) {
  var self = this;
  this.bodier = bodier;
  this.extended_height = 0;
  this.reset_extender = function(e) {
    self.extended_height = self.bodier.outerHeight() - self.root.position().top;
    self.root.height(self.extended_height);
  }
  
  this.start_up = function() {
    $(window).bind('load', self.reset_extender);
    //self.reset_extender();
  }
  return this;
}

function Home_store() {
  var self = this;
  this.store = this.root;
  this.tabs = this.store.children('.tabs').children();
  this.basins = this.store.children('.basins').children();
  
  this.store_interface = new Runes({
    basins : this.basins,
    basin_visual_active : false,
    change_wrapper_height : false
  },{
    tabs : this.tabs,
    switch_method : 'basic_switch',
    tab_visual_active : true
  }).start_up();
  
  return this;
}

function Mini_cart() {
  var self = this;
  this.mini_cart = this.root;
  this.cart_object = new Object();
  this.total_price = this.mini_cart.children('h3');
  this.total_price.push(this.mini_cart.find('h5 strong')[0])
  this.cart_items = this.mini_cart.find('ol');
  this.item_count = this.mini_cart.find('h4 em');
  this.click_trigger = true;
  this.already_jaxed = false;
  this.cart_out = true;
  this.cart_slid_out = false;
  this.cart_details = self.mini_cart.children('div');
  this.cart_cookie = new Cookier('cartinfo');
  this.cart_ck_price = this.cart_cookie.eat_cookie();
  if (this.cart_ck_price) {
    this.cart_ck_price = unescape(this.cart_ck_price).replace(/\+/g, '').replace(/\"/g,'')
    this.cart_ck_price = 'self.cart_ck_price = ' + this.cart_ck_price;
    eval(this.cart_ck_price);
    this.total_price.html(Number_to_currency(self.cart_ck_price.total));
  } else {
    this.total_price.html(Number_to_currency(0));
  }
  
  this.start_up = function() {
    self.mini_cart.bind('update_cart', self.get_cart);
    self.total_price.bind('click', self.toggle_cart);
    self.total_price.bind('mouseover', self.cart_peep);
    self.item_count.siblings('img.close').bind('click', self.take_cart_out);
    self.mini_cart.bind('mouseleave', self.take_cart_out);
    //self.cart_details.bind('mouseover', self.toggle_cart);
  }
  
  this.cart_peep = function() {
    if (self.cart_delay) {
      clearTimeout(self.cart_delay);
    }
    if (!self.cart_slid_out && self.cart_out) {
     self.cart_slid_out = true;
      self.sketcher.draw(self.cart_details.css({
        display: 'block', 
        top: -self.cart_details.outerHeight(), 
        opacity : 0
      }), {
        top: -self.cart_details.outerHeight() + self.cart_details.children('div.cart_actions').outerHeight(),
        opacity: 1
      });
    }
  }
  
  this.toggle_cart = function(e) {
    if (self.cart_out) {
      self.get_cart(0)
    } else {
      self.take_cart_out();
    }
  }
  
  this.take_cart_out = function(e) {
    if (e) {
      if (e.currentTarget.className == 'close' || self.cart_out) {
        self.cart_outer(true);
      } else {
        self.total_price.bind('mouseover', self.cart_peep);
        self.cart_outer(false);
      }
    } else {
      self.cart_outer(true);
    }
  }
  
  this.cart_outer = function(price_bound) {
    self.cart_out = true;
    self.cart_slid_out = false;
    self.sketcher.draw(self.cart_details, {
      top: -self.cart_details.height() -50,
      opacity: 0
    }, function() {
      if (price_bound) {
        self.total_price.bind('mouseover', self.cart_peep);
      }
    }, .8);
  }
  
  this.bring_cart_in = function(auto_out) {
    if (!self.cart_slid_out) {
      self.total_price.unbind('mouseover', self.cart_peep);
      self.cart_details.css({
        display: 'block', 
        top: -self.cart_details.height() -50, 
        opacity : 0
      });
    }
    self.sketcher.draw(self.cart_details, {
      top: 0,
      opacity: 1
    }, function() {
      self.cart_out = false;
      self.mini_cart.trigger('cart_updated');
      if (auto_out) {
        setTimeout(function() {
          self.take_cart_out();
        }, 3000);
      }
    }, .8);
  }
  
  this.populate_cart = function(data, textStatus) {
    self.cart_object = data.items;
    self.total_price.html(Number_to_currency(data.total));
    self.item_count.html(data.items.length)
    var temp_cart = '';
    for (var i = 0; i < self.cart_object.length; i++) {
      temp_cart += '<li>' + self.build_cart_item(self.cart_object[i].name, self.cart_object[i].total_cost) + '</li>';
    }
    if (temp_cart == '') {
      temp_cart = '<li><em>-- no items --</em> <span> </span><strong>$--.--</strong></li>'
    }
    self.cart_items.html(temp_cart);
    if (self.click_trigger) {
      self.bring_cart_in(false);
    } else {
      self.bring_cart_in(true);
    }
    if (!self.already_jaxed) { self.already_jaxed = true; }
  }
  
  this.get_cart = function(e, data) {
    //self.populate_cart(data.cart);
    self.click_trigger = (e == 0 ? true : false );
    if (self.already_jaxed && self.click_trigger) {
      self.bring_cart_in(false);
      return true;
    }
    $.ajax({
      dataType : 'json',
      url : '/cart.json',
      success : self.populate_cart
    })
  }
  
  this.build_cart_item = function(product_name, product_price) {
    return '<em>' + product_name + '</em><span>&nbsp;</span><strong>' + Number_to_currency(product_price) + '</strong>';
  }
  
  return this;
}

function Product_plus(mini_cart) {
  var self = this;
  this.product_vitals = this.root;
  this.mini_cart = mini_cart;
  this.product_options = this.product_vitals.find('#product_chooser select');  
  this.product_id = this.product_vitals.find('#product_variation_id');
  this.product_price = this.product_vitals.find('#product_price');
  this.product_availabily = this.product_vitals.find('#product_availabily');
  this.product_warning = this.product_vitals.find('.product_warning');
  this.product_options_loading_idicator = this.product_vitals.find('#product_chooser h4')
  this.product_updater = null;
  this.loading_indicator = this.product_vitals.find('button#addcart').addClass('disabled').children('span');
  this.actioner  = '/cart/items';
  
  this.start_up = function() {
    self.product_warning.children('div.no_options').siblings().hide();
    self.product_vitals.find('button').bind('click', self.pick_action);
    if (self.product_vitals.children('#product_chooser').hasClass('remote')) {
      self.product_options.bind('change', self.update_product);
      self.product_options.trigger('change', self.update_product);
    } else {
      self.loading_indicator.parent().removeClass('disabled');
    }
    self.product_vitals.bind('submit', self.send_to_cart);
  }
  
  this.cart_here = function() {
    self.sketcher.draw(self.loading_indicator.children(), {opacity : 0}, function() {
      self.loading_indicator.html('&nbsp;');
    }, .45);
    self.sketcher.draw(self.loading_indicator.siblings(), {lineHeight :100, width: 103}, function() {
      self.loading_indicator.siblings().html('add to cart');
      self.sketcher.draw(self.loading_indicator.siblings(), {lineHeight :29}, null, .5);
    }, .5);
    self.sketcher.draw(self.loading_indicator, { width: 1, paddingLeft: 5 }, null, 1);
  }
  
  this.wait_for_cart = function(data, textStatus) {
    if (this.url.match('wishlist')) {

    } else if (this.url.match('registries')) {

    } else {;
      self.mini_cart.trigger('update_cart', data);
      self.mini_cart.bind('cart_updated', self.cart_here);
    }
  }

  this.pick_action = function(e) {
    self.actioner = $(e.currentTarget).attr('value');
    if ($.browser.msie) {
      var temp_action = e.currentTarget.outerHTML.toString().match(/value\=\".*?\"/);
      if (temp_action) {
        temp_action = temp_action.toString().replace('value="', '').replace('"','');
        self.actioner = temp_action;
      }
    }
  }
  
  this.options_yet_selected = function() {
    for (var i = 0; i < self.product_options.length; i++) {
      if (self.product_options[i].selectedIndex == 0) {
        self.product_options.eq(i).addClass('required');
      }
    }
    self.product_warning.addClass('required')
  }
  
  this.send_to_cart = function(e) {
    e.preventDefault();
    self.loading_indicator.parent().blur();
    if (self.product_id.val() == "") {
      self.options_yet_selected();
      return false;
    }
    if (self.cart_updater) {
      self.cart_updater.abort();
    }
    if (self.actioner.match('wishlist')) {
      self.product_warning.children('div.wishlist').show().siblings().hide();
    } else if (self.actioner.match('registries')) {
      self.product_warning.children('div.registry').show().siblings().hide();
    } else {;
      self.loading_indicator.html('<img src="/images/forms/preloader_aqua.gif" />');
      self.sketcher.draw(self.loading_indicator.children(), { opacity: 1 }, null, 1.2);
      self.sketcher.draw(self.loading_indicator, { width: 20, paddingLeft: 16 }, null, 1);
      self.sketcher.draw(self.loading_indicator.siblings(), {lineHeight :100, width: 131}, function() {
        self.loading_indicator.siblings().html('adding to cart');
        self.sketcher.draw(self.loading_indicator.siblings(), {lineHeight :29}, null, .5);
      }, .5);
      
      self.sketcher.draw(self.loading_indicator.parent(), {opacity: .5}, function() {
        self.sketcher.draw(self.loading_indicator.parent(), {opacity: 1}, null, .5);
      }, .5);
    }
    self.cart_updater = $.ajax({
      dataType: 'json',
      type: 'POST',
      url : self.actioner,
      data : self.product_vitals.serialize(),
      success : self.wait_for_cart
    });
    return false;
  }
  
  this.change_product = function(data, text_status) {
    self.product_options_loading_idicator.removeClass('loading');
    if (data.product_variation_id) {
      self.product_warning.removeClass('required')
      self.loading_indicator.parent().removeClass('disabled');
      self.product_id.val(data.product_variation_id);
			var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
			var weekdays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
			var ta_date = new Date(data.product_variation_estimated_ship_date);
      var temp_avaiabilty_date = '*estimated to ship on or before: <br />' + weekdays[ta_date.getDay()] + ', ' + months[ta_date.getMonth()] + ' ' + ta_date.getDate() + ', ' + ta_date.getFullYear();
      // temp_avaiabilty_date += new Date(data.product_variation_estimated_ship_date).toLocaleFormat("%A, %B %e, %Y");
      self.product_availabily.html(temp_avaiabilty_date)
      self.product_price.html(Number_to_currency(data.product_variation_price));
      /**** COMMENTED OUT BECAUSE IT DOESN'T WORK - MtB ****
      if (product_variation_shipping_rate) {
        self.product_vitals.find('fieldset h5 span.estimate').html('+' + product_variation_shipping_rate.toString())
      } else {
        self.product_vitals.find('fieldset h5 span.estimate').html('free!')
      }
      ******/
    } else {
      self.product_id.val('');
      for (var item in data) {
        var temp_select = self.product_options.filter('#' + item.toString());
        var temp_options = '<option value="">-- select --</option>';
        for (var i = 0; i < data[item].length; i++) {
          temp_options += '<option value="' + data[item][i] + '">' + data[item][i] + '</option>';
        }
        temp_select.removeClass('loading').html(temp_options);
      }
    }
  }
  
  this.update_product = function(e) {
    var me = $(e.currentTarget);
    for (var i = 0; i < self.product_options.length; i++) {
      if (self.product_options[i].selectedIndex == 0) {
        self.product_options.eq(i).children('option').html('-- loading options --');
        self.product_options.eq(i).addClass('loading');
      }
    }
    self.product_options_loading_idicator.addClass('loading');
    if (self.product_updater) {
      self.product_updater.abort();
    }
    self.product_updater = $.ajax({
      dataType: 'json',
      url : location.pathname + '/options',
      data : self.product_vitals.serialize().replace(/\&product_variation_id.*/,''),
      success : self.change_product
    });
  }
  
  return this;
}

function Product_grid_fixer() {
  var self = this;
  this.product_titles = this.root.find('div.product');
  if (this.product_titles.length < 5) { return this }
  number_in_column = 4;
  for (var i = 0; i < this.product_titles.length; i++) {
    if ((i+1)%number_in_column == 0) {
	  if ((document.all)&&(navigator.appVersion.indexOf("MSIE 7.0")!=-1)) {
		this.product_titles.eq(i).after('<hr>')
	  }
	  this.product_titles.eq(i).after('<hr />')
    }
  }  

  return this;
}

function Image_gallery() {
  var self = this;
  this.image_tabs = this.root.find('div.tabs div.holder img');
  this.large_images = this.root.find('div.basins div.holder img');
  this.tab_sliders = this.root.find('div.tabs').children('a');
  this.photo_description = this.root.find('h5.photo_description');
  this.full_size = new Array();
  
  this.thumb_clone_iteration = 0;
  this.clone_iteration = 0;
    
  this.gallery_interface = new Runes({
    basins : this.large_images,
    center_basin : true,
    infinate_scroll : true
  },{
    tabs : this.image_tabs, 
    switch_method : 'all_slide_switch',
    tab_animation: {
      over : { opacity : 1 },
      out : { opacity : .5 }
    }
  },{
    sliders : this.tab_sliders,
    switch_method : 'all_slide_switch',
    auto : false,
    slide_animation: {
      over : { opacity : 1 },
      out : { opacity : .5 }
    }
  },{
    switch_method : 'all_slide_switch'
  }).start_up();
  
  
  this.popin_whipup = function() {
    var popin = new Image_gallery_Popin_view();
    popin.view.popin_content += '<div class="holder" >';
    for (var i = 0; i < self.large_images.length; i++) {
      self.full_size[i] = new Image();
      self.full_size[i].src = self.large_images[i].src.replace('large.jpg', 'zoom.jpg');
      self.full_size[i].alt = self.large_images[i].alt;
      self.full_size[i].title = self.large_images[i].title;
      popin.view.popin_content += '<div class="basin" >';
      popin.view.popin_content += '<img src="' + self.full_size[i].src + '" alt="' + self.full_size[i].alt + '" />';
      if (self.full_size[i].title) {
        popin.view.popin_content += '<p>' + self.full_size[i].title + '</p>';
      }
      popin.view.popin_content += '</div>';
    }
    popin.view.popin_content += '</div>';
    return popin;
  }
  
  this.start_up = function() {
    self.large_images.bind('click', self.big_image);
    //self.large_images.bind('mouseenter', self.bring_in_zoom_graphic);
     self.root.children('#click_to_enlarge').bind('click', self.big_popup_blah);
    //self.root.bind('mouseleave', self.take_out_zoom_graphic);
    self.gallery_interface.basin_wrapper.bind('new_active', self.swich_description);
    //self.gallery_interface.tabs.eq(self.orig_length-1).trigger('click');
    self.ready_popin = self.popin_whipup();
    self.gallery_popin = new Popin(self.ready_popin);
  }
  
  this.big_popup_blah = function() {
    self.large_images.filter('.active').trigger('click')
  }
  
  this.bring_in_zoom_graphic = function(e) {
    var me = $(e.currentTarget);
    if (me.hasClass('active')) {
      self.root.children('#click_to_enlarge').show();
    } else {
      self.root.children('#click_to_enlarge').hide();
    }
  }
  
  this.take_out_zoom_graphic = function(e) {
    self.root.children('#click_to_enlarge').hide();
  }
  
  this.swich_description = function() {
    var current_description = self.gallery_interface.basins[self.gallery_interface.active_index].title;
    if (current_description) {
      self.photo_description.css({visibility : 'visible'}).html(current_description)
    } else {
      self.photo_description.css({visibility : 'hidden'});
    }
  }
  
  this.bi_gallery_linkup = function() {
    self.gallery_interface.tabs.eq(self.full_gallery.active_index).trigger('click');
  }
    
  this.big_image = function(e) {
    var me = $(e.currentTarget);
    var clicked_iter = me.prevAll().length;
    if (!me.hasClass('active')) {
      self.gallery_interface.tabs.eq(clicked_iter).trigger('click');
      return false;
    }
    self.gallery_popin.plugin_popin(self.root.parents('#content'));
    self.full_gallery = new Runes({
      basins : self.gallery_popin.popin_content.children('div.holder').children(),
      basin_visual_active : true,
      change_wrapper_height : true,
      change_wrapper_width : true,
      infinate_scroll : true
    },{
      sliders : self.gallery_popin.popin_actions.children('img').not('.close'),
      switch_method : 'all_slide_switch',
      auto : false,
      slide_animation: {
        over : { opacity : 1 },
        out : { opacity : .5 }
      }
    }).start_up();
    self.full_gallery.basin_wrapper.bind('new_active', self.bi_gallery_linkup)
    self.full_gallery.slide_goto(clicked_iter);
 }
  
  return this;
}

function Product_tabs() {
  var self = this;
  this.product_details = this.root;
  this.product_tabs = this.product_details.children('.tabs').children();
  this.product_basins = this.product_details.children('.basin');
  
  this.store_interface = new Runes({
    basins : this.product_basins,
    basin_visual_active : false,
    change_wrapper_height : false
  },{
    tabs : this.product_tabs,
    switch_method : 'basic_switch',
    tab_visual_active : true
  }).start_up();
  
  return this;
}

function Active_shelving() {
  var self = this;
  this.product_header = this.root.find('div.header');
  this.sort_options = this.product_header.children('form');
  this.sort_link = this.product_header.children('a#sort_link')
  
  this.start_up = function() {
    self.sort_link.bind('click', self.show_options);
    self.sort_options.children('h4').children('img.closer').bind('click', self.hide_options);
  }
  
  this.show_options = function(e) {
    self.sort_link.addClass('active').unbind('click', self.show_options)
    self.sort_link.bind('click', self.hide_options)
    self.sort_options.fadeIn(300);
  }

  this.hide_options = function(e) {
    self.sort_link.removeClass('active').unbind('click', self.hide_options)
    self.sort_link.bind('click', self.show_options)
    self.sort_options.fadeOut(300);
  }
  
  return this;
}

function Home_sidebar_callout() {
  var self = this;
  this.expanded = false;
  
  this.always_viewable = this.root.children('p');
  this.collapsed_height = this.always_viewable.outerHeight();
  this.expanded_height = this.root.outerHeight();
  
  this.root.height(this.collapsed_height);
  this.root.append('<a class="collapse_trigger" href="#open"> read more </a>');
  this.expand_link = this.root.children('a:last');
  
  this.start_up = function() {
    self.expand_link.bind('click', self.toggle_visible);
  }
  
  this.toggle_visible = function(e) {
    var new_height = (self.expanded ? self.collapsed_height : self.expanded_height );
    var current_action = (self.expanded ? 'read more' : 'close' );
    self.expand_link.html(current_action)
    self.sketcher.draw(self.root, { height : new_height });
    self.expanded = !self.expanded;
  }
  
  return this;
}

function Table_striper() {
  var self = this;
  if (this.root.is('table')) {
    this.root.children('tbody').children('tr:odd').addClass('striped');
  } else if (this.root.is('dl')) {
	var element_dt = this.root.children('dt:odd');
	var element_dd = this.root.children('dd:odd');
	
    element_dt.addClass('striped');
    element_dd.addClass('striped');
	
	this.set_height = function(e) {
	  element_dt.each(function(index) {
	    element_dt.eq(index).height(element_dd.eq(index).height());
	  });
	}
	
	$(window).load(this.set_height);
  }
  
  return this;
}

function Side_navi() {
  var self = this;

  this.top_tier = this.root.children();
  this.top_parents = this.top_tier.children('ul').parent().not('.active').addClass('parent');
  
  this.top_parents.prepend('<img src="/images/global/icons/side_nav_plus.png" class="plus" alt=" " />');
  this.top_parents.prepend('<img src="/images/global/icons/side_nav_minus.png" class="minus" alt=" " />');
  
  this.start_up = function() {
    self.top_parents.children('img').bind('click', self.side_navi_expand);
  }
  
  this.side_navi_expand = function(e) {
    var me = $(e.currentTarget);
    if (me.parent().hasClass('active')) {
      me.parent().removeClass('active');
      me.siblings('a').removeClass('active');
    } else {
      me.parent().addClass('active');
      me.siblings('a').addClass('active parent');
    }
  }

  return this;
}


function Designer_expander() {
  var self = this;
  
  this.expander = this.root.find('a.expander');
  this.side_extender = this.root.parent().siblings('#sidebar').children('#side_extender');
  this.body = this.root.parent().parent('#body');
  this.expanded = false;
  this.old_side_height = 0;
  
  this.start_up = function() {
    $(window).bind('load', self.get_side_height);
    self.full_height = this.root.height('auto').outerHeight();
    self.root.height(20);
    self.expander.bind('click', self.expander_action);
  }
  this.get_side_height = function() {
	self.old_side_height = self.body.outerHeight() - self.side_extender.position().top;
  }
  
  this.expander_action = function() {
    var new_height = self.expanded ? 20 : self.full_height;
    var new_action = self.expanded ? ' [ click to expand ] ' : ' [ click to collapse ] ';
	
    self.expanded = !self.expanded;
    self.sketcher.draw(self.root, { height : new_height }, function(){self.expander.html(new_action)});
	
	if(self.expanded == false){
		self.sketcher.draw(self.side_extender, { height : self.old_side_height });
	}else{
		self.sketcher.draw(self.side_extender, { height : self.side_extender.height() + new_height});
	}
  }
  
  return this;
}

function Designer_grid_fixer() {
  var self = this;
  var first_column = 3
  var last_column = 3;
  var designer_titles
  var cssObj = {
    'padding-left' : '0px',
	'margin-left' : '30px'}
  
  for(var i=0; i<this.root.length; ++i) {
    designer_titles = this.root.eq(i).find('a.designer');
	
	for(var j=0; j<designer_titles.length; ++j) {
	
		if((j)%first_column == 0) {
			designer_titles.eq(j).css(cssObj);
		}
	
		if((j+1)%last_column == 0) {
			designer_titles.eq(j).css('border', 'none');
		}
		
	}
  } 

  return this;
}

function Popin_pager() {
  var self = this;
  this.current_popin = null;
  this.url = this.root.attr('href');
  
  this.start_up = function() {
    self.root.bind('click', self.get_content);
  }
  
  this.popin_whipup = function(html) {
    var popin = new Plain_Popin_view();
    popin.view.popin_content += '<div class="deskman">';
    popin.view.popin_content += html;
    popin.view.popin_content += '</div>';
    self.current_popin = new Popin(popin);
    self.current_popin.plugin_popin($('#jax_container'));
  }
  
  this.get_content = function(e) {
    e.preventDefault();
    var clicky = $(e.target);
    if (clicky.is(":not(a)")) {
      clicky = clicky.parent("a");
    }
    if (clicky.is("a")) {
      $.ajax({
        url: clicky.attr("href"),
        type: "GET",
        async: false,
        success: self.popin_whipup
      });
    }
  }
  
  return this;
}

function Tag_tips(classy_tipper, position) {
  var self = this;
  this.tippers = this.root.children();
  this.jax_space = $('#jax_container');
  this.tip_class_name = classy_tipper;
  this.tip_position = position;
  this.start_up = function() {
    self.tippers.bind('mouseenter', self.get_tip);
    self.tippers.bind('mouseleave', self.remove_tip);
  }
  
  this.get_tip = function(e) {
    e.preventDefault();
    e.stopPropagation()
    var me = $(e.currentTarget);
    me.data('tip',  $('<div class="tooltip"><span>' + me.attr('title') + '</span></div>').appendTo(self.jax_space));
    me.removeAttr('title');
    me.data('tip').bind('mouseenter', function() {return false});
    me.data('tip').addClass(self.tip_class_name).addClass(self.tip_position).css({
      top: me.offset().top + ( self.tip_position == 'bottom' ? me.outerHeight() : -me.data('tip').outerHeight() ), 
      left: me.offset().left -  (me.data('tip').outerWidth() / 2) + 20
    })
    self.sketcher.draw(me.data('tip'), {opacity : .8});
    return false;
  }

  this.remove_tip = function(e) {
    var me = $(e.currentTarget);
    me.attr('title', me.data('tip').children('span').html());
    self.sketcher.draw(me.data('tip'));
  }

  
  return this;
}

function Cart_helper_adder() {
  var self = this;
  
  this.quantity_field = this.root.find('form.quantity input');
  this.quantity_post_value = this.root.find('div.functions form:first input[name="item[quantity]"]');
  this.current_value = this.quantity_field.val();
  
  this.start_up = function() {
    self.quantity_field.bind('keyup', self.osmosis_form);
  }
  
  this.osmosis_form = function(e) {
    self.current_value = self.quantity_field.val();
    self.quantity_post_value.val(self.current_value);
  }
  
  return this;
}

function Gift_card_jaxer() {
  var self = this;
  this.gc_action = this.root.find('button');
  
  this.start_up = function() {
    self.gc_action.bind('click', self.send_gc)
  }
  
  this.process_gc = function(data) {
    location.reload();
  }
  
  this.send_gc = function(e) {
    e.preventDefault();
    $.ajax({
      data: { code : self.root.children('input').val() },
      url : '/cart/claim',
      type : 'POST',
      success : self.process_gc
    });
    return false;
  }
  
  return this;
}

function Remove_shipping_graphic_hack() {
  var self = this;
  this.root.parent().css({marginTop : 0}).siblings('img.free_shipping').remove();
  return this;
}

function Swatcher() {
  var self = this;
  this.swatches = this.root;
  this.large_swatch = this.root.find('img.larger');
  this.jax_space = $('#jax_container');
  
  this.swatch_box = function(swatch) {
    var swatch_html = '<div class="swatch_up">';
    swatch_html += '<img class="closer" src="/images/global/icons/small_close.png" alt="close" />';
    swatch_html += '<img class="larger" src="' + swatch.attr('src') + '" alt="' + swatch.attr('alt') + '" />';
    swatch_html += '<span>' + swatch.parent().attr('title') + '</span>';
    swatch_html += '</div>';
    return swatch_html;
  }
  
  this.start_up = function() {
    self.swatches.bind('click', self.swatch_plug_in)
  }
  
  this.swatch_plug_in = function(e) {
    var me = $(e.currentTarget);
    self.jax_space.append(self.swatch_box(me.children('img.larger')));
    var swatch_view = self.jax_space.children(':last');
    swatch_view.css({
      left: me.offset().left - (swatch_view.outerWidth() - me.outerWidth()) /2,
      top: me.offset().top + 20,
      visibility: 'visible'
    });
    swatch_view.children('img.closer').bind('click', self.close_swatch);
  }
  
  this.close_swatch = function(e) {
    self.sketcher.draw($(e.currentTarget).parent());
  }

  return this
}

function Related_extender() {
  var self = this;
  this.wind = $(window);
  this.orig_width = self.root.width();
  
  this.start_up = function() {
    self.wind.bind('resize', self.resizer);
    self.wind.trigger('resize');
    self.root.find('img.headline_ribbon').bind('click', self.ribbon_click)
  }
  
  this.ribbon_click = function(e) {
    document.location = self.root.find('div.product').eq(0).children('a.main_link').attr('href');
  }
  
  this.resizer = function() {
    self.sized_width = self.wind.width() - 272;
    self.root.css({
      marginLeft : -( self.sized_width - self.orig_width ) / 2 + 1,
      width : self.sized_width - 5
    });
  }
  
  return this;
}

function Home_brandnew_tag_add() {
  var self = this;
  this.root.append('<img src="http://fawnandforest.copiousdev.com/system/uploads/Client_assets/sale_flags/brand_new_big.png" class="flag" alt="brand new"/>')
  
  return this;
}

function Blog_post_relatedproducts_expander() {
  var self = this;
  this.expander_link = this.root.children('p').children('a');
  this.product_grid = this.root.children('div.grid');
  this.expanded = false;

  this.start_up = function() {
    self.expander_link.bind('click', self.expand_product_grid);
  }
  
  this.expand_product_grid = function(e) {
    if (self.expanded) {
      self.sketcher.draw(self.product_grid, {opacity : .1})
      self.sketcher.draw(self.root, {height : 20})
    } else {
      self.sketcher.draw(self.product_grid, {opacity : 1})
      self.sketcher.draw(self.root, {height : self.product_grid.outerHeight(true)})
    }
    self.expanded = !self.expanded;
  }
  return this;
}

function Content_height_setter() {
  var self = this;
  this.basin_first = this.root.children('.first');
  this.column_left = this.basin_first.children('.left');

  this.start_up = function() {
    $(window).load(function() {
      self.set_height();
	});  
  } 
  
  this.set_height = function() {
	var total_height = self.basin_first.height() - 10;
	  
	self.column_left.height(total_height);
  } 
  
  return this;
}

function Bundle_price_setter() {
  var self = this;
  var shipping_height = 20;
  
  this.bundle_item = this.root;
  this.chooser = this.root.children('.chooser');
  this.checkbox = this.chooser.children('.add_to_bundle').find('.checkbox');
  this.selectbox = this.chooser.children('.options').find('select');
  this.options = this.selectbox.children('option');
  this.warning = this.chooser.children('.price').find('.product_warning');
  
  this.start_up = function()
  {
    $(window).load(function() {
	  self.chooser.each(function() {
	    element = $(this);
		
	    var product_info = element.siblings('.product_info');
		var price = element.children('.price');
		var add_to_bundle = element.children('.add_to_bundle');
		
		var chooserHeight = element.children('.options').height() +
							element.children('.availability').height() +
							add_to_bundle.height() +
							shipping_height;
		
		price.height(product_info.height() - chooserHeight);
	  });
	});
	
	self.checkbox.bind('click', self.check_options)
	self.selectbox.bind('click', self.remove_warning);
  }
  
  this.check_options = function(e)
  {
	var $target = $(e.target);
	var drop_down = $target.parent().parent().parent().children('.options').children('select');
	var warning = $target.parent().parent().parent().children('.price').children('.product_warning');
	
	if ($target.is(':checked')) {
	  for(var i=0; i < drop_down.children('option').length; i++)
	  {	
		if(drop_down.children('option').eq(i).selectedIndex == 0)
		{
		  drop_down.addClass('required');
		}
	  }
	  warning.addClass('required');
	}else{
	  if(drop_down.hasClass('required'))
	  {
	    drop_down.removeClass('required');
	  }
	  if(warning.hasClass('required'))
	  {
	    warning.removeClass('required');
	  }
	}
	/*
	if (self.product_id.val() == "") {
      self.options_yet_selected();
      return false;
	  
	  this.options_yet_selected = function() {
    for (var i = 0; i < self.product_options.length; i++) {
      if (self.product_options[i].selectedIndex == 0) {
        self.product_options.eq(i).addClass('required');
      }
    }
    self.product_warning.addClass('required')
  }
    }
	*/
  }
  
  this.remove_warning = function(e)
  {
	var select = $(e.currentTarget);
	var warning = select.parent().siblings('.price').children('.product_warning');
	
	if(select.children('option:selected').val() != "")
	{
		if(warning.hasClass('required'))
		{
			warning.removeClass('required');
		}
	}else{
		warning.addClass('required');
	}
  }
  
  this.options_warning = function()
  {
	for(var i=0; i<self.selectbox.length; i++)
	{
	  if(self.selectbox[i].selectedIndex == 0)
	  {
	    self.selectbox.eq(i).addClass('required');
	  }
	}
	
	self.warning.addClass('required');
  }
  
  return this;
}
function Disable_bundle_options() {
  var self = this;
  this.checkbox = this.root.children('.add_to_bundle').find('.checkbox');
  this.drop_down = this.root.children('.options').find('select');
  
  this.start_up = function() {
    self.drop_down.attr('disabled', 'disabled');
	self.checkbox.bind('click', self.on_checkbox_click);
  }
  
  this.on_checkbox_click = function(e) {
    var $target = $(e.target);
	var drop_down = $target.parent().parent().parent().children('.options').children('select');
	
    if ($target.is(':checked')) {
	  drop_down.attr('disabled', '');
	}else{
	  drop_down.attr('disabled', 'disabled');
	  drop_down.children('option').eq(0).attr('selected', 'selected');
	}
	
  }
  
  return this;
}