/* ffw.js - Implementation of the Floor Finder Widget */

// HTML for Each Step...

var ffwStepOne = "<div id=\"ffwStepOne\"><h4>For what room are you considering new flooring?</h4> <a href=\"#ffwLiving\" id=\"ffwStepOneOption-Living\">Living/Den</a> <a href=\"#ffwBed\" id=\"ffwStepOneOption-Bed\">Bedroom</a> <a href=\"#ffwBath\" id=\"ffwStepOneOption-Bath\">Bath</a> <a href=\"#ffwKitchen\" id=\"ffwStepOneOption-Kitchen\">Kitchen</a></div>";

var ffwStepTwo = "<div id=\"ffwStepTwo\"><h4>Next, who will be using the room?</h4><div><input type=\"checkbox\" id=\"ffwStepTwoOption-Adults\" /><label for=\"ffwStepTwoOption-Adults\">Adults</label></div><div><input type=\"checkbox\" id=\"ffwStepTwoOption-Teens\" /><label for=\"ffwStepTwoOption-Teens\">Teenagers</label></div><div><input type=\"checkbox\" id=\"ffwStepTwoOption-Kids\" /><label for=\"ffwStepTwoOption-Kids\">Children</label></div><div><input type=\"checkbox\" id=\"ffwStepTwoOption-Pets\" /><label for=\"ffwStepTwoOption-Pets\">Pets</label></div><div id=\"ffwStepTwo-Submit-Holder\"><a href=\"#ffwStepTwo\" id=\"ffwStepTwo-Submit\">Next &rsaquo;</a></div></div>";

var ffwStepThree = "<div id=\"ffwStepThree\"><a href=\"#ffwModern\" id=\"ffwStepThreeOption-Modern\">Modern</a><a href=\"#ffwTraditional\" id=\"ffwStepThreeOption-Traditional\">Traditional</a></div>";

var ffwStepResult = "<div id=\"ffwStepResult\"><p><img src=\"\" /><span></span></p><a href=\"#\" id=\"ffwResultsOutbound\">View more products suited to you</a> or <a href=\"#reset\" id=\"ffwReset\">start over</a>.</div>";

// Results Array...

