(function($){
  $.fn.reorganize_horizontally = function(total_rows, should_move){
    var items = this.children();
    this.width(items.first().width() * Math.round((items.size() / total_rows)));
    this.height(items.first().height() * total_rows);
    if(should_move) move_slideable(this.selector, 40, true);
    return this;
  };
  
  $.fn.hover_slide = function(){
    var MAX_TIME_TO_ANIMATE = 8000;
    var container = this;
    var selector = this.selector;
    if(container.children().size() > 0){
      container.after("<div class='slider-hover-previous-wrapper'><a class='slider-hover-previous' href='javascript:void(0)'>Previous</a></div>");
      container.after("<div class='slider-hover-next-wrapper'><a class='slider-hover-next' href='javascript:void(0)'>Next</a></div>");

      $(".slider-hover-previous, .slider-hover-next").click(function(e) {
        e.preventDefault();
      });
      $(".slider-hover-previous").hover(
        function() {
          // Faster if closer to the end (ie, the front of the list) - make it a consistent speed no matter where it is
          var time_to_move = (Math.abs(get_slideable_percent_moved(selector)) / 100) * MAX_TIME_TO_ANIMATE;
          container.animate({left: 0}, time_to_move);
        },
        function() {
          container.stop();
          move_slider_to_container_proportion(selector);
        }
      );    
      $(".slider-hover-next").hover(
        function() {
          var total_width = get_slideable_total_width(selector);
          var left_value = -total_width;
          var time_to_move = ((100 - get_slideable_percent_moved(selector)) / 100) * MAX_TIME_TO_ANIMATE;
          container.animate({left: left_value}, time_to_move);                                 
        },
        function() {
          container.stop();
          move_slider_to_container_proportion(selector);
        }
      );
    }
    return this;
  };
  
  
  $.fn.do_the_hammer_dance = function(){
    var object = this;
    var next = object.next();
    object.fadeIn(1000);
    return this;
  };
})(jQuery);

/* jQuery.function_name = function(){}; */

jQuery.adjustContentHeight = function(){
  var content = $('#content');
  //var kids=$(content).children();
  //var height = $(content).children().height() - parseInt(content.css('padding-top'), 10) - parseInt(content.css('padding-bottom'), 10);
  var height = $(content).height() - parseInt(content.css('padding-top'), 10) - parseInt(content.css('padding-bottom'), 10);
  content.height(height);
};

jQuery(document).ready(function(){
  // on load
  
  var MIN_IMAGES_TO_SHOW_SCROLL = 12;
  // Show side scroll buttons for clients pages (/*/clients/) and work category pages (/*/work/*/)
  /*if (
       ($('.clients-page ul.image-listing').size() > 0) && ($('.clients-page ul.image-listing li').size() > MIN_IMAGES_TO_SHOW_SCROLL) ||
       ($('ul.work-category-listing').size() > 0) && ($('ul.work-category-listing li').size() > MIN_IMAGES_TO_SHOW_SCROLL)
    ) {
    $('ul.image-listing').reorganize_horizontally(2, true).hover_slide().fadeIn('1000');
  }
  if($('ul.client-work').size() > 0) {
    $('ul.client-work').reorganize_horizontally(2, false).fadeIn('1000');
  }*/
  $.adjustContentHeight();
  $('#team-profiles').hover_slide().fadeIn('1000');
  $('#nav a, a.animated').live('click', function(){
    $('#content').fadeOut('slow');
    $('body > img.bg').fadeOut('slow');
  });
    
});

