
jQuery.fn.dataViewer = function(settings) {
	 settings = jQuery.extend({
			dataEaseFunc: "expoinout",			// type of easing animation for the data area
			dataEaseTime:100,					// amount of time to move from one page to the next
			menuEaseTime:500,					// amaount of time to move the pagination links
			containerWidth:740,					// width of the DataViewer container
			numDisplayPages:9,					// number of pagination links to display at any one time
			numDisplayItems:10,					// number of items (rows) to display on each page
			headerBackColor:"#6a7285",			// background color of the headers
			headerForeColor:"#FFF",				// fore color of the headers
			headerHoverBackColor:"#45526e",		// background color of the headers on the hover event
			evenRowBackColor:'#FFF',			// background color of the even-numbered rows in table content
			evenRowForeColor:'#222',			// fore color of the even-numbered rows in table content
			oddRowBackColor:'#EEE',				// background color of the odd-numbered rows in table content
			oddRowForeColor:'#222',				// fore color of the odd-numbered rows in table content
			menuBackColor:"#6a7285",			// background color of the pagination menu
			menuForeColor:"#FFF",				// fore color of the pagination menu
			menuBackHoverColor:"#F93",			// background color of the pagination links on the hover event
			menuSquareColor:"#BBB"				// border color of the pagination number links
  }, settings);
	return this.each(function(){
	
		// Assign the temporary container for the original table...
		var tempContainer = jQuery(this);

		// Add the DataViewer class to give the temporary table the atyles of our new table ( mainly to get our column widths)
		tempContainer.addClass("DataViewer");
		
		// The number of rows to display in a single panel
		var itemDisplayNumber = 2;
		
		// Get the table header contents, if there is a table header
		var tableHeader = (tempContainer.find("thead").html() != null) ? "<thead>" + tempContainer.find("thead").html() + "</thead>" : "";
		
		// Get the number of rows that are in the table body
		var tableRowCount = tempContainer.find("tbody").find("tr").size();
		
		// Initialize the varaible used to hold the new table header html
		var newTableHeader = "";
		
		// If there is a table header being used in the table...
		if ( tableHeader != "" )
		{
			// Get the number of header columns in the table header
			var tableHeaderCount = (tempContainer.find("thead").find("tr th").size());

			// Build the new table header for the above information, but include the entire table to gert the proper widths
			// and then set the display of the <tbody> to none to hide the table, but display the header...
			newTableHeader += "<div class='new-header'><table class='old-table'><thead><tr>";
			for (m = 0; m < tableHeaderCount; m++)
			{
				// Get the text of the old table header to populate the new table header
				var headerText = tempContainer.find("thead").find("tr th:eq(" + m + ")").text();
				
				
				// If the table header has the class "sortable" then assign it a class of "sort0"
				if (  tempContainer.find("thead").find("tr th:eq(" + m + ")").hasClass("sortable") )
				{ 
					// Remove the border-right from the last table header and add 2px to fill the empty space
					if ( m == tableHeaderCount-1 )
					{ 
						newTableHeader += "<th style='border-right:0px' class='sort0' rel='" + m + "'>" + headerText + "</th>"; 
					}
					else
					{ newTableHeader += "<th class='sort0' rel='" + m + "'>" + headerText + "</th>"; }
				}
				else
				{ 
					// Remove the border-right from the last table header and add 2px to fill the empty space
					if ( m == tableHeaderCount-1 )
					{ 
						newTableHeader += "<th style='border-right:0px' rel='" + m + "'>" + headerText + "</th>"; 
					}
					else
					{ newTableHeader += "<th rel='" + m + "'>" + headerText + "</th>"; }
				}
			}
			newTableHeader += "</tr></thead><tbody style='display:none;'>";

			// Variable used to the hold the number of table rows
			var rowCounter1 = 0;
			for (j = 0; j < 1; j++)
			{
				newTableHeader += ( rowCounter1 <= tableRowCount ) ? "<tr>" + tempContainer.find("tbody").find("tr:eq(" + rowCounter1 + ")").html() + "</tr>" : ""; 
				rowCounter1++;
			}
			newTableHeader += "</tbody></table></div>"	
		}

		// ================================== Contstruct the new table ================================== //
		// Variable used to the hold the number of table columns
		var rowCounter2 = 0;
		// Rebuild the table
		var newTableString = newTableHeader + "<div class='new-table-container-outer'><div class='overlay'><img src='Pagination/images/LoadingProgressBar.gif' /></div><div class='new-table-container-inner'><table class='new-table'>" + tableHeader + "<tbody>";
			for (j = 0; j < tableRowCount; j++)
			{
				if (j%2==0)
				{ newTableString += ( rowCounter2 <= tableRowCount ) ? "<tr id='TR_" + j + "' class='even-row'>" + tempContainer.find("tbody").find("tr:eq(" + rowCounter2 + ")").html() + "</tr>" : ""; }
				else
				{ newTableString += ( rowCounter2 <= tableRowCount ) ? "<tr id='TR_" + j + "' class='odd-row'>" + tempContainer.find("tbody").find("tr:eq(" + rowCounter2 + ")").html() + "</tr>" : ""; }
				rowCounter2++;
			}
		newTableString += "</tbody></table></div></div>"		

		// Add the new output before the current table
		tempContainer.before("<div class='DataViewer'>" + newTableString + "</div>");
		
		// Assign the container and parent of the container
		var _MasterContainer = jQuery(this).prev();

		// Assign the main content area
		var _ContentContainer = _MasterContainer.find(".new-table-container-outer");
		
		// Assign the height of the outer container
		if ( _ContentContainer.find("tbody tr").size() > settings.numDisplayItems )
		{ 
		    var _ContentContainerHeight = (settings.numDisplayItems * 31); 
		    // Set the height of the outer container only if there is more than 1 page
		    _ContentContainer.height(_ContentContainerHeight);
		}
		else
		{ 
		    var _ContentContainerHeight = (_ContentContainer.find("tbody tr").size() * 31); 
		 }

		// Set the position of the "Sorting" image...
		var overlayImage = _ContentContainer.find(".overlay");
		overlayImage.css("top",((_ContentContainerHeight/2)-(overlayImage.height()/2)) + "px");
		overlayImage.css("left",((settings.containerWidth/2)-(65/2)) + "px");
	
		// Assign the number of panels in our container
		var _PageCount = Math.ceil(_ContentContainer.find("tbody tr").size() / settings.numDisplayItems);

		// Set the panel  global varaible to the first panel number
		var _CurrentPanel = 1;
		
		// Get the max number of pagination numbers to display at once, unless the panel count is less than the max count, then set the page count to the panel count
		var _PaginationCount = ( _PageCount < settings.numDisplayPages ) ? _PageCount : settings.numDisplayPages;
		
		// Initialize the starting page variable (used when there are more pages than max pages to be displayed at one time)
		var _StartPage = 1;

	 
		// Create appropriate nav
		_ContentContainer.each(function(i) {

			// Set the width of the DataViewer
			_MasterContainer.width(settings.containerWidth);

			// Equalize the table header <th> with the table's <td>
            var columnWidths = "";
            for (z = 0; z < _MasterContainer.find(".new-table tbody tr:eq(0) td").size(); z++)
            {
                var newWidth = _MasterContainer.find(".new-table tbody tr:eq(0) td:eq(" + z +")").width();
                _MasterContainer.find(".new-header thead th:eq(" + z +")").width(newWidth);
            }

	        // Remove the old table
	        tempContainer.remove();


			// display the pagination only if there is more than on panle of data
			if ( _PageCount > 1 )
			{
				// generate the page html code after the table itself...
				var PaginationHTML = "<div class='PaginationContainer'>";
				PaginationHTML += "<div class='First-Button'><a href='#' class='PaginationButtonDisabled'>First</a></div>";
				PaginationHTML += "<div class='Prev-Button'><a href='#' class='PaginationButtonDisabled'>Prev</a></div>";
				PaginationHTML += "<div id='Number-Buttons' class='Number-Buttons'><table align='center'><tr><td><div class='Number-Button-Outer'><div class='Number-Button-Inner'></div></div></td></tr></table></div>";
				PaginationHTML += "<div class='Next-Button'><a href='#'>Next</a></div>";
				PaginationHTML += "<div class='Last-Button'><a href='#'>Last</a></div>";
				PaginationHTML += "</div>";
				PaginationHTML += "<div class='BottomPaginationMargin'></div>";
				
				jQuery(this).after(PaginationHTML);
				
				// Set the width of the Outer pager container from the number of Pagination Count
				var OuterWidth = _PaginationCount * 33;
				_MasterContainer.find(".PaginationContainer").width(settings.containerWidth);
				jQuery(this).parent().find("div.Number-Button-Outer").css("width" , OuterWidth);
		
				// ----------------------------- Build Pagination Numbers  -----------------------------
				for (n = 0; n < _PageCount; n++)
				{
					//the first number...disable it...
					if ( n == 0 ) { _MasterContainer.find("div.Number-Button-Inner").append("<div class='Number-Button-Div'><a href='#' id='PL_" + (n+1) + "' rel='" + (n+1) + "' class='PaginationButtonDisabled'>" + (n+1) + "</a></div>"); }
					//after the first number...display the page numbers enabled...
					else { _MasterContainer.find("div.Number-Button-Inner").append("<div class='Number-Button-Div'><a href='#' id='PL_" + (n+1) + "' rel='" + (n+1) + "'>" + (n+1) + "</a></div>"); }
				}
				
				// Set the entire width of the total numbers of the pagination
				_MasterContainer.find("div.Number-Button-Inner").css("width" , jQuery("div.Number-Button-Div").size() * (34));

				// Set the width of the Outer pager _MasterContainer from the number of Pagination Count
				var OuterWidth = settings.containerWidth - 180;
				//container.find(".Number-Button-Outer").width(OuterWidth);
				_MasterContainer.find(".Number-Buttons").width(OuterWidth);

			}
			
			// Build the Color Styles...
			_MasterContainer.find(".even-row").css("backgroundColor",settings.evenRowBackColor).css("color",settings.evenRowForeColor);
			_MasterContainer.find(".odd-row").css("backgroundColor",settings.oddRowBackColor).css("color",settings.oddRowForeColor);				
			
			_MasterContainer.find(".PaginationContainer").css("backgroundColor",settings.menuBackColor).css("color",settings.menuForeColor);
			_MasterContainer.find(".PaginationContainer a").css("color",settings.menuForeColor);
			_MasterContainer.find(".Number-Button-Div").css("border","1px solid " + settings.menuSquareColor);
			_MasterContainer.find("th").css("backgroundColor",settings.headerBackColor).css("color",settings.headerForeColor);
			
			_MasterContainer.find("th.sort0").hover( 
				function () { jQuery(this).css("backgroundColor",settings.headerHoverBackColor) }, 
				function () { if (jQuery(this).hasClass("sort0")) { jQuery(this).css("backgroundColor",settings.headerBackColor); } }
			);

			_MasterContainer.find(".Number-Button-Div a").hover( 
				function () { jQuery(this).css("backgroundColor",settings.menuBackHoverColor).css("color",settings.menuForeColor) }, 
				function () { jQuery(this).css("backgroundColor",settings.menuBackColor).css("color",settings.menuForeColor) }
			);

			_MasterContainer.find(".First-Button a, .Prev-Button a, .Next-Button a, .Last-Button a").not(".PaginationButtonDisabled").hover( 
				function () { jQuery(this).css("color",settings.menuBackHoverColor) }, 
				function () { jQuery(this).css("color",settings.menuForeColor) }
			);





			// ----------------------------- Pagination Number Click Events -----------------------------
			jQuery(".Number-Button-Div a").click(function(){
	
				if ( jQuery(this).hasClass("PaginationButtonDisabled") == false)
				{
					// remove the enabled class and apply the disabled class to this link
					jQuery(this).addClass("PaginationButtonDisabled").parent().parent().find("a").not(jQuery(this)).removeClass("PaginationButtonDisabled"); 
											   
					// get the new panel number to go to
					_CurrentPanel = parseInt(jQuery(this).attr("rel"));
					
					// get the top position of the new panel
					var cnt = - (_ContentContainerHeight*(_CurrentPanel - 1));
					
					// animate the panelContainer to the new panel
					jQuery(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().parent().find("div.new-table-container-inner").animate({ top: cnt}, settings.dataEaseTime, settings.dataEaseFunc);
					
					// this is the first panel, disable the first/previous links
					if (_CurrentPanel == 1) 
					{ 
						jQuery(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().find(".First-Button a").removeClass("PaginationButtonEnabled").addClass("PaginationButtonDisabled"); 
						jQuery(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().find(".Prev-Button a").removeClass("PaginationButtonEnabled").addClass("PaginationButtonDisabled"); 
					}
					// this is not the first panel, remove the disabled class if it exists
					else 
					{ 
						jQuery(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().find(".First-Button a").removeClass("PaginationButtonDisabled").addClass("PaginationButtonEnabled"); 
						jQuery(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().find(".Prev-Button a").removeClass("PaginationButtonDisabled").addClass("PaginationButtonEnabled"); 
					}
					
					// This is the last panel, disable the next/last links
					if (_CurrentPanel == _PageCount) 
					{ 
						jQuery(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().find(".Next-Button a").removeClass("PaginationButtonEnabled").addClass("PaginationButtonDisabled"); 
						jQuery(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().find(".Last-Button a").removeClass("PaginationButtonEnabled").addClass("PaginationButtonDisabled"); 
					}
					// this is not the last panel, remove the disabled class if it exists
					else 
					{ 
						jQuery(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().find(".Next-Button a").removeClass("PaginationButtonDisabled").addClass("PaginationButtonEnabled"); 
						jQuery(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().find(".Last-Button a").removeClass("PaginationButtonDisabled").addClass("PaginationButtonEnabled"); 
					}
					
	
					// ============================ Reconfigure The Pagination Numbers ============================
					// The number of pages is less than or equal to the _PaginationCount value
					if (_PageCount <= _PaginationCount) { _StartPage = 1; }
					else
					{
						// The number of pages is greater than the _PaginationCount, but the current page is less than the _PaginationCount
						if (_CurrentPanel < _PaginationCount)
						{
							// The current page is in the top half
							if (_CurrentPanel > (_PaginationCount + 1) / 2) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2)); }
							// The current page is in the bottom half
							else { _StartPage = 1; }
						}
						// The number of pages is greater than the _PaginationCount, and the current page is greater than the _PaginationCount
						else
						{
							if (_PageCount > (_CurrentPanel + _PaginationCount)) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2)); }
							else
							{
								if (_CurrentPanel < (_PageCount - ((_PaginationCount - 1) / 2))) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2));}
								// Current page is in top _PaginationCount
								else { _StartPage = (_PageCount - _PaginationCount + 1); }
							}
						}
					}
					// Get the new left position... and animate to that position...
					var newLeftpos = -((_StartPage-1) * 33);
					jQuery(this).parent().parent().parent().find("div.Number-Button-Inner").animate({ left: newLeftpos}, settings.menuEaseTime);
					// ============================ Reconfigure The Pagination Numbers ============================
	
				}
				return false;
	
			});	
	
			// ----------------------------- First Button Click Event -----------------------------
			jQuery(".First-Button a").click(function(){
	
				if ( (jQuery(this).hasClass("PaginationButtonDisabled") == false) && (_CurrentPanel != 1) )
				{	
					_CurrentPanel = 1;
					
					var cnt = - (_ContentContainerHeight*(_CurrentPanel - 1));
					
					// this is the first panel, disable me and the first button
					jQuery(this).removeClass("PaginationButtonEnabled").addClass("PaginationButtonDisabled");
					jQuery(this).parent().parent().find(".Prev-Button a").removeClass("PaginationButtonEnabled").addClass("PaginationButtonDisabled"); 
					
					// animate the panelContainer to the new panel
					jQuery(this).parent().parent().parent().find("div.new-table-container-inner").animate({ top: cnt}, settings.dataEaseTime, settings.dataEaseFunc);

					// the prev/next links are now active because we have moved back...
					jQuery(this).parent().parent().find(".Next-Button a").removeClass("PaginationButtonDisabled").addClass("PaginationButtonEnabled"); 
					jQuery(this).parent().parent().find(".Last-Button a").removeClass("PaginationButtonDisabled").addClass("PaginationButtonEnabled"); 
	
					// remove the disabled class and apply the disabled class to the first number link
					jQuery(this).parent().parent().find(".Number-Button-Div a").removeClass("PaginationButtonDisabled");
					jQuery(this).parent().parent().find("#PL_" + _CurrentPanel).addClass("PaginationButtonDisabled");
	
					// ============================ Reconfigure The Pagination Numbers ============================
					// The number of pages is less than or equal to the _PaginationCount value
					if (_PageCount <= _PaginationCount) { _StartPage = 1; }
					else
					{
						// The number of pages is greater than the _PaginationCount, but the current page is less than the _PaginationCount
						if (_CurrentPanel < _PaginationCount)
						{
							// The current page is in the top half
							if (_CurrentPanel > (_PaginationCount + 1) / 2) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2)); }
							// The current page is in the bottom half
							else { _StartPage = 1; }
						}
						// The number of pages is greater than the _PaginationCount, and the current page is greater than the _PaginationCount
						else
						{
							if (_PageCount > (_CurrentPanel + _PaginationCount)) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2)); }
							else
							{
								if (_CurrentPanel < (_PageCount - ((_PaginationCount - 1) / 2))) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2));}
								// Current page is in top _PaginationCount
								else { _StartPage = (_PageCount - _PaginationCount + 1); }
							}
						}
					}

					// Get the new left position... and animate to that position...
					var newLeftpos = -((_StartPage-1) * 33);
					jQuery(this).parent().parent().find("div.Number-Button-Inner").animate({ left: newLeftpos}, settings.menuEaseTime);
					// ============================ Reconfigure The Pagination Numbers ============================
	
				}
				return false;
			});
	
			// ----------------------------- Previous Button Click Event -----------------------------
			jQuery(".Prev-Button a").click(function(){
	
				if ( (jQuery(this).hasClass("PaginationButtonDisabled") == false) && (_CurrentPanel != 1) )
				{
					_CurrentPanel -= 1;
					
					var cnt = - (_ContentContainerHeight*(_CurrentPanel - 1));
					
					// this is the first panel, disable me and the first button
					if (_CurrentPanel == 1) 
					{ 
						jQuery(this).removeClass("PaginationButtonEnabled").addClass("PaginationButtonDisabled");
						jQuery(this).parent().parent().find(".First-Button a").removeClass("PaginationButtonEnabled").addClass("PaginationButtonDisabled"); 
					}
					
					// animate the panelContainer to the new panel
					jQuery(this).parent().parent().parent().find("div.new-table-container-inner").animate({ top: cnt}, settings.dataEaseTime, settings.dataEaseFunc);
	
					// the prev/next links are now active because we have moved back...
					jQuery(this).parent().parent().find(".Next-Button a").removeClass("PaginationButtonDisabled").addClass("PaginationButtonEnabled"); 
					jQuery(this).parent().parent().find(".Last-Button a").removeClass("PaginationButtonDisabled").addClass("PaginationButtonEnabled"); 
	
					// remove the disabled class and apply the disabled class to the previous number link
					jQuery(this).parent().parent().find(".Number-Button-Div a").removeClass("PaginationButtonDisabled");
					jQuery(this).parent().parent().find("#PL_" + _CurrentPanel).addClass("PaginationButtonDisabled"); 
	
					// ============================ Reconfigure The Pagination Numbers ============================
					// The number of pages is less than or equal to the _PaginationCount value
					if (_PageCount <= _PaginationCount) { _StartPage = 1; }
					else
					{
						// The number of pages is greater than the _PaginationCount, but the current page is less than the _PaginationCount
						if (_CurrentPanel < _PaginationCount)
						{
							// The current page is in the top half
							if (_CurrentPanel > (_PaginationCount + 1) / 2) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2)); }
							// The current page is in the bottom half
							else { _StartPage = 1; }
						}
						// The number of pages is greater than the _PaginationCount, and the current page is greater than the _PaginationCount
						else
						{
							if (_PageCount > (_CurrentPanel + _PaginationCount)) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2)); }
							else
							{
								if (_CurrentPanel < (_PageCount - ((_PaginationCount - 1) / 2))) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2));}
								// Current page is in top _PaginationCount
								else { _StartPage = (_PageCount - _PaginationCount + 1); }
							}
						}
					}
					// Get the new left position... and animate to that position...
					var newLeftpos = -((_StartPage-1) * 33);
					jQuery(this).parent().parent().find("div.Number-Button-Inner").animate({ left: newLeftpos}, settings.menuEaseTime);
					// ============================ Reconfigure The Pagination Numbers ============================
				}
				return false;
			});
	
			// ----------------------------- Next Button Click Event -----------------------------
			jQuery(".Next-Button a").click(function(){
	
				if ( (jQuery(this).hasClass("PaginationButtonDisabled") == false) && (_CurrentPanel != _PageCount) )
				{
					var cnt = - (_ContentContainerHeight*_CurrentPanel);

					_CurrentPanel += 1;
					
					// This is the last panel..., disable me and the last button
					if (_CurrentPanel == _PageCount) 
					{ 
						jQuery(this).removeClass("PaginationButtonEnabled").addClass("PaginationButtonDisabled");
						jQuery(this).parent().parent().find(".Last-Button a").removeClass("PaginationButtonEnabled").addClass("PaginationButtonDisabled"); 
					}
					
					// animate the panelContainer to the new panel
					jQuery(this).parent().parent().parent().find("div.new-table-container-inner").animate({ top: cnt}, settings.dataEaseTime, settings.dataEaseFunc);
					
					// the prev/next links are now active because we have moved back...
					jQuery(this).parent().parent().find(".First-Button a").removeClass("PaginationButtonDisabled").addClass("PaginationButtonEnabled"); 
					jQuery(this).parent().parent().find(".Prev-Button a").removeClass("PaginationButtonDisabled").addClass("PaginationButtonEnabled"); 
	
					// remove the disabled class and apply the disabled class to the next number link
					jQuery(this).parent().parent().find(".Number-Button-Div a").removeClass("PaginationButtonDisabled");
					jQuery(this).parent().parent().find("#PL_" + _CurrentPanel).addClass("PaginationButtonDisabled"); 
	
					// ============================ Reconfigure The Pagination Numbers ============================
					// The number of pages is less than or equal to the _PaginationCount value
					if (_PageCount <= _PaginationCount) { _StartPage = 1; }
					else
					{
						// The number of pages is greater than the _PaginationCount, but the current page is less than the _PaginationCount
						if (_CurrentPanel < _PaginationCount)
						{
							// The current page is in the top half
							if (_CurrentPanel > (_PaginationCount + 1) / 2) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2)); }
							// The current page is in the bottom half
							else { _StartPage = 1; }
						}
						// The number of pages is greater than the _PaginationCount, and the current page is greater than the _PaginationCount
						else
						{
							if (_PageCount > (_CurrentPanel + _PaginationCount)) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2)); }
							else
							{
								if (_CurrentPanel < (_PageCount - ((_PaginationCount - 1) / 2))) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2));}
								// Current page is in top _PaginationCount
								else { _StartPage = (_PageCount - _PaginationCount + 1); }
							}
						}
					}
					// Get the new left position... and animate to that position...
					var newLeftpos = -((_StartPage-1) * 33);
					jQuery(this).parent().parent().find("div.Number-Button-Inner").animate({ left: newLeftpos}, settings.menuEaseTime);
					// ============================ Reconfigure The Pagination Numbers ============================
				}
				return false;
			});
	
			// ----------------------------- Last Button Click Event -----------------------------
			jQuery(".Last-Button a").click(function(){
	
				if ( (jQuery(this).hasClass("PaginationButtonDisabled") == false) && (_CurrentPanel != _PageCount) )
				{
					_CurrentPanel = _PageCount-1;

					var cnt = - (_ContentContainerHeight*_CurrentPanel);

					_CurrentPanel++;
					
					// This is the last panel..., disable me and the last button
					jQuery(this).removeClass("PaginationButtonEnabled").addClass("PaginationButtonDisabled");
					jQuery(this).parent().parent().find(".Next-Button a").removeClass("PaginationButtonEnabled").addClass("PaginationButtonDisabled"); 
					
					// animate the panelContainer to the new panel
					jQuery(this).parent().parent().parent().find("div.new-table-container-inner").animate({ top: cnt}, settings.dataEaseTime, settings.dataEaseFunc);
					
					// the prev/next links are now active because we have moved back...
					jQuery(this).parent().parent().find(".First-Button a").removeClass("PaginationButtonDisabled").addClass("PaginationButtonEnabled"); 
					jQuery(this).parent().parent().find(".Prev-Button a").removeClass("PaginationButtonDisabled").addClass("PaginationButtonEnabled"); 
	
					// remove the disabled class and apply the disabled class to the last number link
					jQuery(this).parent().parent().find(".Number-Button-Div a").removeClass("PaginationButtonDisabled");
					jQuery(this).parent().parent().find("#PL_" + _CurrentPanel).addClass("PaginationButtonDisabled"); 
	
	
					// ============================ Reconfigure The Pagination Numbers ============================
					// The number of pages is less than or equal to the _PaginationCount value
					if (_PageCount <= _PaginationCount) { _StartPage = 1; }
					else
					{
						// The number of pages is greater than the _PaginationCount, but the current page is less than the _PaginationCount
						if (_CurrentPanel < _PaginationCount)
						{
							// The current page is in the top half
							if (_CurrentPanel > (_PaginationCount + 1) / 2) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2)); }
							// The current page is in the bottom half
							else { _StartPage = 1; }
						}
						// The number of pages is greater than the _PaginationCount, and the current page is greater than the _PaginationCount
						else
						{
							if (_PageCount > (_CurrentPanel + _PaginationCount)) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2)); }
							else
							{
								if (_CurrentPanel < (_PageCount - ((_PaginationCount - 1) / 2))) { _StartPage = (_CurrentPanel - ((_PaginationCount - 1) / 2));}
								// Current page is in top _PaginationCount
								else { _StartPage = (_PageCount - _PaginationCount + 1); }
							}
						}
					}
					// Get the new left position... and animate to that position...
					var newLeftpos = -((_StartPage-1) * 33);
					jQuery(this).parent().parent().find("div.Number-Button-Inner").animate({ left: newLeftpos}, settings.menuEaseTime);
					// ============================ Reconfigure The Pagination Numbers ============================
				}
				return false;
			});



			// Make the new generated table sortable if there are any sortable column headers
			jQuery(_ContentContainer).find("table").tablesorter(); 	

			jQuery(_ContentContainer).find("table").bind("sortStart", function() { 
				//jQuery(_ContentContainer).find(".overlay").animate({opacity:1.0}, {duration:100});
			}).bind("sortEnd", function() { 
				jQuery(_ContentContainer).find(".overlay").animate({opacity:0.0}, {duration:700});
			}); 
			
			// Click fucntion to trigger the proper sort, whether it be asc, desc, or nothing...
			jQuery(_MasterContainer).find(".new-header th").click(function() 
				{ 
					var tempNumb = jQuery(this).attr("rel");
					if ( jQuery(this).hasClass("sort0") )
					{
						jQuery(_ContentContainer).find(".overlay").animate({opacity:1.0}, {duration:100});
						jQuery(this).removeClass("sort0").addClass("sort1");
						var sorting = [[tempNumb,0]];
						jQuery(_ContentContainer).find("table").trigger("sorton",[sorting])
						jQuery(this).parent().find("th.sort1").not(jQuery(this)).removeClass("sort1").addClass("sort0").css("backgroundColor",settings.headerBackColor);
						jQuery(this).parent().find("th.sort2").not(jQuery(this)).removeClass("sort2").addClass("sort0").css("backgroundColor",settings.headerBackColor);
						jQuery(this).css("backgroundColor",settings.headerHoverBackColor);
					}
					else if ( $(this).hasClass("sort1") )
					{
						jQuery(_ContentContainer).find(".overlay").animate({opacity:1.0}, {duration:100});
						jQuery(this).removeClass("sort1").addClass("sort2");
						var sorting = [[tempNumb,1]];
						jQuery(_ContentContainer).find("table").trigger("sorton",[sorting])
						jQuery(this).parent().find("th.sort1").not(jQuery(this)).removeClass("sort1").addClass("sort0").css("backgroundColor",settings.headerBackColor);
						jQuery(this).parent().find("th.sort2").not(jQuery(this)).removeClass("sort2").addClass("sort0").css("backgroundColor",settings.headerBackColor);
						jQuery(this).css("backgroundColor",settings.headerHoverBackColor);
					}
					else if ( $(this).hasClass("sort2") )
					{
						jQuery(_ContentContainer).find(".overlay").animate({opacity:1.0}, {duration:100});
						jQuery(this).removeClass("sort2").addClass("sort1");
						var sorting = [[tempNumb,0]];
						jQuery(_ContentContainer).find("table").trigger("sorton",[sorting])
						jQuery(this).parent().find("th.sort1").not(jQuery(this)).removeClass("sort1").addClass("sort0").css("backgroundColor",settings.headerBackColor);
						jQuery(this).parent().find("th.sort2").not(jQuery(this)).removeClass("sort2").addClass("sort0").css("backgroundColor",settings.headerBackColor);
						jQuery(this).css("backgroundColor",settings.headerHoverBackColor);
					}
	
					var tempTableContainer = jQuery(this).parent().parent().parent().parent().parent().find(".new-table");
					for ( k = 0; k <= tableRowCount; k++ )
					{
						if (k%2==0)
						{ tempTableContainer.find("tr:eq(" + k + ")").css("backgroundColor",settings.oddRowBackColor).css("color",settings.oddRowForeColor); }
						else	
						{ tempTableContainer.find("tr:eq(" + k + ")").css("backgroundColor",settings.evenRowBackColor).css("color",settings.evenRowForeColor); }
					}
	
					return false;
					
				}
			); 


			
		});

});
};