var ffwResults = {
		'Bath--Modern': {
			'desc': 'Opt for durable and gorgeous ceramic tile in a light tone with bold, dark glass inserts to add a touch of modern elegance.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/bath--modern.jpg',
			'url': 'http://www.carpetone.com/flooringtool/bathmodern'
		},
		'Bath--Traditional': {
			'desc': 'Large, stone tiles will give your bathroom a timeless, traditional look.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/bath--traditional.jpg',
			'url': 'http://www.carpetone.com/flooringtool/bathtraditional'
		},			
		'Bed-Pets-Modern': {
			'desc': 'An easy-to-clean, light colored laminate with subtle variations in tone and the appearance of hardwood sets the stage for a modern flooring option.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/bed-pets-modern.jpg',
			'url': 'http://www.carpetone.com/flooringtool/bedpetsmodern'
		},
		'Bed-Pets-Traditional': {
			'desc': 'Check out laminate options in luxurious brown tones and a narrow plank appearance. This traditional option will also stand the test of time with your pets.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/bed-pets-traditional.jpg',
			'url': 'http://www.carpetone.com/flooringtool/bedpetstraditional'
		},
		'Bed-Kids-Modern': {
			'desc': 'The bold texture of frieze carpet gives your room a modern look while multi-colored fibers are a great option for active households.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/bed-kids-modern.jpg',
			'url': 'http://www.carpetone.com/flooringtool/bedkidsmodern'
		},
		'Bed-Kids-Traditional': {
			'desc': 'Select a bold-colored carpet for a lush look. It&rsquo;s stylish, comfortable and long-lasting &mdash; what more can you ask for?',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/bed-kids-traditional.jpg',
			'url': 'http://www.carpetone.com/flooringtool/bedkidstraditional'
		},
		'Bed-Teens-Modern': {
			'desc': 'For a modern style, your teens are sure to turn to lively patterned carpets.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/bed-teens-modern.jpg',
			'url': 'http://www.carpetone.com/flooringtool/bedteensmodern'
		},
		'Bed-Teens-Traditional': {
			'desc': 'Soft, deep cut pile in any tone warms up traditional bedrooms, and today&rsquo;s durable fibers keep it looking great for years to come.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/bed-teens-traditional.jpg',
			'url': 'http://www.carpetone.com/flooringtool/bedteenstraditional'
		},
		'Bed-Adults-Modern': {
			'desc': 'Long, narrow planks of hardwood in light and subtle tones set the stage for a modern bedroom.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/bed-adults-modern.jpg',
			'url': 'http://www.carpetone.com/flooringtool/bedadultsmodern'
		},
		'Bed-Adults-Traditional': {
			'desc': 'For an elegant and traditional bedroom, select deep toned carpets with curving organic textures.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/bed-adults-traditional.jpg',
			'url': 'http://www.carpetone.com/flooringtool/bedadultstraditional'
		},
		
		
		'Living-Pets-Modern': {
			'desc': 'A high-traffic area like a living room calls for a durable flooring option like laminate. Choose a high-contrast wood tone for a modern look that is easy to maintain.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/living-pets-modern.jpg',
			'url': 'http://www.carpetone.com/flooringtool/livingpetsmodern'
		},
		'Living-Pets-Traditional': {
			'desc': 'Deep tones in rich maples exude the warmth and timeless qualities you&rsquo;ll want underfoot. Modern laminate makes it durable and easy to maintain.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/living-pets-traditional.jpg',
			'url': 'http://www.carpetone.com/flooringtool/livingpetstraditional'
		},
		'Living-Kids-Modern': {
			'desc': 'Try an exotic looking laminate to enhance your contemporary space with easy-care style.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/living-kids-modern.jpg',
			'url': 'http://www.carpetone.com/flooringtool/livingkidsmodern'
		},
		'Living-Kids-Traditional': {
			'desc': 'For a comfortable, traditional option in your living room, opt for a multicolored loop carpet. Today&rsquo;s technology makes it soft while the multi-colored fibers suit the lifestyle of active families.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/living-kids-traditional.jpg',
			'url': 'http://www.carpetone.com/flooringtool/livingkidstraditional'
		},
		'Living-Teens-Modern': {
			'desc': 'A carpet with a new pattern will add a modern touch to your living room. Check out the newest geometric patterns or add an animal print pattern to really spice up your room.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/living-teens-modern.jpg',
			'url': 'http://www.carpetone.com/flooringtool/livingteensmodern'
		},
		'Living-Teens-Traditional': {
			'desc': 'You can&rsquo;t go wrong with a traditional multicolored berber. It&rsquo;s a functional, great looking flooring option for your high-traffic living room.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/living-teens-traditional.jpg',
			'url': 'http://www.carpetone.com/flooringtool/livingteenstraditional'
		},
		'Living-Adults-Modern': {
			'desc': 'Step out with something truly out of the ordinary - blonde hardwood flooring! This modern option sets up your living room for your own distinctive look.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/living-adults-modern.jpg',
			'url': 'http://www.carpetone.com/flooringtool/livingadultsmodern'
		},
		'Living-Adults-Traditional': {
			'desc': 'Dark, wide hardwood planks with beveled edges and textured appearance lend a timeless look to a traditional living space.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/living-adults-traditional.jpg',
			'url': 'http://www.carpetone.com/flooringtool/livingadultstraditional'
		},
		
		
		'Kitchen-Pets-Modern': {
			'desc': 'Skip the squares and go with long rectangular tiles for an updated kitchen look. Plus, tile is easy to care for and perfect for households with pets.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/kitchen-pets-modern.jpg',
			'url': 'http://www.carpetone.com/flooringtool/kitchenpetsmodern'
		},
		'Kitchen-Pets-Traditional': {
			'desc': 'Square tile with quarry inserts will take your traditional kitchen from good to great. This easy-to-clean and durable flooring option is perfect for homes with pets, too.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/kitchen-pets-traditional.jpg',
			'url': 'http://www.carpetone.com/flooringtool/kitchenpetstraditional'
		},
		'Kitchen-Kids-Modern': {
			'desc': 'Water-resistant and comfortable to walk on, vinyl comes in a variety of styles for your contemporary home. One option for a high-contrast wood plank is to compliment the clean lines of cabinets.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/kitchen-kids-modern.jpg',
			'url': 'http://www.carpetone.com/flooringtool/kitchenkidsmodern'
		},
		'Kitchen-Kids-Traditional': {
			'desc': 'Upgrade your traditional kitchen with faux facing vinyl flooring. This option is durable and water-resistant, sure to hold up to your busy family.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/kitchen-kids-traditional.jpg',
			'url': 'http://www.carpetone.com/flooringtool/kitchenkidstraditional'
		},
		'Kitchen-Teens-Modern': {
			'desc': 'Modernize your kitchen with a high-character, wood-toned vinyl. Long-lasting and durable, this flooring will make a great focal point for your kitchen.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/kitchen-teens-modern.jpg',
			'url': 'http://www.carpetone.com/flooringtool/kitchenteensmodern'
		},
		'Kitchen-Teens-Traditional': {
			'desc': 'Give your kitchen a classic look with square, slate tile. Easy to clean and durable, it&rsquo;s bound to stand up to your family&rsquo;s activities.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/kitchen-teens-traditional.jpg',
			'url': 'http://www.carpetone.com/flooringtool/kitchenteenstraditional'
		},
		'Kitchen-Adults-Modern': {
			'desc': 'Large-scale, light-colored tile sets a modern tone in any kitchen. For extra pop, add glass insets.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/kitchen-adults-modern.jpg',
			'url': 'http://www.carpetone.com/flooringtool/kitchenadultsmodern'
		},
		'Kitchen-Adults-Traditional': {
			'desc': 'You can&rsquo;t go wrong with the bold look of a high-contrast tile pattern. Use full 12x12 tiles, or try a varied size &mdash; either way, your kitchen will look amazing for years to come.',
			'image': 'http://content.blueport.com/carpetone/img/integer/ffw-images/kitchen-adults-traditional.jpg',
			'url': 'http://www.carpetone.com/flooringtool/kitchenadultstraditional'
		}		
	};

