jQuery.preloadImages = function()
{	for (var i = 0; i < arguments.length; i++)
	{	jQuery("<img>").attr("src", arguments[i]);	}
};

$(document).ready(function(){
	// preload main navigation images
	$.preloadImages(
		"images/navAbout-over.gif", 
		"images/navPortfolio-over.gif", 
		"images/navDevelopments-over.gif",  
		"images/navHome-over.gif",  
		"images/navNews-over.gif",  
		"images/navShowroom-over.gif", 
		"images/navVisitUs-over.gif", 
		"images/hideTextBar.gif", 
		"images/showTextBar.gif"
	);
	
	// main navigation rollovers
	$('#mainNav a img:not(.current)').hover(
		function () {
			// Nav image rollover
			var source = $(this).attr('src');
			var newSource = source.replace(".gif", "-over.gif");
			$(this).attr('src', newSource);
		}, 
		function () {
			// Nav image rollout
			var source = $(this).attr('src');
			var newSource = source.replace("-over.gif", ".gif");
			$(this).attr('src', newSource);
		}
	);
	
	// Content show/hide
	var contentHeight = $('.imgContent').height();
	$("a#showHide").click(function()
	{	var imageTag = $("a#showHide").html();
		if ( $(this).hasClass("hide") )
		{	var newImageTag = imageTag.replace(/hide/gi, "show");
			$(this).removeClass('hide').addClass('show').empty().append(newImageTag);
			$(".imgContent").animate({ 
				paddingTop: 0,
				paddingBottom: 0,
				height: 14
			}, 400 );
			$(".imgContent > :not(.show)").fadeOut('fast');
		}
		else if ( $(this).hasClass("show") )
		{	var newImageTag = imageTag.replace(/show/gi, "hide");
			$(this).removeClass('show').addClass('hide').empty().append(newImageTag);
			$(".imgContent").animate({ 
				paddingTop: '24px',
				paddingBottom: '10px',
				height: contentHeight+"px"
			}, 400 );
			$(".imgContent > :not(.hide)").fadeIn('fast');
		}
		return false;
	});
	
	// for certain gallery pages
	$(".divControlsLinks a").click(function(e) {
		e.preventDefault();
		$("#imgContainer").empty();
		$("#imgContainer").html('<img src="' + $(this).attr("href") + '" title="" alt="" />');
		return false;
	});
});


