/**
* swaps image arounds on mouse events down/up and over
*
*@param object		a jquery object
*@param handler		the type of handler mousedown, mouseup, mouseover & mouseout
*/
function swapMenuImages(object, handler) {

	var image = $(object).attr('src');
	var match = image.match(/([^_]+)(.*).(png|gif|jpg)/);
	if(match===null)	return;

	switch(handler) {
		case 'mousedown':
			$(object).attr('src', match[1]+'_on.'+match[3]);
			break;
		case 'mouseup':
		case 'mouseover':
			$(object).attr('src', match[1]+'_over.'+match[3]);
			break;
		case 'mouseout':
			$(object).attr('src', match[1]+'.'+match[3]);
			break;
	}
}


$(document).ready(function() {
	if($('img.button').length>0) {
		$('img.button').mousedown(function() {
			swapMenuImages(this, 'mousedown');
		});
		$('img.button').mouseup(function() {
			swapMenuImages(this, 'mouseup');
		});
		$('img.button').mouseout(function() {
			swapMenuImages(this, 'mouseout');
		});
		$('img.button').mouseover(function() {
			swapMenuImages(this, 'mouseover');
		});

		$('img.button').each(function() {
			var image = $(this).attr('src');
			var match = image.match(/([^_]+)(.*).(png|gif|jpg)/);
			if(match!==null) {				
				$('body').append('<img src="'+match[1]+'_on.'+match[3]+'" alt="" border="0" width="1" height="1" class="displayNone" />');
				$('body').append('<img src="'+match[1]+'_over.'+match[3]+'" alt="" border="0" width="1" height="1" class="displayNone" />');
			}
		});
	}


});
