function borderImages() {
	var carouselImages = $$('ul.carousel li img');
	var articles = $$('article');
	var largeShadowImages = $$('img.largeShadow');
	
	var largeBackgroundImage = '/themes/judson/images/global/border-large.png';
	var smallBackgroundImage = '/themes/judson/images/global/border-small.png';
	
	
	articles.each(function(article){
		var articleSections = article.select('section');
		articleSections.each(function(section){
			var sectionImages = section.select('img');
			dynamicShadow(sectionImages, smallBackgroundImage, '', 16, 0);
			
		});
		
	});
	
	//dynamicShadow(carouselImages, largeBackgroundImage, '', 38, 0);
	dynamicShadow(largeShadowImages, largeBackgroundImage, '', 38, 0);
	
}

//dynamicShadow - Creates a dynamic shadow for images
//Defaults to shadow.gif, 10 width, no offset
//Note: Prototype Framework
function dynamicShadow(selectedImages, shadowURL, containerID, shadowWidth, shadowOffset) {
	var shadowURL = (shadowURL == null) ? "/themes/judson/images/global/border-small.png" : shadowURL;
	var containerID = (containerID == null) ? "page-container" : containerID;
	var shadowWidth = (shadowWidth == null) ? 10 : shadowWidth;
	var shadowOffset = (shadowOffset == null) ? 0 : shadowOffset;

	
	var images = selectedImages;
	var imageClone;
	var imageHeight;
	var imageWidth;
	var shadowContainer;
	var shadowDiv = [];
	
	images.each(function(imageObject){
		imageClone = Object.extend(imageObject);
		imageHeight = imageObject.getHeight();
		imageWidth = imageObject.getWidth();
		imageClass = imageObject.className;
		
		// Create the Shadow Container
		shadowContainer = new Element('div');
		shadowContainer.addClassName('shadowContainer');
		shadowContainer.addClassName(imageClass);
		shadowContainer.setStyle({
			padding: shadowWidth + 'px',
			width: imageWidth + 'px',
			height: imageHeight + 'px',
			background: 'transparent'
		});

		// Create Top Left Div
		shadowDiv[0] = new Element('div');
		shadowDiv[0].setStyle({
			position: 'absolute',
			top: 0,
			left: 0,
			width: shadowWidth + 'px',
			height: shadowWidth + 'px',
			background: 'transparent url("' + shadowURL + '") top left no-repeat'
		});
		shadowContainer.insert({ bottom: shadowDiv[0] });
		
		// Create Top Right Div
		shadowDiv[1] = new Element('div');
		shadowDiv[1].setStyle({
			position: 'absolute',
			top: 0,
			right: 0,
			width: shadowWidth + 'px',
			height: shadowWidth + 'px',
			background: 'transparent url("' + shadowURL + '") top right no-repeat'
		});
		shadowContainer.insert({ bottom: shadowDiv[1] });
		
		// Create Bottom Right Div
		shadowDiv[2] = new Element('div');
		shadowDiv[2].setStyle({
			position: 'absolute',
			bottom: 0,
			right: 0,
			width: shadowWidth + 'px',
			height: shadowWidth + 'px',
			background: 'transparent url("' + shadowURL + '") bottom right no-repeat'
		});
		shadowContainer.insert({ bottom: shadowDiv[2] });
		
		// Create Bottom Left Div
		shadowDiv[3] = new Element('div');
		shadowDiv[3].setStyle({
			position: 'absolute',
			bottom: 0,
			left: 0,
			width: shadowWidth + 'px',
			height: shadowWidth + 'px',
			background: 'transparent url("' + shadowURL + '") bottom left no-repeat'
		});
		shadowContainer.insert({ bottom: shadowDiv[3] });
		
		// Create Center Top Div
		shadowDiv[4] = new Element('div');
		shadowDiv[4].setStyle({
			position: 'absolute',
			top: 0,
			left: shadowWidth + 'px',
			width: imageWidth + 'px',
			height: shadowWidth + 'px',
			backgroundImage: 'url("' + shadowURL + '")',
			backgroundPosition: (-shadowWidth) + 'px top',
			backgroundRepeat: 'no-repeat'
		});
		shadowContainer.insert({ bottom: shadowDiv[4] });
		
		// Create Center Right Div
		shadowDiv[5] = new Element('div');
		shadowDiv[5].setStyle({
			position: 'absolute',
			top: shadowWidth + 'px',
			right: 0,
			width: shadowWidth + 'px',
			height: imageHeight + 'px',
			backgroundImage: 'url("' + shadowURL + '")',
			backgroundPosition: 'right ' + (-shadowWidth) + 'px',
			backgroundRepeat: 'no-repeat'
		});
		shadowContainer.insert({ bottom: shadowDiv[5] });
		
		// Create Center Bottom Div
		shadowDiv[6] = new Element('div');
		shadowDiv[6].setStyle({
			position: 'absolute',
			bottom: 0,
			right: shadowWidth + 'px',
			width: imageWidth + 'px',
			height: shadowWidth + 'px',
			backgroundImage: 'url("' + shadowURL + '")',
			backgroundPosition: (-shadowWidth) + 'px bottom',
			backgroundRepeat: 'no-repeat'
		});
		shadowContainer.insert({ bottom: shadowDiv[6] });
		
		// Create Center Right Div
		shadowDiv[7] = new Element('div');
		shadowDiv[7].setStyle({
			position: 'absolute',
			top: shadowWidth + 'px',
			left: 0,
			width: shadowWidth + 'px',
			height: imageHeight + 'px',
			backgroundImage: 'url("' + shadowURL + '")',
			backgroundPosition: 'left ' + (-shadowWidth) + 'px',
			backgroundRepeat: 'no-repeat'
		});
		shadowContainer.insert({ bottom: shadowDiv[7] });
		
		imageObject.replace(shadowContainer);
		
		shadowContainer.insert({ bottom: imageClone });
		
	});
	
	return false;
}

