/* Author: Ben Jaffe
*/


/*!
 * jQuery hashchange event - v1.3 - 7/21/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */

(function($,window,undefined){'$:nomunge';var str_hashchange='hashchange',doc=document,fake_onhashchange,special=$.event.special,doc_mode=doc.documentMode,supports_onhashchange='on'+str_hashchange in window&&(doc_mode===undefined||doc_mode>7);function get_fragment(url){url=url||location.href;return'#'+url.replace(/^[^#]*#?(.*)$/,'$1');};$.fn[str_hashchange]=function(fn){return fn?this.bind(str_hashchange,fn):this.trigger(str_hashchange);};$.fn[str_hashchange].delay=50;special[str_hashchange]=$.extend(special[str_hashchange],{setup:function(){if(supports_onhashchange){return false;}
$(fake_onhashchange.start);},teardown:function(){if(supports_onhashchange){return false;}
$(fake_onhashchange.stop);}});fake_onhashchange=(function(){var self={},timeout_id,last_hash=get_fragment(),fn_retval=function(val){return val;},history_set=fn_retval,history_get=fn_retval;self.start=function(){timeout_id||poll();};self.stop=function(){timeout_id&&clearTimeout(timeout_id);timeout_id=undefined;};function poll(){var hash=get_fragment(),history_hash=history_get(last_hash);if(hash!==last_hash){history_set(last_hash=hash,history_hash);$(window).trigger(str_hashchange);}else if(history_hash!==last_hash){location.href=location.href.replace(/#.*/,'')+history_hash;}
timeout_id=setTimeout(poll,$.fn[str_hashchange].delay);};$.browser.msie&&!supports_onhashchange&&(function(){var iframe,iframe_src;self.start=function(){if(!iframe){iframe_src=$.fn[str_hashchange].src;iframe_src=iframe_src&&iframe_src+get_fragment();iframe=$('<iframe tabindex="-1" title="empty"/>').hide().one('load',function(){iframe_src||history_set(get_fragment());poll();}).attr('src',iframe_src||'javascript:0').insertAfter('body')[0].contentWindow;doc.onpropertychange=function(){try{if(event.propertyName==='title'){iframe.document.title=doc.title;}}catch(e){}};}};self.stop=fn_retval;history_get=function(){return get_fragment(iframe.location.href);};history_set=function(hash,history_hash){var iframe_doc=iframe.document,domain=$.fn[str_hashchange].domain;if(hash!==history_hash){iframe_doc.title=doc.title;iframe_doc.open();domain&&iframe_doc.write('<script>document.domain="'+domain+'"</script>');iframe_doc.close();iframe.location.hash=hash;}};})();return self;})();})(jQuery,this);

/*!
 * JSizes - JQuery plugin v0.33
 *
 * Licensed under the revised BSD License.
 * Copyright 2008-2010 Bram Stein
 * All rights reserved.
 */
/*global jQuery*/
(function ($) {
	$(document.getElementById("body")).removeClass("nojs").addClass("js");
	var num = function (value) {
			return parseInt(value, 10) || 0;
		};

	/**
	 * Sets or gets the values for min-width, min-height, max-width
	 * and max-height.
	 */
	$.each(['min', 'max'], function (i, name) {
		$.fn[name + 'Size'] = function (value) {
			var width, height;
			if (value) {
				if (value.width !== undefined) {
					this.css(name + '-width', value.width);
				}
				if (value.height !== undefined) {
					this.css(name + '-height', value.height);
				}
				return this;
			}
			else {
				width = this.css(name + '-width');
				height = this.css(name + '-height');
				// Apparently:
				//  * Opera returns -1px instead of none
				//  * IE6 returns undefined instead of none
				return {'width': (name === 'max' && (width === undefined || width === 'none' || num(width) === -1) && Number.MAX_VALUE) || num(width), 
						'height': (name === 'max' && (height === undefined || height === 'none' || num(height) === -1) && Number.MAX_VALUE) || num(height)};
			}
		};
	});

	/**
	 * Returns whether or not an element is visible.
	 */
	$.fn.isVisible = function () {
		return this.is(':visible');
	};

	/**
	 * Sets or gets the values for border, margin and padding.
	 */
	$.each(['border', 'margin', 'padding'], function (i, name) {
		$.fn[name] = function (value) {
			if (value) {
				if (value.top !== undefined) {
					this.css(name + '-top' + (name === 'border' ? '-width' : ''), value.top);
				}
				if (value.bottom !== undefined) {
					this.css(name + '-bottom' + (name === 'border' ? '-width' : ''), value.bottom);
				}
				if (value.left !== undefined) {
					this.css(name + '-left' + (name === 'border' ? '-width' : ''), value.left);
				}
				if (value.right !== undefined) {
					this.css(name + '-right' + (name === 'border' ? '-width' : ''), value.right);
				}
				return this;
			}
			else {
				return {top: num(this.css(name + '-top' + (name === 'border' ? '-width' : ''))),
						bottom: num(this.css(name + '-bottom' + (name === 'border' ? '-width' : ''))),
						left: num(this.css(name + '-left' + (name === 'border' ? '-width' : ''))),
						right: num(this.css(name + '-right' + (name === 'border' ? '-width' : '')))};
			}
		};
	});
})(jQuery);


/* Delay plugin
* http://james.padolsey.com/javascript/jquery-delay-plugin/
*/
$.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
};


/**
* Fullscreenr - lightweight full screen background jquery plugin
* By Jan Schneiders
* Version 1.0
* www.nanotux.com
*
(function($){	
	$.fn.fullscreenr = function(options) {
		if(options.height === undefined) alert('ack');
		if(options.width === undefined) alert('ack');
		if(options.bgID === undefined) alert('ack');
		var defaults = { width: 1280,  height: 1024, bgID: 'bgimg' };
		var options = $.extend({}, defaults, options); 
		$(document).ready(function() { $(options.bgID).fullscreenrResizer(options);	});
		$(window).bind("resize", function() { $(options.bgID).fullscreenrResizer(options); });		
		return this; 		
	};	
	$.fn.fullscreenrResizer = function(options) {
		// Set bg size
		var ratio = options.height / options.width;	
		// Get browser window size
		var browserwidth = $(window).width();
		var browserheight = $(window).height();
		// Scale the image
		if ((browserheight/browserwidth) > ratio){
		    $(this).height(browserheight);
		    $(this).width(browserheight / ratio);
		} else {
		    $(this).width(browserwidth);
		    $(this).height(browserwidth * ratio);
		}
		// Center the image
		$(this).css('left', (browserwidth - $(this).width())/2);
		$(this).css('top', (browserheight - $(this).height())/2);
		return this; 		
	};
})(jQuery);
*/





slowMo=false;
currentCard = [3,0]; //stores the current selected section and card
currentCardArr = [0,0,0,0]; //stores the current card in each section
customAnim = false;
optimDisabled = false;
normalizedCardNavBtns = true;
$(document).ready(function(){

	//cb.gotoCard(3,0,true);
	
	if (window.location.hash !== "") {
		cb.gotoCard(window.location.hash.split("/").join("-").split("#")[1]);
	}
	
	$(document).keydown(function (e) {
	  var keyCode = e.keyCode || e.which,
	      arrow = {left: 37, up: 38, right: 39, down: 40 };

	  switch (keyCode) {
	    case arrow.left:
			cb.gotoCard("previous");
	    break;
	    case arrow.up:
			cb.gotoCard("previousSection");
	    break;
	    case arrow.right:
			cb.gotoCard("next");
	    break;
	    case arrow.down:
			cb.gotoCard("nextSection");
	    break;
	  }
	});
	
});

var cb = new CardBox();

// Bind the event.
$(window).hashchange( function(){
	
	var id = location.hash.split("/").join("-").split("#")[1];
	
	if(!cb.areWeHere(id)) {
		cb.gotoCard(id);		
		// console.log("Hash changed to " + location.hash);
	}
	
});
// Trigger the event (useful on page load).
//$(window).hashchange();



// -------------------------------------------------------------

function CardBox() {
	
	var pages=[], sectionNav=[], ghostNav=[], t, containerHeight, containerWidth, startCards, endCards, cardsToShow;
	var cardDisplayOffset=3; //for animOptim, keeps track of cards that need to be visible for the start or end of the animation
	var sectionSpeed = 300;
	var cardSpeed = 600;
	// loop through navs and sections, link them together
	refreshView();
	setupCards();
	setupNav();
	
	// this.gotoSection = function(sectionNum, animate) {
	// 	sectionMover(sectionNum,animate);
	// };
	
	this.areWeHere = function(id) {
		if(id == $(pages[currentCard[0]][currentCard[1]]).attr("id") ) {
			return true;
		} else {
			return false;
		}
	};
	
	this.getPages = function() {
		return pages;
	};
	
	this.gotoCard = function(sectionNum, cardNum, animate) {
		console.log("------------------- Start Move --------------------");
		console.log("Current cards are");
		console.log(currentCardArr);
		if(isNaN(sectionNum)) {
			if(sectionNum.toLowerCase() == "next") { //Next
				console.log("--Calling Next Card");
				console.log(currentCard[0] + "  ||  " + (currentCard[1]+1) + "  ||  " + animate);
				moveToCard(currentCard[0],currentCard[1]+1,animate);
			} else if (sectionNum.toLowerCase() == "previous") { //Previous
					console.log("--Calling Prev Card");
					moveToCard(currentCard[0],currentCard[1]-1,animate);
			} else if (sectionNum.toLowerCase() == "nextsection") { //Next Section
					moveToCard(currentCard[0]+1,currentCardArr[currentCard[0]+1],animate);
			} else if (sectionNum.toLowerCase() == "previoussection") { //Previous Section
					moveToCard(currentCard[0]-1,currentCardArr[currentCard[0]-1],animate);
			} else {
				var desiredCard = document.getElementById(sectionNum);
				if (desiredCard !== null) {
					var desiredSection = $(desiredCard).parents(".section");
					moveToCard(whatNum(desiredSection),whatNum(desiredCard),animate);
				} else {
					console.error("You just tried to move to a card by its ID or Hash Tag. That ID is not defined.\nThe attempted move was to " + sectionNum + ", which doesn't match the ID of anything in this document.");
				}
			}
		} else {
			moveToCard(sectionNum,cardNum,animate);
		}
		return false;
	};
	
	this.removeOldElements = function(){
		for (var i=0; i < pages.length; i++) {
			$(pages[i]).css({"display":"none"});
		};
		for (var i=0; i < cardsToShow.length; i++) {
			$(cardsToShow[i]).css({"display":"block"});
		}
	};
	
	
	
	function refreshView () {
		containerHeight = $($(".container")[0]).height();
		var containerWidth = $($(".container")[0]).width();
		// console.log(containerHeight + " " + containerWidth);
	}
	
	function animOptim (animProgress, animFrom, animTo) { //animProgress is 0 or 1, start or finish, animFrom and animTo are arrays [section, card] of starting point and ending point
		if(optimDisabled) {return true;}
		console.log("\t\tanimOptim: " + animProgress + ", " + animFrom + ", " + animTo);
		sectionFrom = animFrom[0];
		sectionTo = animTo[0];
		cardFrom = currentCardArr[sectionTo]; //this is the card in the sectionTo that we're animating from
		cardTo = animTo[1];
		
		//Show relevant cards
		if (animProgress == 0) {
			cardsToShow = [];
			cardChange = animTo[1]-currentCardArr[animTo[0]]; //again, we are only referring to the section we're animating to, since we don't do animation in the "from" section
			
			
			for (var i=(Math.min(cardFrom,cardTo)-cardDisplayOffset); i <= Math.max(cardFrom,cardTo)+cardDisplayOffset; i++) {
				if(i<0) {i=0;}
				cardsToShow.push(pages[sectionTo][i]);
				// console.log("\t\t\tadded " + i);
			};
			// console.log("** Cards to show:");
			// console.log(cardsToShow);
			for (var i=0; i < cardsToShow.length; i++) {
				$(cardsToShow[i]).css({"display":"block"});
			};
			
		//hide irrelevant cards
		} else {
			t = clearTimeout();
			
			t = setTimeout("cb.removeOldElements();", sectionSpeed);
		};
		return true;
	}
		
	function makeCardNav (section) {
		var cardNav = document.createElement("div");
		// cardNav.src = "images/cardShadow.png";
		cardNav.className = "cardNav";
		$(section).append(cardNav);
		cardNavWidth = getWidth(cardNav,false, false);
		
		sectionNum = whatNum(section);
		var numCards = pages[sectionNum].length;
		// console.log(pages[sectionNum]);
		var cardNavWidthArr = [];
		var totalWidth = 0;
		var widthToSet = (cardNavWidth/numCards)-1+"px"; // -1 compensates for the border
		
		if (!normalizedCardNavBtns) {
			for (var i=0; i < numCards; i++) { //loop through cards
				cardNavWidthArr.push(getWidth(pages[sectionNum][i],true,true)); 
			}
			for (var j=0; j < numCards; j++) { //sum lengths
				totalWidth+=cardNavWidthArr[j];
			}
		}
		
		for (var i=0; i < numCards; i++) { //create the buttons
			var navBtn = document.createElement("a");
			navBtn.href = "javascript:";
			navBtn.className = "cardNavBtn cardNavBtn"+zeroPad(i,2);
			
			if (!normalizedCardNavBtns) {
				var widthFraction = (cardNavWidthArr[i]/totalWidth);
				// console.log("width1: "+cardNavWidthArr[i]+" , total: "+totalWidth+", fraction is "+widthFraction);
				widthToSet = (cardNavWidth*widthFraction)-1+"px";
			}
			
			navBtn.style.width = widthToSet;
			// console.log(getWidth(navBtn,true,true));
			$(cardNav).append(navBtn);
			
			(function () {
				var btnNum = i;
				var secNum = sectionNum;
				$(navBtn).click(function() {
					cb.gotoCard(secNum,btnNum,true);									//HACK -- shouldn't be referencing the object name here...
					return false;
				});
			})();
			
		};
		updateSectionNav(currentCard[0],currentCard[1]);
		
	}
	
	function whatNum(object) { //returns what number object it is
		var objectType;
		if ($(object).hasClass("section")) {
			objectType = "section";
		}
		if ($(object).hasClass("card")) {
			objectType = "card";
		}
		// console.log("is "+objectType+"!!");
		var objectsBefore = $(object).prevAll("."+objectType);
		return objectsBefore.length;
		
	}
	
	//done :)
	function setupNav () { 
		$.each($("nav a"), function() {
			var sectionNavCurrent = [this];
			var name = $(this).attr("href").split("#")[1];
			var section = $(".section."+name)[0];
			if ($(this).parent().hasClass("nav")) {
				makeCardNav(section);
				sectionNavCurrent.push(section);
				sectionNavCurrent.push($(".section."+name+" .cardNav"));
				sectionNav.push(sectionNavCurrent);
				ghostNav.push($(".ghost a[href='#"+name+"']"));
			}
			
				
		});
		// console.log("* Section Nav Item List is:");
		// console.log(sectionNav);

		for (var i=0; i < sectionNav.length; i++) {
			(function() { //anon function for variable scope for click handler
				var currentSection = i;
				$.each([$(sectionNav[i][1]).find(".sectionHead"),$(sectionNav[i][0])],function(index,value) {
					value.click(function(e) {
						cb.gotoCard(currentSection,currentCardArr[currentSection],true); 								//HACK -- shouldn't be referencing the object name here...
						return false;
					}).hover(function(){
						$.each([$(sectionNav[currentSection][1]).find(".sectionHead"),$(sectionNav[currentSection][0])],function(index,value) {value.addClass("hover");});
					},function(){
						$.each([$(sectionNav[currentSection][1]).find(".sectionHead"),$(sectionNav[currentSection][0])],function(index,value) {value.removeClass("hover");});
					});
				});
			})();
		};
		
		for (var i=0; i < ghostNav.length; i++) {
			(function() { //anon function for variable scope for click handler
				var currentSection = i;
				// console.log("Ghost Nav");
				// console.log(ghostNav);
				ghostNav[i].click(function(e) {
					cb.gotoCard(currentSection,currentCardArr[currentSection],true); 								//HACK -- shouldn't be referencing the object name here...
					return false;
				}).hover(function(){
					value.addClass("hover");
				},function(){
					value.removeClass("hover");
				});
			})();
		};

		// console.log("* Click handlers are assigned on nav items");		
		
		//Setup sections to catch clicks
		$(".section").click(function() {
			return false;
		});
		
		//Setup Next/Prev Arrows
		$(".arrow").click(function(){
			cb.gotoCard($(this).attr("title"));
		});
	}
	
	//done :-)
	function setupCards() {
		console.log("* Setting up cards...");
		//Set up the pages array
		$.each($(".section"), function(sIndex, sValue){ //Loop through sections
			// console.log("\tSetting up cards in section "+sIndex+" ("+$(this).attr("class").split(" ")[1]+")");

			pages.push($(this).find(".card")); //Add arrays of cards to pages array
			$.each($(this).find(".card"), function(cIndex, cValue){ //Loops through cards
				cIndexPadded = zeroPad(cIndex,2);
//				console.log(cIndexPadded + " = " + cIndex);
				$(this).addClass("card"+cIndexPadded);
				createShadows($(this));
				$(cValue).click(function() {
					moveToCard(sIndex, cIndex, true);
					console.log("!!Event Propogation should end here");
					return false;
				});

			});
		});
		console.log("* Pages array is set up:");
		console.log(pages);
		
		//Setup related cards click handlers
		$(".relatedCards a").click(function() {
			cb.gotoCard($(this).attr("title"));
			return false;
		});

		//Position pages
		console.log("* Moving cards into position");
		for(i=0;i<pages.length;i++) {
			cardMover(i, 0, false);
		}
	}
	
	//done :-)
	function createShadows(card) {
		// console.log("Shadows");
		// console.log(card);
		var winOrigWidth = getWidth(card, false,false);
		var shadowOverflow = .07; //the lower the number, the less overflow
		if(winOrigWidth > 300) {shadowOverflow/=(winOrigWidth/300);}
		
		$(card).css({"padding-left":Math.floor(winOrigWidth*shadowOverflow)+"px",
			"padding-right":Math.floor(winOrigWidth*shadowOverflow)+"px",
			"padding-bottom":8+winOrigWidth/50+"px"});
		// console.log(winwidth);
		var winwidth = getWidth(card, false,false);
		var shadow = document.createElement("img");
		shadow.src = "images/cardShadow.png";
		shadow.className = "shadow";
		shadow.width = winwidth;
		shadow.height = 38-(winwidth/6);
		card.append(shadow);
	}
	
	function cardExists (section, card) {
		// alert();
		if (pages[section] !== undefined) {
			if (pages[section][card] !== undefined) {
				return true;
			}
		}
		return false;
	}
	
	function setHash (section, card) {
		var cardId = $($($(".section")[section]).find(".card")[card]).attr("id");
		console.log("Changing hasd to "+cardId);
		window.location.hash = cardId.split("-").join("/");
	}
	
	function updateSectionNav(section,card) {
		$(".cardNav .selected").removeClass("selected");
		$($(".section")[section]).find(".cardNavBtn"+zeroPad(card,2)).addClass("selected");
	}
	
	function moveToCard(section, card, animate) {
		if (!cardExists(section, card)) {console.log("desired card is out of bounds");return false;}
		if (section !== currentCard[0] || card !== currentCard[1]) { //if we aren't already on the desired card
			animOptim(0, currentCard,[section,card]); //ensure relevant cards are displayed
			var consoleMsg = "\t-----------------\n* Moving to Card: (";
			if (animate === undefined) {animate = true;}
			if (section !== NaN && section != currentCard[0]) { //if section is changing
				consoleMsg += " section changed ";
				sectionMover(section, animate);
				currentCard[0]=section; //set currentCard's section to the new section
				currentCard[1]=card; //set currentCard's card to the new card
			}
		
			if (card != NaN && card != currentCardArr[section]) { //if card is changing
				cardMover(section, card, animate);
				currentCard[1]=card;
				consoleMsg += " card changed ";
				console.log("---------\n\n");
				console.log("section = "+section);
				console.log("card = "+card);
				console.log("currentCard = "+currentCard);
				console.log("currentCardArr= "+currentCardArr);
				console.log("currentCardArr[section] = " + currentCardArr[section]);
				if(section !== NaN) {currentCardArr[section] = card;}
			}
			updateSectionNav(section,card);

			console.log(consoleMsg+")");
			animOptim(1, currentCard,[section,card]); //hide now-unneeded cards
			
			setHash(section, card);
			
			return true;
		} else {console.log("not moving, we're already here");return false;}
	}
	
	function cardMover(section,card,animate) {
		var center=($(".container").width() + $(".container").padding().left + $(".container").padding().right)/2;
		
		var triggerActualMove = function(card,xPos, animate) {
			if (animate) {
				$(card).animate({"left":xPos},cardSpeed);
			} else {
				$(card).css({"left":xPos});
			}
		};
		
		var xSelectedPosition = center-getWidth($(pages[section][card]),true,true)/2;
		var xPosition = xSelectedPosition;
		console.log("\tCard Mover: Moving to Section "+section+", Card "+card);
		
		for(j=card-1;j>=Math.max(0);j--) { //go backward (not including current)
			xPosition -= getWidth(pages[section][j],true,true);
			triggerActualMove(pages[section][j],xPosition, animate);
		}
		var xPosition = xSelectedPosition;
		for(j=card;j<(pages[section].length);j++) { //go forward (including current)
			triggerActualMove(pages[section][j],xPosition, animate);
			xPosition += getWidth(pages[section][j],true,true);
		}
	}


	function sectionMover(sectionNum,animate) {
		forward = currentCard[0]<sectionNum;
		speed=((slowMo*3)+1)*sectionSpeed;
		var toAnimate = [];
		
//		console.log("\t(forward = "+forward+")");

		openSection = $($(".section")[sectionNum]);
		openNavBtn = $($(".nav a")[sectionNum]);
		
		var bottom = containerHeight - 44;
		if(forward){
			toAnimate=$.merge($(openSection.add(openSection.prevAll(".section"))),($(openNavBtn.add(openNavBtn.prevAll("a")))));
			for (var i=0; i < toAnimate.length; i++) {
				if(animate) {
					$(toAnimate[i]).animate({"top":"0"},{"queue":"false","duration":speed});
				} else {
					$(toAnimate[i]).css({"top":"0"});
				}
			};
		} else {
			toAnimate=$.merge($(openSection.nextAll(".section")),$(openNavBtn.nextAll("a")));
			for (var i=0; i < toAnimate.length; i++) {
				if(animate) {
					$(toAnimate[i]).animate({"top":bottom+"px"},{"queue":"false","duration":speed});
				} else {
					$(toAnimate[i]).css({"top":bottom+"px"});
				}
				
			};
		}
		$(".section.selected").removeClass("selected");
		openSection.addClass("selected");
	}

// -------------------------------------------------------------









	function getWidth(object, marginTrue, borderTrue) {		// 
			// console.log($(object).width());
			// console.log($(object).padding().left);
			// console.log($(object).padding().right);
		return $(object).width() + $(object).padding().left + $(object).padding().right + borderTrue*($(object).border().left + $(object).border().right) + marginTrue*($(object).margin().left + $(object).margin().right);
	}



	function setupNavButtons() { //depracated?
		//Add click handlers for section buttons
		$("nav a").each(function(){
			$(this).click(function() {
				sectionName = $(this).attr("href").split("#")[1];
				// pages.index(this);
				moveToSection(sectionName);
				return false;
			});
		});
	
			// 
			// this.sections = [];
			// $("nav a").each(function(){
			// 	sectionName = $(this).attr("href").split("#")[1];
			// 	correspondingSection = $(".section."+sectionName);
			// 	sections.push([$(this),correspondingSection.get(0)]);
			// });
			// console.log("Sections are here:"); console.log(sections);
			// 
			// for (var i=0; i < sections.length; i++) {
			// 	console.log("blah " + sections[i][0]);
			// 	
			// 	sections[i][0].click(function(){
			// 		console.log(this);
			// 		
			// 		alert("click! " + sections[i][0] + " " + section[i][1]);
			// 	});
			// };
	
	
		//Add shift-key Easter Egg
		$(document).keydown(function(event) { if(!slowMo && (event.keyCode == '16' || event.keyCode == '17')) {slowMo=true;} });
	    $(document).keyup(function(event) {if (event.keyCode == '16' || event.keyCode == '17') {slowMo=false;} });
	}


}


function zeroPad (num,count) {
	var numZeroPad = num+'';
	while (numZeroPad.length < count) {
		numZeroPad = "0" + numZeroPad;
	}
	return numZeroPad;
}
/*

function setupPages () {

	$.each($(".section"), function(sIndex, sValue){ //Loop through sections
		console.log("---Section "+sIndex+", ("+$(this).attr("class")+")---");
		// grab nav buttons and bars into arrays
		
		
		
		// add click handlers
		
	});
}

*/

