$(document).ready(function(){

	var onExtension = "_on";

	// Image hover swapping
	$('.hoverSwap').mouseover(function(){
		
		if (checkOnState($(this).attr('src'),onExtension) == false)
		{
			$(this).attr('src',getImageSourceWithoutExtension($(this).attr('src')) + onExtension + "." + getFileExtension($(this).attr('src')));
		}
	
	});
	
	$('.hoverSwap').mouseout(function(){
		
		if (checkOnState($(this).attr('src'),onExtension) == true)
		{
			$(this).attr('src',getImageSourceWithoutOn(getImageSourceWithoutExtension($(this).attr('src')),onExtension) + "." + getFileExtension($(this).attr('src')));
		}
	
	});

});

function checkOnState(strImageSource,strOnExtension)
{
	sourceWithoutExtension = getImageSourceWithoutExtension(strImageSource);
		
	if (sourceWithoutExtension.substring(sourceWithoutExtension.length - 3) == strOnExtension)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function getImageSourceWithoutExtension(strImageSource)
{
	return strImageSource.substring(0,getPositionOfPeriod(strImageSource));
}

function getImageSourceWithoutOn(strImageSource,strOnExtension)
{
	return strImageSource.substring(0,strImageSource.length - strOnExtension.length);
}

function getPositionOfPeriod(strImageSource)
{
	return strImageSource.lastIndexOf(".");
}

function getFileExtension(strImageSource)
{	
	return strImageSource.substring(getPositionOfPeriod(strImageSource)+1);
}