//Class: Carousel
//Assists in the rotation of Carousel Items
//IN DEVELOPMENT - NEED DEBUG ON BALANCE
var carousel = Class.create({

	initialize: function(container, direction){
		//console.log('Initialize Carousel');
		
		//Set DOM Containers
		//console.log('Set DOM Containers');
		this.carouselContainer = container;
		this.carouselItems = this.carouselContainer.select('> li');
		this.carouselContainer.setStyle({
			position: 'relative'
		});
		
		//Set Size Constraints
		//console.log('Set Size Constraints');
		this.size = this.carouselItems.size();
		this.currentItem = 0;
		this.previousItem = this.size;
		
		//Set Dimensions & Positioning
		//console.log('Set Dimensions & Positioning');
		this.dimensions = $H(this.carouselContainer.getDimensions());
		
		if(direction == 'vertical'){
			this.measure = 'height';
		}
		else {
			this.measure = 'width';
		}
		
		//console.log('Carousel Items', this.carouselItems);
		this.itemDimensions = $H(this.carouselItems[0].getDimensions());
		this.lastPosition = 0;
		
		var carouselPointer = this;
		
	/*	this.carouselItems.each(function(carouselItem, index){
			console.log('Measurement', carouselPointer.dimensions.get(carouselPointer.measure));
			carouselItem.setStyle({
				position: 'absolute',
				top: carouselPointer.lastPosition + 'px'
			});
			carouselPointer.lastPosition = carouselPointer.lastPosition + carouselPointer.itemDimensions.get(carouselPointer.measure);
		});*/
	},
	/*balance: function(){
		var totalDistance = 0;
		var carouselPointer = this;
		
		this.carouselItems.each(function(carouselItem){
			var itemDimensions = $H(carouselItem.getDimensions());
			var itemMeasure = itemDimensions.get(carouselPointer.measure);
			totalDistance = totalDistance + itemMeasure;
			console.log('Item Measure: ', itemMeasure);
		});
		
		console.log('Total Distance: ', totalDistance);
		
		if(totalDistance < this.dimensions.get(carouselPointer.measure)){
			var itemMeasure = this.dimensions.get(carouselPointer.measure);
			var measureDelta = this.dimensions.get(carouselPointer.measure) - totalDistance;
			
			var numItems = (measureDelta / itemMeasure).ceil();
			var numCycles = (numItems / this.size).ceil();
			var itemsPerCycle = this.size;
			
			var carouselPointer = this;
			var carouselContainer = this.carouselContainer;
			var carouselItems = this.carouselItems;
			
			numCycles.times(function(n){
				console.log('n: ', n);
				itemsPerCycle.times(function(m){
					console.log(m);
					var newItem = new Element('li');
					newItem.update(carouselItems[m].innerHTML);
					
					carouselContainer.insert({
						bottom: newItem
					});
					
					newItem.setStyle({
						position: 'absolute',
						top: carouselPointer.lastPosition + 'px'
					});
					
					carouselPointer.lastPosition = carouselPointer.lastPosition + carouselPointer.itemDimensions.get(carouselPointer.measure);
					
					carouselPointer.size++;
				});
			});
		}
	},*/
	get: function(itemIndex) {
		return this.carouselItems[itemIndex]
	},
	getChildren: function(){
		return this.carouselItems;
	},
	getIndex: function(){
		return { currentIndex: this.currentItem, previousIndex: this.previousItem};
	},
	move: function(itemMove){
		this.previousItem = this.currentItem;
		this.currentItem = (this.size + ((this.currentItem + itemMove) % this.size)) % this.size; //incrementally step up the index
		
		return { current: this.get(this.currentItem), previous: this.carouselItems[this.previousItem], currentIndex: this.currentItem, previousIndex: this.previousItem };
	},
	getCurrentItem: function(){
		return { current: this.carouselItems[this.currentItem], currentIndex: this.currentItem };
	}
});


