function prepareLinks() {
	var links = $$('a');
	links.each(function(el) {
		if (el.getAttribute('rel')=='photobox') {
			el.addEvent('click', function() {
				popupImage(this);
				return false;
			});
		}
	});
}
var popBox = null;
function removePopBox() {
	if (popBox) {
		popBox.remove();
		popBox = null;
	}
}
var screenSize = Window.getSize();

function popupImage(obj) {
	removePopBox();
	var src = obj.getAttribute('href');
	
	if (screenSize.size.x && screenSize.size.y) {
		screenCenterX = (screenSize.size.x / 2);
		screenCenterY = (screenSize.size.y / 2);
		imageWidth = 504; // Average image width
		imageHeight = 504 + 25; // Average image width + approximate header size
		imageWidthOffset = imageWidth / 2;
		imageHeightOffset = imageHeight / 2;
		locationLeft = screenCenterX - imageWidthOffset; // Center of screen minus half the image's width to center the image
		//locationTop = screenCenterY - imageHeightOffset; // Center of screen minus half the image's height to center the image
		locationTop = obj.getTop();
	} else {
		locationLeft = obj.getLeft();
		locationTop = obj.getTop();
	}
		
	
	popBox = new Element('DIV', {
		'styles': {
			'position':'absolute',
			'left': locationLeft + 'px',
			'top': locationTop + 'px'
		},
		'class':'photobox'
	});
	popBoxClose = new Element('A', {
		'href':'#'
	});

	popBoxImage = new Element('IMG', {'src':src});
	popBoxImage.inject(popBox);
	
	popBoxClose.addEvent('click', function() {
		removePopBox();
		return false;
	});
	popBoxClose.setText('Close Window');
	popBoxClose.injectBefore(popBoxImage);
	
	popBox.addEvent('click', function() {
		removePopBox();
		return false;
	});
	popBox.injectInside(obj);
}

/* Rotating Images */

var ImageLink = function(src, href, alt) {
	this.src = src;
	this.href = href;
	//this.alt = alt;
}

var ImageLocation = function(imageObj) {
	this.imgId = imageObj.id;
	this.linkId = this.imgId + 'link';
	this.imgObj = imageObj;
	this.linkObj = $(this.linkId);
}

ImageLocation.prototype.loadNew = function(imgObj) {
	this.linkObj.setAttribute('href', imgObj.href);
	this.imgObj.setAttribute('src', imgObj.src);
	this.imgObj.setAttribute('alt', imgObj.alt);
}

ImageLocation.prototype.getSrc = function() { return this.imgObj.getAttribute('src'); }

var imageLocations = new Array();
var images = new Array();
var imageTimer = null;
var runTimer = true;
// Setup Image Locations
function setupImages() { 
	imageLocations[imageLocations.length] = new ImageLocation($('rotate1'));
	imageLocations[imageLocations.length] = new ImageLocation($('rotate2'));
	imageLocations[imageLocations.length] = new ImageLocation($('rotate3'));
	if (runTimer) imageTimer = setTimeout('getNextImgSet()', rotationInterval);
}

// Setup Images
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-1.jpg', 'http://www.axiscrane.com/assets/images/random/Random-1.jpg', 'AXIX Crane Photo 1');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-2.jpg', 'http://www.axiscrane.com/assets/images/random/Random-2.jpg', 'AXIX Crane Photo 2');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-3.jpg', 'http://www.axiscrane.com/assets/images/random/Random-3.jpg', 'AXIX Crane Photo 3');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-4.jpg', 'http://www.axiscrane.com/assets/images/random/Random-4.jpg', 'AXIX Crane Photo 4');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-5.jpg', 'http://www.axiscrane.com/assets/images/random/Random-5.jpg', 'AXIX Crane Photo 5');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-6.jpg', 'http://www.axiscrane.com/assets/images/random/Random-6.jpg', 'AXIX Crane Photo 6');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-7.jpg', 'http://www.axiscrane.com/assets/images/random/Random-7.jpg', 'AXIX Crane Photo 7');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-8.jpg', 'http://www.axiscrane.com/assets/images/random/Random-8.jpg', 'AXIX Crane Photo 8');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-9.jpg', 'http://www.axiscrane.com/assets/images/random/Random-9.jpg', 'AXIX Crane Photo 9');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-10.jpg', 'http://www.axiscrane.com/assets/images/random/Random-10.jpg', 'AXIX Crane Photo 10');

