text: /*
   * File:        ColReorder.min.js
   * Version:     1.0.8
   * Author:      Allan Jardine (www.sprymedia.co.uk)
   * 
   * Copyright 2010-2012 Allan Jardine, all rights reserved.
   *
   * This source file is free software, under either the GPL v2 license or a
   * BSD (3 point) style license, as supplied with this software.
   * 
   * This source file is distributed in the hope that it will be useful, but 
   * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
   * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
   */
  
  (function(e,t,n){function r(e){for(var t=[],n=0,r=e.length;n<r;n++)t[e[n]]=n;return t}function i(e,t,n){t=e.splice(t,1)[0],e.splice(n,0,t)}function s(e,t,n){for(var r=[],i=0,s=e.childNodes.length;i<s;i++)1==e.childNodes[i].nodeType&&r.push(e.childNodes[i]);t=r[t],null!==n?e.insertBefore(t,r[n]):e.appendChild(t)}e.fn.dataTableExt.oApi.fnColReorder=function(t,n,o){var u,a,l,c,h=t.aoColumns.length,p;if(n!=o)if(0>n||n>=h)this.oApi._fnLog(t,1,"ColReorder 'from' index is out of bounds: "+n);else if(0>o||o>=h)this.oApi._fnLog(t,1,"ColReorder 'to' index is out of bounds: "+o);else{var d=[];u=0;for(a=h;u<a;u++)d[u]=u;i(d,n,o),d=r(d),u=0;for(a=t.aaSorting.length;u<a;u++)t.aaSorting[u][0]=d[t.aaSorting[u][0]];if(null!==t.aaSortingFixed){u=0;for(a=t.aaSortingFixed.length;u<a;u++)t.aaSortingFixed[u][0]=d[t.aaSortingFixed[u][0]]}u=0;for(a=h;u<a;u++){p=t.aoColumns[u],l=0;for(c=p.aDataSort.length;l<c;l++)p.aDataSort[l]=d[p.aDataSort[l]]}u=0;for(a=h;u<a;u++)p=t.aoColumns[u],"number"==typeof p.mData&&(p.mData=d[p.mData],p.fnGetData=t.oApi._fnGetObjectDataFn(p.mData),p.fnSetData=t.oApi._fnSetObjectDataFn(p.mData));if(t.aoColumns[n].bVisible){c=this.oApi._fnColumnIndexToVisible(t,n),p=null;for(u=o<n?o:o+1;null===p&&u<h;)p=this.oApi._fnColumnIndexToVisible(t,u),u++;l=t.nTHead.getElementsByTagName("tr"),u=0;for(a=l.length;u<a;u++)s(l[u],c,p);if(null!==t.nTFoot){l=t.nTFoot.getElementsByTagName("tr"),u=0;for(a=l.length;u<a;u++)s(l[u],c,p)}u=0;for(a=t.aoData.length;u<a;u++)null!==t.aoData[u].nTr&&s(t.aoData[u].nTr,c,p)}i(t.aoColumns,n,o),i(t.aoPreSearchCols,n,o),u=0;for(a=t.aoData.length;u<a;u++)e.isArray(t.aoData[u]._aData)&&i(t.aoData[u]._aData,n,o),i(t.aoData[u]._anHidden,n,o);u=0;for(a=t.aoHeader.length;u<a;u++)i(t.aoHeader[u],n,o);if(null!==t.aoFooter){u=0;for(a=t.aoFooter.length;u<a;u++)i(t.aoFooter[u],n,o)}u=0;for(a=h;u<a;u++)e(t.aoColumns[u].nTh).unbind("click"),this.oApi._fnSortAttachListener(t,t.aoColumns[u].nTh,u);e(t.oInstance).trigger("column-reorder",[t,{iFrom:n,iTo:o,aiInvertMapping:d}]),"undefined"!=typeof t.oInstance._oPluginFixedHeader&&t.oInstance._oPluginFixedHeader.fnUpdate()}},ColReorder=function(e,t){return(!this.CLASS||"ColReorder"!=this.CLASS)&&alert("Warning: ColReorder must be initialised with the keyword 'new'"),"undefined"==typeof t&&(t={}),this.s={dt:null,init:t,fixed:0,dropCallback:null,mouse:{startX:-1,startY:-1,offsetX:-1,offsetY:-1,target:-1,targetIndex:-1,fromIndex:-1},aoTargets:[]},this.dom={drag:null,pointer:null},this.s.dt=e.oInstance.fnSettings(),this._fnConstruct(),e.oApi._fnCallbackReg(e,"aoDestroyCallback",jQuery.proxy(this._fnDestroy,this),"ColReorder"),ColReorder.aoInstances.push(this),this},ColReorder.prototype={fnReset:function(){for(var e=[],t=0,n=this.s.dt.aoColumns.length;t<n;t++)e.push(this.s.dt.aoColumns[t]._ColReorder_iOrigCol);this._fnOrderColumns(e)},_fnConstruct:function(){var e=this,t,n;"undefined"!=typeof this.s.init.iFixedColumns&&(this.s.fixed=this.s.init.iFixedColumns),"undefined"!=typeof this.s.init.fnReorderCallback&&(this.s.dropCallback=this.s.init.fnReorderCallback),t=0;for(n=this.s.dt.aoColumns.length;t<n;t++)t>this.s.fixed-1&&this._fnMouseListener(t,this.s.dt.aoColumns[t].nTh),this.s.dt.aoColumns[t]._ColReorder_iOrigCol=t;this.s.dt.oApi._fnCallbackReg(this.s.dt,"aoStateSaveParams",function(t,n){e._fnStateSave.call(e,n)},"ColReorder_State");var i=null;"undefined"!=typeof this.s.init.aiOrder&&(i=this.s.init.aiOrder.slice()),this.s.dt.oLoadedState&&"undefined"!=typeof this.s.dt.oLoadedState.ColReorder&&this.s.dt.oLoadedState.ColReorder.length==this.s.dt.aoColumns.length&&(i=this.s.dt.oLoadedState.ColReorder);if(i)if(e.s.dt._bInitComplete)t=r(i),e._fnOrderColumns.call(e,t);else{var s=!1;this.s.dt.aoDrawCallback.push({fn:function(){if(!e.s.dt._bInitComplete&&!s){s=!0;var t=r(i);e._fnOrderColumns.call(e,t)}},sName:"ColReorder_Pre"})}},_fnOrderColumns:function(t){if(t.length!=this.s.dt.aoColumns.length)this.s.dt.oInstance.oApi._fnLog(this.s.dt,1,"ColReorder - array reorder does not match known number of columns. Skipping.");else{for(var n=0,r=t.length;n<r;n++){var s=e.inArray(n,t);n!=s&&(i(t,s,n),this.s.dt.oInstance.fnColReorder(s,n))}(""!==this.s.dt.oScroll.sX||""!==this.s.dt.oScroll.sY)&&this.s.dt.oInstance.fnAdjustColumnSizing(),this.s.dt.oInstance.oApi._fnSaveState(this.s.dt)}},_fnStateSave:function(t){var n,r,i,s=this.s.dt;for(n=0;n<t.aaSorting.length;n++)t.aaSorting[n][0]=s.aoColumns[t.aaSorting[n][0]]._ColReorder_iOrigCol;aSearchCopy=e.extend(!0,[],t.aoSearchCols),t.ColReorder=[],n=0;for(r=s.aoColumns.length;n<r;n++)i=s.aoColumns[n]._ColReorder_iOrigCol,t.aoSearchCols[i]=aSearchCopy[n],t.abVisCols[i]=s.aoColumns[n].bVisible,t.ColReorder.push(i)},_fnMouseListener:function(t,n){var r=this;e(n).bind("mousedown.ColReorder",function(e){e.preventDefault(),r._fnMouseDown.call(r,e,n)})},_fnMouseDown:function(t,r){var i=this,s=this.s.dt.aoColumns,o="TH"==t.target.nodeName?t.target:e(t.target).parents("TH")[0],o=e(o).offset();this.s.mouse.startX=t.pageX,this.s.mouse.startY=t.pageY,this.s.mouse.offsetX=t.pageX-o.left,this.s.mouse.offsetY=t.pageY-o.top,this.s.mouse.target=r,this.s.mouse.targetIndex=e("th",r.parentNode).index(r),this.s.mouse.fromIndex=this.s.dt.oInstance.oApi._fnVisibleToColumnIndex(this.s.dt,this.s.mouse.targetIndex),this.s.aoTargets.splice(0,this.s.aoTargets.length),this.s.aoTargets.push({x:e(this.s.dt.nTable).offset().left,to:0});for(var u=o=0,a=s.length;u<a;u++)u!=this.s.mouse.fromIndex&&o++,s[u].bVisible&&this.s.aoTargets.push({x:e(s[u].nTh).offset().left+e(s[u].nTh).outerWidth(),to:o});0!==this.s.fixed&&this.s.aoTargets.splice(0,this.s.fixed),e(n).bind("mousemove.ColReorder",function(e){i._fnMouseMove.call(i,e)}),e(n).bind("mouseup.ColReorder",function(e){i._fnMouseUp.call(i,e)})},_fnMouseMove:function(e){if(null===this.dom.drag){if(5>Math.pow(Math.pow(e.pageX-this.s.mouse.startX,2)+Math.pow(e.pageY-this.s.mouse.startY,2),.5))return;this._fnCreateDragNode()}this.dom.drag.style.left=e.pageX-this.s.mouse.offsetX+"px",this.dom.drag.style.top=e.pageY-this.s.mouse.offsetY+"px";for(var t=!1,n=1,r=this.s.aoTargets.length;n<r;n++)if(e.pageX<this.s.aoTargets[n-1].x+(this.s.aoTargets[n].x-this.s.aoTargets[n-1].x)/2){this.dom.pointer.style.left=this.s.aoTargets[n-1].x+"px",this.s.mouse.toIndex=this.s.aoTargets[n-1].to,t=!0;break}t||(this.dom.pointer.style.left=this.s.aoTargets[this.s.aoTargets.length-1].x+"px",this.s.mouse.toIndex=this.s.aoTargets[this.s.aoTargets.length-1].to)},_fnMouseUp:function(){e(n).unbind("mousemove.ColReorder"),e(n).unbind("mouseup.ColReorder"),null!==this.dom.drag&&(n.body.removeChild(this.dom.drag),n.body.removeChild(this.dom.pointer),this.dom.drag=null,this.dom.pointer=null,this.s.dt.oInstance.fnColReorder(this.s.mouse.fromIndex,this.s.mouse.toIndex),(""!==this.s.dt.oScroll.sX||""!==this.s.dt.oScroll.sY)&&this.s.dt.oInstance.fnAdjustColumnSizing(),null!==this.s.dropCallback&&this.s.dropCallback.call(this),this.s.dt.oInstance.oApi._fnSaveState(this.s.dt))},_fnCreateDragNode:function(){var t=this;this.dom.drag=e(this.s.dt.nTHead.parentNode).clone(!0)[0];for(this.dom.drag.className+=" DTCR_clonedTable";0<this.dom.drag.getElementsByTagName("caption").length;)this.dom.drag.removeChild(this.dom.drag.getElementsByTagName("caption")[0]);for(;0<this.dom.drag.getElementsByTagName("tbody").length;)this.dom.drag.removeChild(this.dom.drag.getElementsByTagName("tbody")[0]);for(;0<this.dom.drag.getElementsByTagName("tfoot").length;)this.dom.drag.removeChild(this.dom.drag.getElementsByTagName("tfoot")[0]);e("thead tr:eq(0)",this.dom.drag).each(function(){e("th",this).eq(t.s.mouse.targetIndex).siblings().remove()}),e("tr",this.dom.drag).height(e("tr:eq(0)",t.s.dt.nTHead).height()),e("thead tr:gt(0)",this.dom.drag).remove(),e("thead th:eq(0)",this.dom.drag).each(function(){this.style.width=e("th:eq("+t.s.mouse.targetIndex+")",t.s.dt.nTHead).width()+"px"}),this.dom.drag.style.position="absolute",this.dom.drag.style.top="0px",this.dom.drag.style.left="0px",this.dom.drag.style.width=e("th:eq("+t.s.mouse.targetIndex+")",t.s.dt.nTHead).outerWidth()+"px",this.dom.pointer=n.createElement("div"),this.dom.pointer.className="DTCR_pointer",this.dom.pointer.style.position="absolute",""===this.s.dt.oScroll.sX&&""===this.s.dt.oScroll.sY?(this.dom.pointer.style.top=e(this.s.dt.nTable).offset().top+"px",this.dom.pointer.style.height=e(this.s.dt.nTable).height()+"px"):(this.dom.pointer.style.top=e("div.dataTables_scroll",this.s.dt.nTableWrapper).offset().top+"px",this.dom.pointer.style.height=e("div.dataTables_scroll",this.s.dt.nTableWrapper).height()+"px"),n.body.appendChild(this.dom.pointer),n.body.appendChild(this.dom.drag)},_fnDestroy:function(){for(var t=0,n=ColReorder.aoInstances.length;t<n;t++)if(ColReorder.aoInstances[t]===this){ColReorder.aoInstances.splice(t,1);break}e(this.s.dt.nTHead).find("*").unbind(".ColReorder"),this.s=this.s.dt.oInstance._oPluginColReorder=null}},ColReorder.aoInstances=[],ColReorder.fnReset=function(e){for(var t=0,n=ColReorder.aoInstances.length;t<n;t++)ColReorder.aoInstances[t].s.dt.oInstance==e&&ColReorder.aoInstances[t].fnReset()},ColReorder.prototype.CLASS="ColReorder",ColReorder.VERSION="1.0.8",ColReorder.prototype.VERSION=ColReorder.VERSION,"function"==typeof e.fn.dataTable&&"function"==typeof e.fn.dataTableExt.fnVersionCheck&&e.fn.dataTableExt.fnVersionCheck("1.9.3")?e.fn.dataTableExt.aoFeatures.push({fnInit:function(e){var t=e.oInstance;return"undefined"==typeof t._oPluginColReorder?t._oPluginColReorder=new ColReorder(e,"undefined"!=typeof e.oInit.oColReorder?e.oInit.oColReorder:{}):t.oApi._fnLog(e,1,"ColReorder attempted to initialise twice. Ignoring second"),null},cFeature:"R",sFeature:"ColReorder"}):alert("Warning: ColReorder requires DataTables 1.9.3 or greater - www.datatables.net/download")})(jQuery,window,document);