// Store State...

var ffwStepOneOption = "";
var ffwStepTwoOption = "";
var ffwStepThreeOption = "";

function ffwResetStates() {
	ffwStepOneOption = "";
	ffwStepTwoOption = "";
	ffwStepThreeOption = "";
	ffwInitSteps();
	
	return false;
}

function ffwInitSteps() {
	$("#ffw").append(ffwStepOne);
	$("#ffwStepOne").addClass('current');
	$("#ffw").append(ffwStepTwo);
	$("#ffw").append(ffwStepThree);
	$("#ffw").append(ffwStepResult);
	
	return false;
}

function ffwInitResults() {
	
	var resultsObj = ffwResults[ffwStepOneOption + "-" + ffwStepTwoOption + "-" + ffwStepThreeOption];
	
	$("#ffwStepResult p span").html(resultsObj['desc']);
	$("#ffwStepResult a#ffwResultsOutbound").attr("href", resultsObj['url']);
	$("#ffwStepResult img").attr("src", resultsObj['image']);
	
	return false;
}

function ffwResetResults() {
	
	$("#ffwStepResult p span").html("");
	$("#ffwStepResult p a#ffwResultsOutbound").attr("href", "");
	$("#ffwStepResult p img").attr("src", "");
	
	ffwResetStates();

	return false;
}



// jQuery Listeners...
(function($) {

	$(function() {
	
		ffwInitSteps();
		
		// Capture Clicks from Step One:
		
		$("#ffwStepOne a").click(function(){
			
			var selectedOption = $(this)[0].id.replace("ffwStepOneOption-","");
			
			ffwStepOneOption = selectedOption;
			
			if (selectedOption == 'Bath') {
				// Skip Step Two...
				$("#ffwStepOne").removeClass('current');
				$("#ffwStepThree").addClass('current');
			} else {
				// Advance to Step Two...
				$("#ffwStepOne").removeClass('current');
				$("#ffwStepTwo").addClass('current');
			}
			
			return false;
			
		});
		
		// Capture Clicks from Step Two:

		$("#ffwStepTwo a").click(function(){			
			
			var selectedOption = "Adults";
			
			// Set to the "worst" selected option...
			
			if ($("#ffwStepTwoOption-Pets").is(":checked")) {
				
				selectedOption = "Pets";
				
			} else if ($("#ffwStepTwoOption-Kids").is(":checked")) {

				selectedOption = "Kids";
			
			} else if ($("#ffwStepTwoOption-Teens").is(":checked")) {
			
				selectedOption = "Teens";
				
			} else {
			
				selectedOption = "Adults";
				
			}
			
			ffwStepTwoOption = selectedOption;
			
						
			// Advance to Step Two...
			$("#ffwStepTwo").removeClass('current');
			$("#ffwStepThree").addClass('current');
			
			return false;
			
		});
		
		// Capture Clicks from Step Three:

		$("#ffwStepThree a").click(function(){
			
			var selectedOption = $(this)[0].id.replace("ffwStepThreeOption-","");
			
			ffwStepThreeOption = selectedOption;
			

			// Advance to Results...
			ffwInitResults();
			$("#ffwStepThree").removeClass('current');
			$("#ffwStepResult").addClass('current');
			
			return false;

		});
		
		// Capture Click to 'Start Over' from the Results:
		$("#ffwReset").click(function(){
			
			$("#ffwStepResult").removeClass('current');
			$("#ffwStepOne").addClass('current');

			ffwResetResults();
			
			return false;
		});
		
	});

})(jQuery);
