$(function() {

	$('a.rolloverimage').each(function() {
		
		$([$('img', this).attr('src')]).preload();
		
		if (!$(this).hasClass('active')) { return; };
		
		var imagePathInfo = $('img', this).attr('src').replace('_over', '').split('.');
		var imagePath = imagePathInfo.slice(0, -1).join('.');
		var imageExtension = imagePathInfo[imagePathInfo.length - 1];
		
		$('img', this).attr('src', imagePath + '_over' + '.' + imageExtension);
		
	});
	
	$('a.rolloverimage').mouseenter(function() {
		
		var imagePathInfo = $('img', this).attr('src').replace('_over', '').split('.');
		var imagePath = imagePathInfo.slice(0, -1).join('.');
		var imageExtension = imagePathInfo[imagePathInfo.length - 1];
	
		$('img', this).attr('src', imagePath + '_over' + '.' + imageExtension);
		
	}).mouseleave(function() {
		
		if ($(this).hasClass('active') || $(this).hasClass('over')) { return; };
		
		var imagePathInfo = $('img', this).attr('src').replace('_over', '').split('.');
		var imagePath = imagePathInfo.slice(0, -1).join('.');
		var imageExtension = imagePathInfo[imagePathInfo.length - 1];
	
		$('img', this).attr('src', imagePath + '.' + imageExtension);
		
	});

	$('#rtsearch, #rtmemberlogin').mouseenter(function() {
		var headerImageName = $(this).find('.rtheader img').attr('name');
		
		$(this).find('.rtheader img').attr('src', 'images/common/'+headerImageName+'_over.gif');
	}).mouseleave(function() {
		var headerImageName = $(this).find('.rtheader img').attr('name');
		
		$(this).find('.rtheader img').attr('src', 'images/common/'+headerImageName+'.gif');
	});
	
	$('input[type=image]').mouseenter(function() {
		var imageName = $(this).attr('name');
		
		$(this).attr('src', 'images/common/'+imageName+'_over.gif');
	}).mouseleave(function() {
		var imageName = $(this).attr('name');
		
		$(this).attr('src', 'images/common/'+imageName+'.gif');
	});
	
});

var basehref = $('base').attr('href');

$.fn.preload = function() {
    this.each(function() {
        (new Image()).src = this;
    });
}
