// JavaScript Document
// for Luv-A-Duck interactive PDA

// assume event.js has been included
var replace_image_id = "pda_screen";
var image_root = "/images/projects/pda/";

var pda_images = [
		{ "link": "pda_1", "image": "login.gif" },
		{ "link": "pda_2", "image": "breeders_page.gif" },
		{ "link": "pda_3", "image": "breeders_flock_entry.gif" },
		{ "link": "pda_4", "image": "incorrect_data_entered.gif" },
		{ "link": "pda_5", "image": "no_data_entered_error.gif" },
		{ "link": "pda_6", "image": "growers_page.gif" },
		{ "link": "pda_7", "image": "growers_data_entry_page.gif" }
];

var offTimer = 0;

// clear the background image
function resetImage()
{
	if(offTimer > 0) {
		window.clearTimeout(offTimer);
	}
	$(replace_image_id).style.backgroundImage = "";
}

// called to mouseover a particular image
function mouseOver(img)
{
	if(offTimer > 0) {
		window.clearTimeout(offTimer);
	}
	$(replace_image_id).style.backgroundImage = "url('" + image_root + img + "')";
}

function mouseOut()
{
	// clear the screen on mouse-out after 300ms
	offTimer = window.setTimeout("resetImage()", 300);
}

function init()
{
	pda_images.each( function(pda_image) {
					// hook up the event handler for mouse-over
					addEvent($(pda_image.link), 'mouseover', function() { mouseOver(pda_image.image) });
					
					// and for mouse-out
					addEvent($(pda_image.link), 'mouseout', mouseOut);
					
					// and make the links not work
					addEvent($(pda_image.link), 'click', function() { return false; });
					
					// and set up the pre-load
					var i = new Image();
					i.src = image_root + pda_image.image;
				});
	
}

addEvent(window, 'load', init);