

// $cmignore

function is_empty(obj) {
	for(var prop in obj) {
       	if(obj.hasOwnProperty(prop))
        	return false;
    	}
    	return true;
}

$(document).ready(function(){
	//Initialize jcarouselite
	$('.thumb_slides, .prev, .next').css('display', 'block');
	$(".thumb_slides").jCarouselLite({
		btnNext: ".next",
		btnPrev: ".prev"
	});
	$('.thumb_slides ul li img').each(function(){$(this).attr('src' ,function(){return this.src.replace(/staticWebSite\//,'');})});

	var unclickedThumbPath ='/images/featured/greenhome/thumbnails/';
	var clickedThumbPath ='/images/featured/greenhome/thumbnails/border/';
	var mainImagePath ='/images/featured/greenhome/rooms/';
	var RoomText = { 
    	"great-room" : { 
        	header : "Great Room", 
        	first : {SW: "SW 6649<br /> Extra White", hex : "#eff0ec", text : "dark"} 
        	 
    	}, 
    	"kitchen" : { 
        	header : "Kitchen", 
        	first : {SW:"SW 6649<br /> Extra White", hex :"#eff0ec", text : "dark"} 
    	}, 
    	"laundry-room" : { 
		header : "Laundry Room",
        	first : {SW : "SW 7067<br /> Cityscape", hex : "#80827f", text : "light"}, 
        	second : {SW : "SW 7029<br /> Agreeable Gray", hex : "#d2cdc2", text : "dark"},
        	third : {SW : "SW 6649<br /> Extra White", hex : "#eff0ec", text : "dark"} 
    	}, 
    	"tower" : { 
		header : "Tower",
        	first : {SW : "SW 6083<br /> Sable", hex: "#5d4c3d", text : "light"}, 
        	second : {SW : "SW 6499<br /> Stream", hex: "#b0cad5", text : "dark"}, 
        	third : {SW : "SW 6649<br /> Extra White", hex: "#eff0ec", text : "dark"} 
    	}, 
    	"master-bath-vanity" : { 
		header : "Master Bath",
        	first : {SW : "SW 7069<br /> Iron Ore", hex : "#444543", text : "light"},
        	second : {SW : "SW 6241<br /> Aleutian", hex : "#9caaba", text : "light"}, 
        	third : {SW : "SW 6239<br /> Upward", hex : "#c1c9d1", text : "light"}
    	}, 
    	"master-bed" : { 
		header : "Master Bedroom",
        	first : {SW : "SW 6866<br /> Heartthrob", hex :"#ad262e", text : "light"},
        	second : {SW : "SW 6240<br /> Windy Blue", hex :"#acb9c7", text : "light"},
        	third : {SW : "SW 6238<br /> Icicle", hex :"#dcdfe1", text : "dark"} 
    	}, 
    	"dining-room" : { 
		header : "Hall",
        	first : {SW : "SW 6670<br /> Gold Crest", hex : "#de9f2f", text : "light"},
        	second : {SW : "SW 7030<br /> Anew Gray", hex : "#bfb8ab", text : "dark"}, 
        	third : {SW : "SW 6649<br /> Extra White", hex : "#eff0ec", text : "dark"} 
    	}, 
    	"sitting-room" : { 
		header : "Loft",
        	first : {SW : "SW 6242<br /> Bracing Blue", hex :"#7c8b9e", text : "light"},
        	second : { SW : "SW 6649<br /> Extra White", hex :"#eff0ec", text : "dark"} 
        	
    	}, 
    	"exterior" : { 
		header : "Exterior View",
        	first : {SW : "SW 7039<br /> Virtual Taupe", hex : "#897c69", text : "light"}, 
        	second : {SW : "SW 7036<br /> Accesible Beige", hex : "#d1c9b8", text : "dark"},
        	third : {SW : "SW 6649<br /> Extra White", hex : "#eff0ec", text : "dark"} 
    	}, 
    	"kids-room" : { 
		header : "Child's Bedroom",
        	first : {SW : "SW 6649<br /> Tango", hex : "#e08d4c", text : "light"}, 
        	second : {SW : "SW 6415<br /> Hearts of Palm", hex : "#cbc791", text : "light"}, 
        	third : {SW : "SW 6649<br /> Extra White", hex : "#eff0ec", text : "dark"} 
    	}, 
    	"kids-bath" : { 
		header : "Child's Bath",
        	first : {SW : "SW 6649<br /> Tango", hex : "#e08d4c", text : "light"}, 
        	second : {SW : "SW 6415<br /> Hearts of Palm", hex : "#cbc791", text : "light"}, 
        	third : {SW : "SW 6649<br /> Extra White", hex : "#eff0ec", text : "dark"} 
   	 } 
}
	var thumbImages= $('li img');
	thumbImages.click(function(){
		//OnClick of Thumbnail, places a border on the clicked thumbnail
		thumbImages.each(function(){
			var thumb= $(this).attr('src');
			var re = /([A-Za-z0-9\-_]+)\.((png)|(jpg))$/;
			thumb.match(re);
			var thumbName=RegExp.$1;
			$(this).attr('src', unclickedThumbPath+thumbName+'.png');
		});
		var thumb= $(this).attr('src');
		var thumbClicked= $(this).attr('src');
		var re = /([A-Za-z0-9\-_]+)\.((png)|(jpg))$/;
		thumb.match(re);
		var thumbName=RegExp.$1;
		$(this).attr('src', clickedThumbPath+thumbName+'.png');
		$('#column_right ul li').each(function(){$(this).removeClass('hidden')})

		var firstHexValue =(!is_empty(RoomText[thumbName]["first"])) ? RoomText[thumbName]["first"].hex : '';
		var secondHexValue =(!is_empty(RoomText[thumbName]["second"])) ? RoomText[thumbName]["second"].hex : '';
		var thirdHexValue =(!is_empty(RoomText[thumbName]["third"])) ? RoomText[thumbName]["third"].hex : '';
		var firstSWValue =(!is_empty(RoomText[thumbName]["first"])) ? RoomText[thumbName]["first"].SW : '';
		var secondSWValue =(!is_empty(RoomText[thumbName]["second"])) ? RoomText[thumbName]["second"].SW : '';
		var thirdSWValue =(!is_empty(RoomText[thumbName]["third"])) ? RoomText[thumbName]["third"].SW : '';
		var firstTextShade =(!is_empty(RoomText[thumbName]["first"]) && RoomText[thumbName].first.text == 'light') ? '#fff' : '#75726c';
		var secondTextShade =(!is_empty(RoomText[thumbName]["second"]) && RoomText[thumbName].second.text == 'light') ? '#fff' : '#75726c';
		var thirdTextShade =(!is_empty(RoomText[thumbName]["third"]) && RoomText[thumbName].third.text == 'light') ?  '#fff' : '#75726c';

		//Swaps out the main image
		$('#main_image').attr('src', mainImagePath+thumbName+'.jpg');

		//Sets the Scene Header text 
		$('#column_left h2 span').html(RoomText[thumbName]["header"]);

		//Sets the Palette Font Color and Palette Background Color
		if(is_empty(RoomText[thumbName]["first"])){
		       	$('#one')
				.addClass('hidden')
				.html('');
		}else{
			$('#one')
				.removeClass('hidden')
				.html(firstSWValue)
				.css('background-color', firstHexValue)
				.css('color', firstTextShade);
		}

		if(is_empty(RoomText[thumbName]["second"])){
		       	$('#two')
				.addClass('hidden')
				.html('');
		}else{
			$('#two')
				.removeClass('hidden')
				.html(secondSWValue)
				.css('background-color', secondHexValue)
				.css('color', secondTextShade);
		}

		if(is_empty(RoomText[thumbName]["third"])){
			$('#three')
				.addClass('hidden')
				.html('');
		}else{	
			$('#three')
				.removeClass('hidden')
				.html(thirdSWValue)
				.css('background-color', thirdHexValue)
				.css('color',  thirdTextShade);
		}
	});
});
// $/cmignore











