(function($){$.fn.floatHeader=function(config){config=$.extend({fadeOut:250,faceIn:250,forceClass:false,markerClass:'floating',floatClass:'floatHeader'},config);return this.each(function(){var self=$(this);var table=self.clone();table.children().remove();self.floatBox=$('<div class="'+config.floatClass+'"style="display:none"></div>');self.floatBox.append(table);createFloater(table,self,config);$(window).scroll(function(){if(self.floatBoxVisible){if(!showHeader(self)){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(showHeader(self)){self.floatBoxVisible=true;self.floatBox.css('position','fixed');if(config.cbFadeIn){config.cbFadeIn(self.floatBox);}else{self.floatBox.fadeIn(config.faceIn);}}}
if(self.floatBoxVisible){self.floatBox.css('top',0);self.floatBox.css('left',self.offset().left-$(window).scrollLeft());}});$(window).resize(function(){table.children().remove();createFloater(table,self,config);});$(self).after(self.floatBox);});};function createFloater(target,template,config){target.width(template.width());var items;if(!config.forceClass&&template.children('thead').length>0){items=template.children('thead').eq(0).children();}else{items=template.find('.'+config.markerClass);}
items.each(function(){var row=$(this);var floatRow=row.clone();floatRow.children().remove();row.children().each(function(){var cell=$(this);var floatCell=cell.clone();floatCell.css('width',cell.width());floatRow.append(floatCell);});target.append(floatRow);});}
function showHeader(element){var top=$(window).scrollTop();var y0=$(element).offset().top;return y0<=top&&top<=y0+$(element).height();}})(jQuery);