var StaticScroller=new Class({Implements:Options,options:{offset:10,scrollElement:document},initialize:function(element,options){this.setOptions(options);this.element=document.id(element);this.scrollElement=document.id(this.options.scrollElement);this.originalPosition=this.element.getPosition();this.bound={scroll:this.scroll.bind(this),resize:this.resize.bind(this)};this.attachWindow();this.checkHeight();},attachScroll:function(){this.scrollElement.addEvent('scroll',this.bound.scroll);return this;},attachWindow:function(){window.addEvent('resize',this.bound.resize);return this;},detachScroll:function(){this.scrollElement.removeEvent('scroll',this.bound.scroll);return this;},detachWindow:function(){window.removeEvent('resize',this.bound.resize);return this;},checkHeight:function(){if(document.getSize().y<this.element.getSize().y){this.detachScroll().reset();}else{this.attachScroll().scroll();}
return this;},isPinned:function(){return(this.element.retrieve('pinned'));},scroll:function(){var collision=(this.scrollElement.getScroll().y>=this.originalPosition.y-this.options.offset);var isPinned=this.isPinned();if(collision){if(!isPinned){this.element.pin().setStyle('top',this.options.offset.toInt());};}else{if(isPinned)this.reset();};return this;},resize:function(){if(this.isPinned())this.reset();this.checkHeight();return this;},reset:function(){if(this.isPinned())this.element.unpin().setStyle('position','');}});(function(){var supportsPositionFixed=false;window.addEvent('domready',function(){var test=new Element('div').setStyles({position:'fixed',top:0,right:0}).inject(document.body);supportsPositionFixed=(test.offsetTop===0);test.dispose();});Element.implement({pin:function(enable){if(this.getStyle('display')=='none')return null;var p,scroll=window.getScroll();if(enable!==false){p=this.getPosition();if(!this.retrieve('pinned')){var pos={top:p.y-scroll.y,left:p.x-scroll.x};if(supportsPositionFixed){this.setStyle('position','fixed').setStyles(pos);}else{this.store('pinnedByJS',true);this.setStyles({position:'absolute',top:p.y,left:p.x}).addClass('isPinned');this.store('scrollFixer',(function(){if(this.retrieve('pinned'))
var scroll=window.getScroll();this.setStyles({top:pos.top.toInt()+scroll.y,left:pos.left.toInt()+scroll.x});}).bind(this));window.addEvent('scroll',this.retrieve('scrollFixer'));}
this.store('pinned',true);}}else{var op;if(!Browser.Engine.trident){var parent=this.getParent();op=(parent.getComputedStyle('position')!='static'?parent:parent.getOffsetParent());}
p=this.getPosition(op);this.store('pinned',false);var reposition;if(supportsPositionFixed&&!this.retrieve('pinnedByJS')){reposition={top:p.y+scroll.y,left:p.x+scroll.x};}else{this.store('pinnedByJS',false);window.removeEvent('scroll',this.retrieve('scrollFixer'));reposition={top:p.y,left:p.x};}
this.setStyles($merge(reposition,{position:'absolute'})).removeClass('isPinned');}
return this;},unpin:function(){return this.pin(false);},togglepin:function(){this.pin(!this.retrieve('pinned'));}});})();