//Photo Galleries
function photoGallery() {
	var photoGalleries = $$('ul.gallery');
	
	photoGalleries.each(function(photoGallery){
		var galleryCarousel = new carousel(photoGallery, 'horizontal');
		var galleryItems = galleryCarousel.getChildren();
		var galleryLock = false;
		
		//console.log('Gallery: ', galleryCarousel);
		//console.log('Gallery Items: ', galleryItems);
		
		//photoGallery.setStyle({
		//	height: galleryItems[0].getHeight() + 'px'
		//});
		
		photoGallery.addClassName('activated');
		
		var itemPosition = 0;
		galleryItems.each(function(galleryItem){

			galleryItem.setStyle({
				position: 'absolute',
				left: itemPosition + 'px'
			});
			
			var itemWidth = galleryItem.getWidth();
			itemPosition = itemPosition + itemWidth;
			
			galleryItem.observe('click', function(event){
				//window.log('Firing the Image Update Event');
				if(galleryExecuter){
					galleryExecuter.stop();
				}
				if(galleryLock == true){
					event.stop();
					return false;
				}
				document.fire('judson:imageUpdate', { imgSrc: galleryItem.down('a').href, caption: galleryItem.down('a').down('img').readAttribute('alt') });
				event.stop();
			});
		});
		
		var galleryNav = new Element('ul');
		galleryNav.addClassName('navGallery');
		photoGallery.insert({
			before: galleryNav
		});
		
		var galleryNavItems = new Array(2);
		galleryNavItems[0] = -1, galleryNavItems[1] = 1;
		
		galleryNavItems.each(function(galleryNavItem, index){
			//console.log('Inserting Gallery Nav: ', index);
		
			var moveIndex = galleryNavItem;
			
			galleryNavItem = new Element('li');
			if(index == 0){
				galleryNavItem.update('&lsaquo;');
			}
			else {
				galleryNavItem.update('&rsaquo;');
			}
			
			galleryNav.insert({
				bottom: galleryNavItem
			});
			
			galleryNavItem.observe('click', function(event){
				var galleryIndex = galleryCarousel.getIndex();
				
				if(moveIndex == -1 && galleryIndex.currentIndex == 0){
					return false;
				}
				else if (moveIndex == 1 && galleryIndex.currentIndex == (galleryItems.size() - 1)){
					return false;
				}
				else if (galleryLock == true){
					return false;
				}
				//console.log('Attempting Moving Gallery: ', moveIndex);
				photoGallery.fire('judson:galleryUpdate', { move: moveIndex });
				if(galleryExecuter){
					galleryExecuter.stop();
				}
			});
		});
		
		var galleryViewport = new Element('div');
		galleryViewport.addClassName('viewport');
		galleryNav.insert({
			before: galleryViewport
		});
		
		var galleryCaption = new Element('p');
		galleryCaption.setOpacity(.75);
		galleryViewport.insert({
			bottom: galleryCaption
		});
		
		var galleryImage = new Image();
		galleryImage.src = galleryItems[0].down('a').href;
		galleryImage.onload = function() {
			galleryViewport.insert({
				top: galleryImage
			});
			//galleryImage.writeAttribute('width', galleryImage.getWidth());
			//galleryImage.writeAttribute('height', galleryImage.getHeight());
		}
		
		galleryCaption.update(galleryItems[0].down('a').down('img').readAttribute('alt'));
		
		document.observe('judson:galleryUpdate', function(event){
			galleryLock = true;
			var itemMove = event.memo.move;
			//console.log('Moving Gallery: ', itemMove);
			
			var galleryUpdate = galleryCarousel.move(itemMove);
			var currentGalleryItem = galleryUpdate.current;
			var previousGalleryItem = galleryUpdate.previous;
			var previousWidth = 0;
			
			if(itemMove == 1){
				previousWidth = previousGalleryItem.getWidth();
			}
			else {
				previousWidth = currentGalleryItem.getWidth();
			}
			
			//console.log('Gallery Update: ', galleryUpdate);
			//console.log('Gallery Current Index: ', galleryUpdate.currentIndex);
			//console.log('Gallery Previous Index: ', galleryUpdate.previousIndex);
			//console.log('Previous Width: ', previousWidth);
			
			galleryItems.each(function(galleryItem){
				var currentPosition = galleryItem.getStyle('left');
				currentPosition = currentPosition.gsub('px', '');
				currentPosition = parseInt(currentPosition);
				//console.log('Current Position: ', currentPosition);
				
				var newPosition = (currentPosition - (itemMove * previousWidth));
				//console.log('New Position: ', newPosition);
				
				var animation = new S2.FX.Morph(galleryItem, {
					after: function(){ galleryLock = false; },
					style: 'left:' + newPosition + 'px', 
					transition: 'easeFromTo', 
					duration: .5
				});
				
				animation.play();
			});
			
		});
		
		document.observe('judson:imageUpdate', function(event){
			galleryLock = true;
			//window.log('Caught the Image Update Event');
			var imageSource = event.memo.imgSrc;
			var imageCaption = event.memo.caption;
			
			var carouselImage = new Image();
			carouselImage.src = imageSource;
			
			var oldImage = galleryViewport.down('img');
			
			var fadeOut = new S2.FX.Morph(oldImage, {
				after: function() {
					oldImage.remove();
					carouselImage.setOpacity(0);
					galleryViewport.insert({
						top: carouselImage
					});
					galleryCaption.update(imageCaption);
					fadeIn.play();
				},
				style: 'opacity: 0',
				transition: 'easeFromTo',
				duration: .5
			});
			
			var fadeIn = new S2.FX.Morph(carouselImage, {
				before: function() {
					var adjustHeight = new S2.FX.Morph(galleryViewport, {
						style: 'height: ' + carouselImage.getHeight() + 'px'
					});
					adjustHeight.play();
				},
				after: function() {
					galleryLock = false;
				},
				style: 'opacity: 1',
				transition: 'easeFromTo',
				duration: .5
			});
			
			carouselImage.onload = function(){
				fadeOut.play();
			}
			
			if(carouselImage.complete){
				fadeOut.play();
			}
			
		});
		
		var galleryExecuter = new PeriodicalExecuter(function(pe){
			
			var galleryIndex = galleryCarousel.getIndex();
			var moveIndex = 1;
			if (galleryIndex.currentIndex == (galleryItems.size() - 1)){
				pe.stop();
				return false;
			}
			
			photoGallery.fire('judson:galleryUpdate', { move: moveIndex });
			var currentGalleryItem = galleryCarousel.getCurrentItem();
			
			document.fire('judson:imageUpdate', { imgSrc: currentGalleryItem.current.down('a').href, caption: currentGalleryItem.current.down('a').down('img').readAttribute('alt') });
		},5);
	});
}

