	/* Dave Arthur - Sept 2010 */
	
	
	/* This script is designed to center the modular contents of General Container Boxes upon page load and as the browser window is increased in width */
	/* To implement, enclose the modular units in a div with class "CenteredContent" */
	/* The script should analyze the contents of CenteredContent, determine how much space is available
in CenteredContent div and how many units it can fit in the container's width.  Once it has determined this, it will assign a width to the CenteredContent div 
so it can be centered by margin: auto CSS within the "Content" div. */
	
	function setCenteredContentWidth() {
	  
	  /* Define variables in funtion */
	  
		var numGCboxes;
		var targetDiv;
		var j, k;
		
	
		/* Determine how many CenteredContent blocks in MainContent block and loop through each calling the centerContainer function  */
		
		
		numGCBoxes = $(".MainContent").children();
		
		for (j=0; j < numGCBoxes.length; j++) {
				if ($(numGCBoxes[j]).is(".GeneralContainerBox")) {
				
					targetDiv = $(numGCBoxes[j]).find(".CenteredContent");
					
					if (targetDiv.length) {
						
						for (k = 0; k < targetDiv.length; k++) {
						
							$(targetDiv[k]).attr("id", "CenteredContent" + k);
							 
							centerContainer(targetDiv[k]);
						}
					}	
					
				}	
			
		}
		
	}
		
	function centerContainer(obj) {
	
		/* Define variables in funtion */
	
		var numberFit; 
		var newWidth;
		var unitCount = 0;
		var totalUnitWidth;
		var maxWidth;
		var currContainerWidth;
		var a;
		
		var contentUnits = $(obj).children();  /* get the children of the target CenteredContent div */
		
		 if ( contentUnits[0].nodeName === "UL" ) {   /* check if the children contains an unordered list.  If it does get it's children (list items) */
			contentUnits = $(obj).find("li"); 
		 }
		 
		 totalUnitWidth = contentUnits.outerWidth(true);  /* Find the total outerwidth of the individual CenteredContent units */
		 
		 for (a=0; a < contentUnits.length; a++) {
		 
			 if ( $(contentUnits[a]).css("float") === "left" ) {  /* Only loop through units which are floated left */
			 
				unitCount ++;  /* Performs a count of the total number of units */
			 }
		}
		
		 maxWidth = totalUnitWidth * unitCount;  /* Determines the maximum width of all of the units  - If the user stretches the browser window and display all of the units
		 horizontally, the width is capped so it can be centered */
		 
		 $(obj).css("max-width", maxWidth); /* Sets CSS Max-width value */
		 
		 currContainerWidth = $(obj).width();  /* Finds current CenteredContent width */
			
		 numFit = Math.floor(currContainerWidth / totalUnitWidth);  /* Determines how many units will fit within current CenteredContent width */

		 newWidth = numFit * totalUnitWidth;  /* Determines New width */
		 
		 $(obj).css("width", newWidth); /* Assigns new width to CenteredContent */
	  
	}
	  
	  
	  
	  
	  /* Function calls */
	  
	  /* Page load */

      $(document).ready(function() { 
		 
		 setCenteredContentWidth();
		 
		 /* Sets re-sizing event call */
		 
		 $(window).resize(function() {
			$(".CenteredContent").css("width", "100%");  /* resets CenteredContent to width 100% */
			setCenteredContentWidth() });
   
      });
	  
	  
	  
	  
