(function($){$.fn.floatHeader=function(config){config=$.extend({fadeOut:250,faceIn:250,floatClass:'floatHeader'},config);return this.each(function(){var self=$(this);var table=self.clone();table.empty();self.floatBox=$('<div class="'+config.floatClass+'"style="display:none"></div>');self.floatBox.append(table);self.floatBoxVisible=false;self.IEWindowWidth=document.documentElement.clientWidth;self.IEWindowHeight=document.documentElement.clientHeight;createHeader(table,self,config);$(window).scroll(function(){var headerOutsideScreen=isHeaderOutsideScreen(self);if(self.floatBoxVisible&&!headerOutsideScreen){var offset=self.offset();self.floatBox.css('position','absolute');self.floatBox.css('top',offset.top);self.floatBox.css('left',offset.left);self.floatBoxVisible=false;if(config.cbFadeOut){config.cbFadeOut(self.floatBox)}else{self.floatBox.fadeOut(config.fadeOut)}}else if(headerOutsideScreen){self.floatBoxVisible=true;if(config.cbFadeIn){config.cbFadeIn(self.floatBox)}else{self.floatBox.fadeIn(config.faceIn)}}if(self.floatBoxVisible){if($.browser.msie&&$.browser.version=="6.0"){self.floatBox.css({'position':'absolute','top':$(window).scrollTop(),'left':self.offset().left})}else{self.floatBox.css({'position':'fixed','top':0,'left':self.offset().left-$(window).scrollLeft()})}}});if($.browser.msie&&$.browser.version<=7){$(window).resize(function(){if(self.IEWindowWidth!=document.documentElement.clientWidth||self.IEWindowHeight!=document.documentElement.clientHeight){self.IEWindowWidth=document.documentElement.clientWidth;self.IEWindowHeight=document.documentElement.clientHeight;table.empty();createHeader(table,self,config)}})}else{$(window).resize(function(){table.empty();createHeader(table,self,config)})}$(self).after(self.floatBox);if($.browser.safari){$(window).one('scroll',function(){table.empty();createHeader(table,self,config)})}})};function createHeader(target,template,config){target.width(template.outerWidth());if(template.children('thead').length===0){return}var items=template.children('thead').eq(0).children();items.each(function(){var row=$(this);var floatRow=row.clone();floatRow.empty();row.children().each(function(){var cell=$(this);var floatCell=cell.clone();if($.browser.msie){floatCell.css('width',cell.outerWidth());floatCell.css('padding','0 0 0 0')}else{floatCell.css('width',cell.width())}floatRow.append(floatCell)});target.append(floatRow)})}function isHeaderOutsideScreen(element){var top=$(window).scrollTop();var y0=$(element).offset().top;return y0<=top&&top<=y0+$(element).height()}})(jQuery);