//
// JavaScript Document - Created by David W Saunders
//
// choosePic() will randomly load backgrounds into the body tag
// 

var image = myPix = new Array("_images/IMG_3299_300_301_tonemapped.jpg",
						      "_images/_MG_5238.jpg",
							  "_images/sailingsunset.jpg", 
							  "_images/_MG_6309.jpg",
							  "_images/_MG_6374.jpg",
							  "_images/IMG_4293_2_1_tonemapped.jpg",
							  "_images/IMG_4308_7_6_tonemapped.jpg",
							  "_images/IMG_4311_10_09_tonemapped.jpg",
							  "_images/IMG_4323_2_1_tonemapped.jpg");

//
// This little bit of code picks and random number between 0 and the max
// size of the array which is currenty at 5 starting the count number
// at 0. As I add more images to the front page gallery the list will grow.
//

function choosePic(){
	randomNum = Math.floor((Math.random() * myPix.length));	
	image = myPix[randomNum];
	return image;
}


//
// This little bit of code loads the array
// And class the function to resize the image
//

window.addEvent('domready', function() {
	//preload images
	var aPreLoad = new Array();
	var aPreLoadi = 0;
	
	// resize the background please
	resize_background_image_now();	
});

//
// These lines will resize the photo to the correct size
// All my images are set to a aspect ratio of 2/3 so this bit will keep that ratio
//

window.addEvent('resize', resize_background_image_now);

function resize_background_image_now()
{	
	var bgimage = $('background').getElement('img');
	
	var ratio = 3/2;
	
	bgimage.set('width', window.getWidth());
	bgimage.set('height', window.getWidth() / ratio);
	
	
	if (bgimage.getStyle('height').toInt() < window.getHeight()) {
		bgimage.set('height', window.getHeight());
		bgimage.set('width', window.getHeight() * ratio);
	}
}
	


//
// This is some test code to see how far things have gotten
//

var test = "This is a test from javascript 1 2 3" + "<br>";

function print(){
	document.write( test )
	return;	
}
