// gallery vars to keep track of animations
var curHomeImgElmnt;
var lastHomeImgElmnt;
var loadedOnce = false;
var clickedOnce = false;
var origX;
var origY;
var yMoveDist = 340;
var newImgStr;
var newGalleryHtml;
var imgPreloader;

// initialization
function initGallery()
{
	// find elements that we load images into and slide around
	curHomeImgElmnt = $('homeGalleryImg1');
	lastHomeImgElmnt = $('homeGalleryImg2');
	
	// start gallery if elements exist
	if( curHomeImgElmnt )
	{
		curHomeImgElmnt.zIndex = 11;
		lastHomeImgElmnt.zIndex = 10;
//		setTimeout("loadFirstImage()",1000);
		//setTimeout("loadFirstGallery()",1000);
	}
}

// auto-load the first image
function loadFirstImage()
{
	// grab all thumb links
	var imgLinks = $$('.homeImgLink');
	
	// call the javascript link in the first thumbnail button
	var pureJsCall = imgLinks[0].href.replace('javascript:','');
	eval( pureJsCall );	
}

// respond to a thumbnail click and kcik off a new image load
function homePic( image )
{
	imgPreloader = new Image();									// new image loader obj
	newImgStr = '<div><img src="' + image + '" /></div>';		// create new html to insert
	imgPreloader.onload = fadeNewImg;							// image loaded callback
	imgPreloader.src = image;									// kick off the preload
}

// fade in an image the first time... slide images after that
function fadeNewImg()
{
	// swap references to the current div that we're loading into
	lastHomeImgElmnt = curHomeImgElmnt;
	if( curHomeImgElmnt == $('homeGalleryImg1') )
		curHomeImgElmnt = $('homeGalleryImg2');
	else
		curHomeImgElmnt = $('homeGalleryImg1');
	
	curHomeImgElmnt.style.zIndex = 11;
	lastHomeImgElmnt.style.zIndex = 10;
	
	// load image into current container and hide initially
	curHomeImgElmnt.hide();
	curHomeImgElmnt.update( newImgStr );
	
	// fade new img in
	Effect.AppearTweaked( curHomeImgElmnt, { duration:.9 } );
	
}

Event.observe(window, 'load', initGallery, false);