//Activate the carousel on the home page.
function carouselCall() {
	var carouselContainers = $$('ul.carousel');
	//console.log(carouselContainers);
	carouselContainers.each(function (carouselContainer) {
		var newCarousel = new carousel(carouselContainer, 'horizontal');
		//console.log(newCarousel);
		var carouselItems = newCarousel.getChildren();
		//console.log(carouselItems);
		carouselItems.each(function (carouselItem, index) {
			var content = carouselItem.down('section');
			var contentImage = carouselItem.down('img');

			contentImage.setStyle({
				opacity: 0
			});

			carouselItems[0].down('img').setStyle({
				opacity: 1
			});

			//console.log(contentImage);
			var contentHeight = content.getHeight();

			//console.log(contentHeight);

			content.setStyle({
				height: 0,
				position: 'static'
			});

			/*	content.down('a').setStyle({
			height: 0,
			display: 'none'
			});
			*/
			carouselItems[0].down('section').setStyle({
				height: 'auto'
			});

			/*carouselItems[0].down('a').setStyle({
			display: 'block',
			position: 'absolute',
			bottom: 0,
			height: 'auto',
			clear: 'both'
			});*/

			var bodyClass = $('main').hasClassName('large');
		//	console.log(bodyClass);

			if (bodyClass) {
				contentHeight = contentHeight + 80;
			}

			carouselItem.openAnimation = new S2.FX.Morph(carouselItem.down('section'), {
				style: 'height:' + contentHeight + 'px', transition: 'easeFromTo', duration: .5,
				after: function () {
					carouselItem.down('img').morph('opacity: 1', { duration: .2 });
				},
				before: function () {
					carouselItem.down('section').setStyle({
						display: 'block'
					});
					/*carouselItem.down('a').setStyle({
					display: 'block',
					height: 'auto'
					});*/
				}
			});

			carouselItem.closeAnimation = new S2.FX.Morph(carouselItem.down('section'), {
				style: 'height:' + 0 + 'px', transition: 'easeFromTo', duration: .5,
				after: function () {
					carouselItem.down('img').morph('opacity: 0', { duration: .5 });
				},
				before: function () {
					carouselItem.down('section').setStyle({
						display: 'none'
					});
				}
			});

			carouselItem.observe('click', function (event) {
				if (carouselItem.hasClassName('open')) {

				} else {
					var carouselIndex = newCarousel.getIndex();
					//console.log('Index: ', index, 'Current Index: ', carouselIndex.currentIndex);
					var itemMove = index - carouselIndex.currentIndex;
					var carouselUpdate = newCarousel.move(itemMove);
					//console.log('Carousel Update: ', carouselUpdate);

					carouselItems[carouselUpdate.currentIndex].openAnimation.play();
					carouselItems[carouselUpdate.previousIndex].closeAnimation.play();
					carouselItems[carouselUpdate.currentIndex].addClassName('open');
					carouselItems[carouselUpdate.previousIndex].removeClassName('open');
				}
			});
		});
	});
}

