  'use strict';

  var pluginName = 'insight',
      defaults = {
        fn: null,
        classIn:      'insight',
        classAbove:   'insight-above',
        classBelow:   'insight-below',
        classLeft:    'insight-left',
        classRight:   'insight-right',
        container:    $(window),
      };

  function InSight(element, options) {
    this.el = element;
    this.$el = $(this.el);
    this.options = $.extend({}, defaults, options);
    this._defaults = defaults;
    this._name = pluginName;
    this.init();
  }

  InSight.prototype = {

    init: function() {
      this.handler = this._handler.bind(this);
      $(window)
        .off('DOMContentLoaded load resize', this.handler)
        .on('DOMContentLoaded load resize', this.handler);
      this.options.container
        .off('scroll', this.handler)
        .on('scroll', this.handler)
        .trigger('scroll');
    },
    destroy: function() {
      $(window)
        .off('DOMContentLoaded load resize', this.handler);
      this.options.container
        .off('scroll', this.handler);
      this.$el.removeData(pluginName);
    },
    _handler: function(e, rect, wWidth, wHeight, insight, position) {
      try {
        rect = this.el.getBoundingClientRect();
        wWidth = this.options.container.width();
        wHeight = this.options.container.height();
        insight = rect.top < wHeight &&
                  rect.bottom > 0 &&
                  rect.left < wWidth &&
                  rect.right > 0;
        position = {
          above: rect.top < 0 && rect.bottom <= 0,
          left: rect.left < 0 && rect.right <= 0,
          right: rect.left >= wWidth && rect.right > wWidth,
          below: rect.top >= wHeight && rect.bottom > wHeight,
        };

        if (insight) {
          this.$el.addClass(this.options.classIn);
        }

        if (position.above) {
          this.$el.addClass(this.options.classAbove);
        }
        else {
          this.$el.removeClass(this.options.classAbove);
        }

        if (position.below) {
          this.$el.addClass(this.options.classBelow);
        }
        else {
          this.$el.removeClass(this.options.classBelow);
        }

        if (position.left) {
          this.$el.addClass(this.options.classLeft);
        }
        else {
          this.$el.removeClass(this.options.classLeft);
        }

        if (position.right) {
          this.$el.addClass(this.options.classRight);
        }
        else {
          this.$el.removeClass(this.options.classRight);
        }
      }
      catch(e) {}
      this.options.fn && this.options.fn.apply(this.el, [{
        target: this.el,
        insight: insight,
        position: position,
        rect: rect,
      }]);
    }
  };

  $.fn[pluginName] = function(options) {
    return this.each(function() {

      var $el = $(this);
      var inst = $el.data(pluginName);

      if(!inst) {
        inst = new InSight(this, options);
        $el.data(pluginName, inst);
      }

      else if (options === 'destroy') {
        inst.destroy();
      }

    });
  };

@@ -55,24 +55,45 @@
 efaults = %7B%0A
+        fraction: 0,%0A
         fn: 
@@ -98,16 +98,16 @@
 : null,%0A
-
         
@@ -643,24 +643,104 @@
 bind(this);%0A
+      this.options.fraction = Math.max(Math.min(+this.options.fraction, 1), 0);%0A
       $(wind
@@ -1447,159 +1447,8 @@
 ();%0A
-        insight = rect.top %3C wHeight &&%0A                  rect.bottom %3E 0 &&%0A                  rect.left %3C wWidth &&%0A                  rect.right %3E 0;%0A
     
@@ -1685,24 +1685,24 @@
  %3E wHeight,%0A
-
         %7D;%0A%0A
@@ -1701,16 +1701,875 @@
     %7D;%0A%0A
+        if (this.options.fraction) %7B%0A          var heightFraction = Math.min(rect.height, wHeight) * this.options.fraction;%0A          var widthFraction = Math.min(rect.width, wWidth) * this.options.fraction;%0A          insight = (%0A                      (rect.top %3C= wHeight - heightFraction && rect.bottom %3E 0) %7C%7C%0A                      (rect.top %3C wHeight && rect.bottom %3E= heightFraction && rect.bottom %3C= wHeight)%0A                    ) &&%0A                    (%0A                      (rect.left %3C= wWidth - widthFraction && rect.right %3E 0) %7C%7C%0A                      (rect.left %3C wWidth && rect.right %3E= widthFraction && rect.right %3C= wWidth)%0A                    );%0A        %7D%0A        else %7B%0A          insight = rect.top %3C wHeight &&%0A                    rect.bottom %3E 0 &&%0A                    rect.left %3C wWidth &&%0A                    rect.right %3E 0;%0A        %7D%0A%0A
         

add option to specify a fraction that must be visible before adding insight class