var fixto=function(t,i,e){function o(i,e,o){this.child=i,this._$child=t(i),this.parent=e,this._replacer=new h.MimicNode(i),this._ghostNode=this._replacer.replacer,this.options=t.extend({className:"fixto-fixed"},o),this.options.mind&&(this._$mind=t(this.options.mind)),this.options.zIndex&&(this.child.style.zIndex=this.options.zIndex),this._saveStyles(),this._saveViewportHeight(),this._proxied_onscroll=this._bind(this._onscroll,this),this._proxied_onresize=this._bind(this._onresize,this),this.start()}var n,s=function(){var t={getAll:function(t){return e.defaultView.getComputedStyle(t)},get:function(t,i){return this.getAll(t)[i]},toFloat:function(t){return parseFloat(t,10)||0},getFloat:function(t,i){return this.toFloat(this.get(t,i))},_getAllCurrentStyle:function(t){return t.currentStyle}};return e.documentElement.currentStyle&&(t.getAll=t._getAllCurrentStyle),t}(),h=function(){function i(t){this.element=t,this.replacer=e.createElement("div"),this.replacer.style.visibility="hidden",this.hide(),t.parentNode.insertBefore(this.replacer,t)}i.prototype={replace:function(){var t=this.replacer.style,i=s.getAll(this.element);t.width=this._width(),t.height=this._height(),t.marginTop=i.marginTop,t.marginBottom=i.marginBottom,t.marginLeft=i.marginLeft,t.marginRight=i.marginRight,t.cssFloat=i.cssFloat,t.styleFloat=i.styleFloat,t.position=i.position,t.top=i.top,t.bottom=i.bottom,t.display=i.display},hide:function(){this.replacer.style.display="none"},_width:function(){return this.element.getBoundingClientRect().width+"px"},_widthOffset:function(){return this.element.offsetWidth+"px"},_height:function(){return this.element.getBoundingClientRect().height+"px"},_heightOffset:function(){return this.element.offsetHeight+"px"},destroy:function(){t(this.replacer).remove();for(var i in this)this.hasOwnProperty(i)&&(this[i]=null)}};var o=e.documentElement.getBoundingClientRect();return o.width||(i.prototype._width=i.prototype._widthOffset,i.prototype._height=i.prototype._heightOffset),{MimicNode:i,computedStyle:s}}(),r="Microsoft Internet Explorer"===navigator.appName;r&&(n=parseFloat(navigator.appVersion.split("MSIE")[1])),o.prototype={_bind:function(t,i){return function(){return t.call(i)}},_toresize:8===n?e.documentElement:i,_mindtop:function(){var i=0;return this._$mind&&t(this._$mind).each(function(){i+=t(this).outerHeight(!0)}),i},_onscroll:function(){if(this._scrollTop=e.documentElement.scrollTop||e.body.scrollTop,this._parentBottom=this.parent.offsetHeight+this._fullOffset("offsetTop",this.parent)-s.getFloat(this.parent,"paddingBottom"),this.fixed){if(this._scrollTop>this._parentBottom||this._scrollTopthis._fullOffset("offsetTop",this.child)-s.getFloat(this.child,"marginTop")-this._mindtop()&&this._viewportHeight>this.child.offsetHeight+s.getFloat(this.child,"marginTop")+s.getFloat(this.child,"marginBottom")&&(this._fix(),this._adjust())},_adjust:function(){var t=this._parentBottom-this._scrollTop-(this.child.offsetHeight+s.getFloat(this.child,"marginTop")+s.getFloat(this.child,"marginBottom")+this._mindtop()),i=this._mindtop();0>t?this.child.style.top=t+i+"px":this.child.style.top=0+i+"px"},_fullOffset:function(t,i){for(var e=i[t];null!==i.offsetParent;)i=i.offsetParent,e+=i[t];return e},_fix:function(){var t=this.child,i=t.style;if(this._saveStyles(),e.documentElement.currentStyle){var o=s.getAll(t);i.left=this._fullOffset("offsetLeft",t)-s.getFloat(t,"marginLeft")+"px",i.width=t.offsetWidth-(s.toFloat(o.paddingLeft)+s.toFloat(o.paddingRight)+s.toFloat(o.borderLeftWidth)+s.toFloat(o.borderRightWidth))+"px"}else i.width=s.get(t,"width"),i.left=t.getBoundingClientRect().left-s.getFloat(t,"marginLeft")+"px";this._replacer.replace(),i.position="fixed",i.top=this._mindtop()+"px",this._$child.addClass(this.options.className),this.fixed=!0},_unfix:function(){var t=this.child.style;this._replacer.hide(),t.position=this._childOriginalPosition,t.top=this._childOriginalTop,t.width=this._childOriginalWidth,t.left=this._childOriginalLeft,this._$child.removeClass(this.options.className),this.fixed=!1},_saveStyles:function(){var t=this.child.style;this._childOriginalPosition=t.position,this._childOriginalTop=t.top,this._childOriginalWidth=t.width,this._childOriginalLeft=t.left},_onresize:function(){this._saveViewportHeight(),this._unfix(),this._onscroll()},_saveViewportHeight:function(){this._viewportHeight=i.innerHeight||e.documentElement.clientHeight},stop:function(){this._unfix(),t(i).unbind("scroll",this._proxied_onscroll),t(this._toresize).unbind("resize",this._proxied_onresize),this._running=!1},start:function(){this._running||(this._onscroll(),t(i).bind("scroll",this._proxied_onscroll),t(this._toresize).bind("resize",this._proxied_onresize),this._running=!0)},destroy:function(){this.stop(),this._$child.removeData("fixto-instance"),this._replacer.destroy();for(var t in this)this.hasOwnProperty(t)&&(this[t]=null)}};var l=function(t,i,e){return new o(t,i,e)},a=!!("ontouchstart"in i);return(a||8>n)&&(l=function(){return"not supported"}),t.fn.fixTo=function(i,e){var o=t(i),n=0;return this.each(function(){var s=t(this).data("fixto-instance");if(s){var h=i;s[h].call(s)}else t(this).data("fixto-instance",l(this,o[n],e));n++})},{FixToContainer:o,fixTo:l,computedStyle:s,mimicNode:h}}(window.jQuery,window,document);