//First and Last LI Selector
//Note: Prototype Driven
function liFirstLast() {
	var firstLIs =	$$('ul > li:first-child');
	var lastLIs = $$('ul > li:last-child');
	
	firstLIs.each(function(liFirst) {
		liFirst.addClassName('first');
		});
		
	lastLIs.each(function(liLast) {
		liLast.addClassName('last');
	});
}

//External Link Helper
//Updates Links with External Relation to
//use target="_blank"
function externalLinks(){
	var links = $$('a[rel=external]');
	
	links.each(function(externalLink){
		externalLink.writeAttribute('target', '_blank');
	});
}

//Input Clear
//Clears text inputs on a page on focus
//Note: Prototype driven
function inputClear() {
	var textInputs = $$('input[type="text"]');
	
	textInputs.each(function(textInput){
		textInput.initialValue = textInput.value;
		textInput.observe('focus', function(event) {
			if(textInput.value == textInput.initialValue){
				textInput.clear();
			}
		});
		textInput.observe('blur', function(event){
			if(textInput.value.blank() == true) {
				textInput.value = textInput.initialValue;
			}
		});
	});
}


//Setup Zebra Striping Classing on all Tables.
function zebraStripe(){
	var evens = $$('section:nth-child(even)');
	
	if(evens) {
	  evens.each(function(even) {
		even.addClassName('even');
	  });
	}
}

// Cookie Functions
// Set the cookie 
function setCookie(name, value, expires, path, domain, secure) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

// Read the cookie 
function readCookie(name) { 
	var needle = name + "="; 
	var cookieArray = document.cookie.split(';'); 
	for(var i=0;i < cookieArray.length;i++) { 
		var pair = cookieArray[i]; 
		while (pair.charAt(0)==' ') { 
			pair = pair.substring(1, pair.length); 
		} 
		if (pair.indexOf(needle) == 0) { 
			return pair.substring(needle.length, pair.length); 
		} 
	} 
	return null; 
}

