// hoverableImage.js (Website Framework) || Version: 0.00 || Last Updated: 2011-08-10 17:00 || Updated by: Hidde-Finne Peters || Created: 2011-08-10 by Jelle Kingma
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------
//	0.00:	Evolved from the imageButton.js, simply works on any element of element type "img" or "input[type=img]" with class "hoverable"
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

function initializeHoverableImages () {
	var elements = jQuery.merge($("img.hoverable"), $("input[type=image].hoverable"));
	elements.each(function () {
		initializeHoverableImage($(this));
	});
}

// Supplied element is expected to be a jquery object!
function initializeHoverableImage (element) {
	if (element.length > 0 && element.attr('src')) {
		preloadHoverableImage(element);
		element.mouseover(function() {
			element.attr('src', element.attr('src').replace(new RegExp('_default\\b'), '_hover'));
		});
		element.mouseout(function() {
			element.attr('src', element.attr('src').replace(new RegExp('_hover\\b'), '_default'));
		});
	}
}

function preloadHoverableImage (element) {
	var copy = element.clone(true);
	copy.attr('src', copy.attr('src').replace(new RegExp('_default\\b'), '_hover'));
	copy.load(function() {
		copy.remove();
	});
}

$('document').ready(initializeHoverableImages);
