(function(){
  
var ns = 'FixedElement',
    default_options = {
      lock: 'xy'
    };

var fe = window[ns] = function( element, options ) {
  
  this.options = {};
  jQuery.extend( this.options, default_options, options );
  this.lock = this.options.lock;
  this.x = this.options.x || 0;
  this.y = this.options.y || 0;
  this.root = $(element);
  
  this.init();
  this.observe();
  $(window).trigger('resize');

}

fe.prototype = {
  
  init: function () {
    this.root.css({
      position: $.browser.msie ? 'absolute' : 'fixed'
    });
    
    if ( $.browser.msie ) {
      this.root.css( 'bottom', 'auto' );
    }
  },
  
  observe: function () {
    var func = $.browser.msie ? this.repositionIE : this.reposition;
    $(window).resize( $.proxy( func, this ) );
    $(document).scroll( $.proxy( func, this ) );
  },
  
  reposition: function ( event ) {
    var px = 'px',
        x = this.x,
        y = this.y;
    
    if ( ! /x/.test(this.lock) ) {
      x = - $(document).scrollLeft();
    }
    
    if ( ! /y/.test(this.lock) ) {
      y = - $(document).scrollTop();
    }
    
    this.root.css( {
      'left':   x + px,
      'top':    y + px
    } );
  },
  
  repositionIE: function ( event ) {
    var px = 'px',
        x = this.x,
        y = this.y;
    
    if ( /x/.test(this.lock) ) {
      x += $(document).scrollLeft();
    }
    
    if ( /y/.test(this.lock) ) {
      y += $(document).scrollTop();
    }

    this.root.css( {
      'left':   x + px,
      'top':    y + px
    } );
  }
  
};


})();
