
/* List of available images */

var banner_images = [
	'building1.jpg',
	'crowd.jpg',
	'doctor.jpg',
	'dummy.jpg',
	'laser.jpg',
	'library.jpg',
	'staircase.jpg',
	'striped_shirt.jpg',
	'sweatshirts.jpg'
];


/* DON'T EDIT ANYTHING BEYOND THIS POINT */

var banner_images_dir = '/banner_images/';
var banner_image_width = 150; // pixels
var banner_image_height = 100; // pixels

function fill_banner_with_images() {

	// Settings
	var banner_indexes = $A([]);
	var last_index = -1;
	var i, random_index;
	var can_repeat_after = banner_images.length-1;
	
	// Scramble the order of the images
	var images_copy = banner_images;
	var scrambled_images = $A([]);
	var breaker = 0;
	while (images_copy.length) {
	
		// Just in case
		breaker++;
		if (breaker > 100) break;
	
		// Get random image index
		random_index = Math.floor(Math.random()*images_copy.length);
		
		// If invalid index (for whatever reason) try again
		if (random_index > images_copy.length) continue;
		
		// Add the image to the scrambled array
		scrambled_images.push(images_copy[random_index]);
		images_copy = images_copy.without(images_copy[random_index]);
		
	}
		
	// Build the banner
	var img;
	rows = 2; // should be one for interior pages
	var max_width = screen.width;
	rows.times( function (r) {
		var index = r==0 ? -1 : Math.ceil(scrambled_images.length/2)-1;
		// var curr_width = r==0 ? 0 : -Math.round(banner_image_width/2); // staggered
		var curr_width = 0;
		while (curr_width < max_width) {
			index++;
			if (index > scrambled_images.length-1) index = 0;
			img = document.createElement('img');
			img.src = banner_images_dir + scrambled_images[index];
			img.style.position = 'absolute';
			img.style.left = curr_width + 'px';
			img.style.top = r*banner_image_height + 'px';
			img.style.width = banner_image_width + 'px';
			img.style.height = banner_image_height + 'px';
			$('photobar').appendChild(img);
			curr_width += banner_image_width;
		}
	});
}
Event.observe(window, 'load', fill_banner_with_images);