/* ScrollOut: Easily Scroll to an Anchor for Jquery v 1.4
   Released under the MIT license by Tyler Montgomery July 2010
   plugin-er-ized from code presented here: http://beski.wordpress.com/2009/04/21/scroll-effect-with-local-anchors-jquery/
*/

(function($) {

  var ScrollOut = function() {};

  $.extend(ScrollOut.prototype, {
    scroll: function(anchor){
      scroll_to = $(anchor).offset().top - this.options.offset;
      $('html, body').animate({scrollTop: scroll_to}, this.options.speed);  
    }

  });

  $.fn.scrollOut = function(opts, callback){
    $.scrollOut(this.selector, opts, callback);
    return this;
  };

  $.scrollOut = function(anchor, opts, callback) {
    var scrollOut = $.scrollOut.instance;
    if(!scrollOut){ 
      scrollOut = $.scrollOut.instance = new ScrollOut(); 
    }
    scrollOut.options = $.extend({}, $.scrollOut.defaults, opts || {});
    scrollOut.scroll(anchor);
    if(callback){
      setTimeout(function(){callback.apply();}, scrollOut.options.speed + 50);
    }
    return scrollOut;
  };


  $.scrollOut.defaults = {
    speed: 800,
    offset: 150// pixels from the top of the browser window to your anchor
  };

  function log() {
    if (window.console) {
      console.log.apply(console, arguments);
    }
  }

})(jQuery);