images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-11.jpg', 'http://www.axiscrane.com/assets/images/random/Random-11.jpg', 'AXIX Crane Photo 11');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-12.jpg', 'http://www.axiscrane.com/assets/images/random/Random-12.jpg', 'AXIX Crane Photo 12');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-13.jpg', 'http://www.axiscrane.com/assets/images/random/Random-13.jpg', 'AXIX Crane Photo 13');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-14.jpg', 'http://www.axiscrane.com/assets/images/random/Random-14.jpg', 'AXIX Crane Photo 14');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-15.jpg', 'http://www.axiscrane.com/assets/images/random/Random-15.jpg', 'AXIX Crane Photo 15');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-16.jpg', 'http://www.axiscrane.com/assets/images/random/Random-16.jpg', 'AXIX Crane Photo 16');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-17.jpg', 'http://www.axiscrane.com/assets/images/random/Random-17.jpg', 'AXIX Crane Photo 17');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-18.jpg', 'http://www.axiscrane.com/assets/images/random/Random-18.jpg', 'AXIX Crane Photo 18');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-19.jpg', 'http://www.axiscrane.com/assets/images/random/Random-19.jpg', 'AXIX Crane Photo 19');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-20.jpg', 'http://www.axiscrane.com/assets/images/random/Random-20.jpg', 'AXIX Crane Photo 20');

images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-21.jpg', 'http://www.axiscrane.com/assets/images/random/Random-21.jpg', 'AXIX Crane Photo 21');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-22.jpg', 'http://www.axiscrane.com/assets/images/random/Random-22.jpg', 'AXIX Crane Photo 22');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-23.jpg', 'http://www.axiscrane.com/assets/images/random/Random-23.jpg', 'AXIX Crane Photo 23');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-24.jpg', 'http://www.axiscrane.com/assets/images/random/Random-24.jpg', 'AXIX Crane Photo 24');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-25.jpg', 'http://www.axiscrane.com/assets/images/random/Random-25.jpg', 'AXIX Crane Photo 25');
images[images.length] = new ImageLink('http://www.axiscrane.com/assets/images/random/thumb/Random-26.jpg', 'http://www.axiscrane.com/assets/images/random/Random-26.jpg', 'AXIX Crane Photo 26');


// Configuration Values
var rotationInterval = 3000; // Interval to wait before rotating images; Equals [seconds] x 1000.
var numImages = 3; // Number of images curretly in random display
var uniqueThreshold = 9; // Current image must be unique for the past [uniqueThreshold] number of images, including the number in the current display set.  Minimum should be [numImages] to prevent potential duplicates from appearing within the same set of images

function getFileName(full_path) {
	file_split = full_path.split('/');
	return file_split[file_split.length-1];
}

lastImages = new Array();
function getNextImgSet() {
	var queue = new Array();

	for (i=0; i < numImages; i++) {
		sameImage = true;
		while (sameImage) {
			var randNum = Math.round(Math.random()*(images.length-1));
			found = false;
			
			for (x=0; x < lastImages.length; x++){
				if (getFileName(lastImages[x].src) == getFileName(images[randNum].src)) {
					found = true;
				}
			}
			sameImage = found;
		}
		queue[queue.length] = images[randNum];
		lastImages.push(queue[queue.length-1]);
		if (lastImages.length > uniqueThreshold) {
			lastImages.shift();
		}
	}
	
	for (i=0; i < queue.length; i++) {
		imageLocations[i].loadNew(queue[i]);
	}
	
	if (runTimer) imageTimer = setTimeout('getNextImgSet()', rotationInterval);
	
}
