(function($) {
	
	var cache = [];
	
	$.fn.preload = function() {
		return this.each(function() {
			var imageCache = document.createElement('img');
			imageCache.src = this;
			cache.push(imageCache);
		});
	};
	
	$.fn.navHighlight = function() {
		return this.each(function() {
			if (($(this).text() === "Shop" && $('title').text().match(/Welcome$/))
				|| ($(this).text() === "View Cart" && $('title').text().match(/Your Shopping Cart$/))
				|| $('title').text().match($(this).text() + "$"))
			{
				$(this).css('color', 'black').css('font-weight', 'bold');
			}
		});
	};		
	
	$(document).ready(function() {
		
		$(".nav-link").navHighlight();
		
		$(".img-swap").hover(
			function() {
				this.src = this.src.replace("-grey", "-black");
			},
			function() {
				this.src = this.src.replace("-black", "-grey");
			});

		// Cache a few images
		$(['images/facebook-button-black.png','images/twitter-button-black.png']).preload();
	});

})(jQuery);