function calculatorHandling(){
	var calculators = $$('fieldset.calculator');
	
	if(!calculators) return false;
	
	function formatDollars(numberToFormat) {
		var numberToFormat = numberToFormat + '';
		var formattedNumber = numberToFormat.replace(/(\d{1,2}?)((\d{3})+)$/, "$1,$2");
		formattedNumber = formattedNumber.replace(/(\d{3})(?=\d)/g, "$1,");
		
		return '$' + formattedNumber;
	}
	
	function scrubNumber(number) {
		//Strip out and format number for calculator
		number = number.gsub('$', '');
		number = number.gsub(',', '');
		number = Number(number);
		
		return number;
	}
	
	calculators.each(function(calculator) {
		var calculatorFields = calculator.select('input');
		var calculatorTotals = calculator.select('ul.totals li');
		
		calculator.totals = [0,0];
		
		function updateCalculator(){
			calculator.totals = [0,0];
			
			calculatorFields.each(function(calculatorField){
				var inputValue = scrubNumber(calculatorField.getValue());
				
				if(calculatorField.up('label').hasClassName('subtract')){
					calculator.totals[0] = calculator.totals[0] - inputValue;
					calculator.totals[1] = calculator.totals[1] - inputValue;
				}
				else if(calculatorField.up('label').hasClassName('range')){
					var value1 = scrubNumber(calculatorField.getValue());
					
					window.log('addition value 1:', value1);
					
					calculator.totals[0] = calculator.totals[0] + value1;
					
					if(calculatorField.next('input')){
						var value2 =  scrubNumber(calculatorField.next('input.').getValue());
						calculator.totals[1] = calculator.totals[1] + value2;
						calculator.totals[0] = calculator.totals[0] - value2;
					}
					
					window.log('calculator.total 1:', calculator.totals[0]);
					window.log('calculator.total 2:', calculator.totals[1]);
				}
				else { //Assume Adding
					calculator.totals[0] = calculator.totals[0] + inputValue;
					calculator.totals[1] = calculator.totals[1] + inputValue;
				}
			});
			
			calculatorTotals.each(function(calculatorTotal){
				var numberToOutput = 0;
				if(calculatorTotal.hasClassName('subtotal')){
					if(calculator.totals[0] == calculator.totals[1]){
						numberToOutput = formatDollars(calculator.totals[0]);
					}
					else {
						numberToOutput = formatDollars(calculator.totals[0]) + ' to ' + formatDollars(calculator.totals[1]);
					}
				}
				/*else if (calculatorTotal.hasClassName('add')){
					var subtractionValue = scrubNumber(calculatorTotal.down('em').innerHTML);
					
					calculator.totals[0] = calculator.totals[0] + subtractionValue;
					calculator.totals[1] = calculator.totals[1] + subtractionValue;
					
					numberToOutput = calculatorTotal.down('em').innerHTML;
				}
				else if (calculatorTotal.hasClassName('subtract')){
					var subtractionValue = scrubNumber(calculatorTotal.down('em').innerHTML);
					
					calculator.totals[0] = calculator.totals[0] - subtractionValue;
					calculator.totals[1] = calculator.totals[1] - subtractionValue;
					
					numberToOutput = calculatorTotal.down('em').innerHTML;
				}*/
				else if (calculatorTotal.hasClassName('range')){
					//window.log('Hit a range');
					var subtractionValue1 = scrubNumber(calculatorTotal.down('em').innerHTML);
					var subtractionValue2 = scrubNumber(calculatorTotal.down('em').next('em').innerHTML);
					//window.log('Range is ', subtractionValue1, 'to', subtractionValue2);
					
					calculator.totals[0] = calculator.totals[0] - subtractionValue1;
					calculator.totals[1] = calculator.totals[1] - subtractionValue2;
					
					numberToOutput = calculatorTotal.down('em').innerHTML;
				}
				else { //Must be the total
					if(calculator.totals[0] == calculator.totals[1]){
						//numberToOutput = formatDollars(calculator.totals[0]);
					}
					else {
						//window.log('total 1:', calculator.totals[0]);
						//window.log('total 2:', calculator.totals[1]);
						if(calculator.totals[1] > calculator.totals[0]){
							numberToOutput = formatDollars(calculator.totals[0]) + ' to ' + formatDollars(calculator.totals[1]);
						}
						else {
							numberToOutput = formatDollars(calculator.totals[1]) + ' to ' + formatDollars(calculator.totals[0]);
						}	
					}
				}
				calculatorTotal.down('em').update(numberToOutput);
			});
		}
		
		updateCalculator();
		
		calculator.observe('keyup', function(event) {
			updateCalculator();
		});
	});
	
}

