(function($) {
  $.fn.Stickify = function(settings) {
    
    settings = $.extend({
      contentContainer: ""
    }, settings);
    
    return this.each(function(){
      
      $this = $(this);

      var top = $this.offset().top - parseInt($this.css('marginTop').replace(/auto/,0));  

      $(window).scroll(function() {
        var y = parseInt($(this).scrollTop());
        
        if (y >= top) {
          // if so, add the fixed class
          $this.parent().addClass('fixed');
        
        } else if(y >= $(settings.contentContainer).outerHeight()){
          $this.parent().addClass('b-fixed');
        
        } else {
          // otherwise remove it
          $this.parent().removeClass('fixed');
        }
        
      });
      
      /*if(settings.contentContainer == ""){
        alert("Please provide your main content wrapper in settings.");
      }
      else{
        alert($(settings.contentContainer).outerHeight());
      }*/
      
    });
    
  }
  
})(jQuery);
