//jQuery.noConflict();
(function($){
	var swap_image = function(e, src, type) {
		type = type != null ? type : 'OUT';
		switch (type) {
		case 'OVER':
			$(this).attr('src', this.$overIMG.attr('src'));
			break;
		case 'DOWN':
			$(this).attr('src', this.$downIMG.attr('src'));
			break;
		case 'OUT':
			$(this).attr('src', this.defaultSrc);
			break;
		}
	};
	
	$(document).ready(function() {
		$('img.swap-image')
		.bind("swap_image", swap_image)
		.each(function() {
			this.defaultSrc = $(this).attr('src');
			if ($(this).hasClass('swap-image-OVER')) {
				this.$overIMG = $('<img src="' + $(this).attr('src').replace(/^(.*)_OUT.(.*)$/, '$1_OVER.$2') + '"/>')
			}
			if ($(this).hasClass('swap-image-DOWN')) {
				this.$downIMG = $('<img src="' + $(this).attr('src').replace(/^(.*)_OUT.(.*)$/, '$1_DOWN.$2') + '"/>')
			}
		})
		;
		$('.swap-image-trigger')
		.each(function() {
			this.$targets = $($(this).attr('class').match(/swap-image\{([^\}]+)\}/)[1])
			this.$overtargets = this.$targets.filter('.swap-image-OVER');
			this.$downtargets = this.$targets.filter('.swap-image-DOWN');
			
			$(this).bind("mouseenter", function() {this.$overtargets.trigger("swap_image", [this, 'OVER']);});
			$(this).bind("mouseleave", function() {this.$overtargets.trigger("swap_image", [this, 'OUT']);});
		})
		;
	});
})(jQuery);