//Print Button
//Looks for anchors with the 'print' class
//Adds a hook of window.print to allow for print functionality. 
function printPage() {
	var printButtons = $$('p.print');
	
	if(!printButtons){
		return false;
	}
	
	printButtons.each(function(printButton){
		printButton.observe('click', function(event){
			window.print();
			event.stop();
		});
	});	
}


function shareThis(){
	var shareThisLinks = $$('ul.share li a');
	var pageTitles = $$('title');
	var pageTitle = pageTitles[0].innerHTML;
	
	//console.log(shareThisLinks);
	if(!shareThisLinks[0]) return false;
	shareThisLinks[0].observe('click', function(event){
		var currentURL = location.href;		//grab current URL
		this.writeAttribute('href', 'http://api.addthis.com/oexchange/0.8/forward/facebook/offer?url=' + currentURL + '&title=' + pageTitle + '&username=judsonretirement');
	});
	
	shareThisLinks[1].observe('click', function(event){
		var currentURL = location.href;		//grab current URL
		this.writeAttribute('href', 'http://api.addthis.com/oexchange/0.8/forward/twitter/offer?url=' + currentURL + '&title=' + pageTitle + '&username=judsonretirement&template=Look what I found at Judson: {{url}}');
	});	
}

//Adds Date and Time Picking functionality to form inputs with the classes:
//datepicker and timepicker 
function createPickers() {
	var dateInputs = $$('label.datepicker input');

	dateInputs.each(function (dateInput) {
		new Control.DatePicker(dateInput);
	});

	var timeInputs = $$('label.timepicker input');

	timeInputs.each(function (timeInput) {
		new Control.DatePicker(timeInput, { datePicker: false, timePicker: true, use24hrs: false });
	});
}


function fontToggler() {
	var fontSizer = $('fontSizer'); //Our font size toggling button
	var fontParameter = 'normal'; //Default parameter of normal set upon page load.
	var fontCookie = readCookie('judsonFonts');

	//Check cookie for large setting
	if (fontCookie == 'large') {
		fontParameter = 'large';

		$('main').toggleClassName('large');

		if ($('breakout')) {
			$('breakout').toggleClassName('large');
		}

		$('navMain').toggleClassName('large');

		fontSizer.toggleClassName('selected');

	}

	fontSizer.on('click', function (event) {
		if (fontParameter == 'normal') {
			fontSizer.toggleClassName('selected');

			fontSizer.blur(); //Blur the button as to not have any visual anomalies if someone clicks and drags.

			$('main').toggleClassName('large');

			if ($('breakout')) {
				$('breakout').toggleClassName('large');
			}

			$('navMain').toggleClassName('large');

			fontParameter = 'large'; //We made it large, lets keep track of that.

			setCookie('judsonFonts', 'large', 90, '/', '', ''); // set the cookie to remember this, and apply it to other pages.
		} else {
			fontSizer.toggleClassName('selected');

			fontSizer.blur(); //Blur the button as to not have any visual anomalies if someone clicks and drags.

			$('main').toggleClassName('large');

			if ($('breakout')) {
				$('breakout').toggleClassName('large');
			}

			$('navMain').toggleClassName('large');

			fontParameter = 'normal'; //We made it normal, lets keep track of that.

			setCookie('judsonFonts', 'normal', 90, '/', '', ''); // set the cookie to remember this, and apply it to other pages.
		}
	});
}


//Replacement for Window Onload - Loads before images, cross-browser
document.observe("dom:loaded", function () {
	fontToggler();
	//shareThis();
	printPage();
	borderImages();
	carouselCall();
	liFirstLast(); // Adds classes 'first' and 'last' to respective LIs
	zebraStripe();
	calculatorHandling();
	photoGallery();
	createPickers();
	externalLinks();
});

// usage: log('inside coolFunc',this,arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
	log.history = log.history || [];   // store logs to an array for reference
	log.history.push(arguments);
	if(this.console){
		console.log( Array.prototype.slice.call(arguments) );
	}
};

// catch all document.write() calls
(function(doc){
	var write = doc.write;
	doc.write = function(q){
		log('document.write(): ',arguments);
		if (/docwriteregexwhitelist/.test(q)) write.apply(doc,arguments); 
	};
})(document);
