(function($)
{
	var cache = [];
	// Arguments are image paths relative to the current page.
	$.preLoadImages = function()
	{
		var args_len = arguments.length;
		for (var i = args_len; i--;)
		{
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
})(jQuery)


$(document).ready(function()
{

	jQuery.preLoadImages("/images/remodeling-description-green.png","/images/remodeling-description.png","/images/remodeling-projects-02.png");
	
// HOMEPAGE
	$("#ad").click(function(event)
	{
		$(this)
			.css("background-image","url('/images/homepage-ad2.jpg')");
		$(this)
			.find("img")
			.fadeOut(1200);
		$(this).css("cursor","inherit");
		event.preventDefault();
	});

// FINISHES
	var thumbnails = $("#finishes-examples > a");

	thumbnails.mouseover(function ()
	{
		var img = $(this).find("img");
		var src = img.attr("src");
		var icon = "/images/zoom.png";
		$(this).data("src",src);
		var imgUrl = "url('" + src +"')";

		$(this).css("background-image",imgUrl);
		img.attr("src",icon);
		img.attr("width","16");
		img.attr("height","16");
	});
	thumbnails.mouseout(function ()
	{
		var img = $(this).find("img");
		var src = $(this).data("src");
		var imgUrl = "url('" + src +"')";

		$(this).css("background-image",imgUrl);
		img.attr("width","70");
		img.attr("height","70");
		img.attr("src",src);
	});

// REMODELING

// CONTACT US
	$("#showroom > img:first").wrap('<div id="showroom-img-wrapper" />');
	var wrapper = $("#showroom-img-wrapper");
	
	var addImages = '<img src="/images/contactus-showroom-1.jpg" /><img src="/images/contactus-showroom-2.jpg" /><img src="/images/contactus-showroom-3.jpg" /><img src="/images/contactus-showroom-4.jpg" /><img src="/images/contactus-showroom-5.jpg" /><img src="/images/contactus-showroom-6.jpg" /><img src="/images/contactus-showroom-7.jpg" /><img src="/images/contactus-showroom-8.jpg" /><img src="/images/contactus-showroom-9.jpg" />';

	wrapper.html(addImages);

	$.fn.cycle.defaults = { 
	    timeout:       4800,  // milliseconds between slide transitions (0 to disable auto advance) 
	    speed:         1000,  // speed of the transition (any valid fx speed value) 
	    height:       'auto', // container height 
	    sync:          1,     // true if in/out transitions should occur simultaneously 
	    pause:         1,     // true to enable "pause on hover" 
	    delay:         2400     // additional delay (in ms) for first transition (hint: can be negative) 
	};	
	wrapper.cycle();






	var mainIcon = $("#top > #icon");
	var description = $("#top > #description");
	var altIcons = $("#alternatives > a");
	var green = "/images/remodeling-icon-green.png";

	$("#icon").find("img:first").remove();
//	$("#top").addClass("green");
	//$("#description").find("img:first").remove();
	//$("#top").removeClass();

	altIcons
		.mouseover(function()
		{
			var altImg = $(this).find("img:first"); // Alt Icon's image
			var imgUrl = altImg.attr("src"); // Alt Icon's Img Url
//			var descImgUrl = imgUrl.replace("icon","description"); // Description Img Url
			var current = $(this).attr("id"); // Type of icon

			altImg.data("url",imgUrl);

			$(this).find("img:first").remove();
			$(this).addClass("current"); // !
			description.find("img:first").remove();
			mainIcon.css("background-image","url('" + imgUrl + "')");
			$("#top").addClass(current);
			mainIcon.html('<img src="/images/remodeling-icon-' + current + '.png" />');
			//mainIcon.find("img:first").attr("src","/images/remodeling-icon-" + current + ".png").fadeIn();

//			mainIcon.css("background-image","url('" + green + "')");
//			mainIcon.find("img:first").fadeOut("fast");
//			description.css("background-image","none");
//			$("#top").class(current);
//			altImg.fadeOut("slow");
			//img.attr('src','/images/remodeling-icon-green.png');
//			iconMain.attr('src',imgUrl);

		})
		.mouseout(function()
		{
			var altImg = $(this).find("img:first");
			var origUrl = altImg.data("url");

			mainIcon.css("background-image","url('" + green + "')");
			$(this).removeClass("current");
			$("#top").removeClass();
			mainIcon.find("img:first").attr("src",green);
//			$(this).removeClass(); // !
			//	$(this).removeClass("current");
			//description.attr('src','/images/remodeling-description.png');
			//iconMain.attr('src','/images/remodeling-icon-green.png');
			//img.attr('src',origUrl);
		})



});





/*
	var iconMain = $("#top > #icon");
	var description = $("#top > #description");
	var altItems = $("#alternatives > a");

	altItems.hover(
		function () {
			var img = $(this).find("img");
			var imgUrl = img.attr("src");
			img.data("url",imgUrl);
			var descImgUrl = imgUrl.replace("icon","description");
//						img.fadeOut("fast");
			img.attr('src','/images/remodeling-icon-green.png');
			iconMain.attr('src',imgUrl);
			description.attr('src',descImgUrl);
		}, 
		function () {
			var img = $(this).find("img");
			var origUrl = img.data("url");
			description.attr('src','/images/remodeling-description.png');
			iconMain.attr('src','/images/remodeling-icon-green.png');
			img.attr('src',origUrl);
		}
	);


*/
/*
	altItems.mouseover(function()
	{
		var img = $(this).find("img");
		var imgUrl = img.attr("src");
		var descImgUrl = imgUrl.replace("icon","description");

		img.data("url",imgUrl);

		img.fadeOut(300, function()
		{
//			iconMain.fadeOut(300);
//			description.fadeOut(300);
		});
		iconMain.attr('src',imgUrl).fadeIn(300, function()
		{
			$(this).attr('src','/images/remodeling-icon-green.png');
			description.attr('src',descImgUrl);
		});
	}).mouseout(function()
	{
//		$("div.nav-" + myClass).fadeOut(300, function()
//		{
//			$(this).remove();
//		});
	});



*/




// currentIcon.remove();
// currentDesc.remove();
// altIcons.find("img").remove();
/*
$(document).ready(function()
{
	var currentIcon = $("#icon > img");
	var currentDesc = $("#description > img");
	var altIcons = $("#alternatives > a");

	currentIcon.remove();
	currentDesc.remove();
	altIcons.find("img").remove();

	altIcons.hover(
		function () {
			var type = $(this).attr("id");

			$(this).addClass("current");
		//	$("#top").addClass(type).fadeIn("slow");
			var html = '<div style="background: url(' + "'/images/remodeling-icons.png'" + ') no-repeat 0 -45px; width: 90px; height: 90px;"></div>';
			$("#icon").show(function(){
				$(this).html(html);
			});
		},
		function () {
			var type = $(this).attr("id");

			$(this).removeClass("current");

			$("#top")
				.removeClass()
				.addClass("green");
		}
	);
*/
//		altIcons.click();

/*


});
*/

