$(document).ready(function(){

	// "Sign Up for Email" Modal Window...
	$(".emailSignUpLink").click(function (e) {
		
		e.preventDefault();
		
		// Fix IE 7 overlay issue...
		$('.ie7-flash-hack').addClass('ie7-flash-hide');
		
		$('#emailSignupBox').modal(
			{
				overlayClose: true,
				
				onClose: function (d) {
					$('.ie7-flash-hide').removeClass('ie7-flash-hide');
					$.modal.close();
				}
			
			}
		);
		
		return(false);
	});


	
	// "Tools To Get You Started"
	// Footer Include Scrolling...

	$("#tools-list").jCarouselLite({
		btnNext: ("#tools-next"),
		btnPrev: ("#tools-prev"),
		visible: 2,
		circular: false
	});
	
	// "Erinn's Photos"
	// Thumb Scrolling...
	$("#photos-thumbs").jCarouselLite({
		btnNext: ("#photos-next"),
		btnPrev: ("#photos-prev"),
		visible: 5,
		circular: false
	});

	
	// Click Thumb to load Large Photo...
	$("#photos-thumbs a").click(function() {
		
		// Do nothing if it's already the current image...
		if ($(this).hasClass("current")) {
			return (false);
		}
		
		// Toggle the 'current' class on the thumb...
		$("#photos-thumbs a.current").removeClass("current");
		$(this).addClass("current");
		
		// Get the sub-string past the dash...
		var whichPhoto = $(this).attr("id");
		whichPhoto = whichPhoto.substring((whichPhoto.indexOf("-")+1));

		// Hide the current large photo and show the "whichPhoto" id'd one...
		var largePhoto = "#photo-" + whichPhoto;
		$("#photos-large .current").addClass("hide");
		$("#photos-large .current").removeClass("current");
		$(largePhoto).addClass("current");
		$(largePhoto).removeClass("hide");
		
		return false;
	
	});
	
	// Click on Video Thumb to load Video...
	$("#video-thumbs a").click(function() {
		
		// Do nothing if it's already the current image...
		if ($(this).hasClass("current")) {
			return (false);
		}
		
		stopAllVideos();
		
		// Toggle the 'current' class on the thumb...
		$("#video-thumbs a.current").removeClass("current");
		$(this).addClass("current");
		
		// Get the sub-string past the dash...
		var whichVideo = $(this).attr("id");
		whichVideo = whichVideo.substring((whichVideo.indexOf("-")+1));

		// Hide the current Video Div and show the "whichVideo" id'd one...
		var videoId = "#video-" + whichVideo;
		$(".video.current").addClass("hide");
		$(".video.current").removeClass("current");
		$(videoId).addClass("current");
		$(videoId).removeClass("hide");
		
		return(false);
		
	});

	
	// "Erinn's Picks" Favorite Floors Page
	// Thumb Scrolling...
	$("#floor-thumbs").jCarouselLite({
		btnNext: ("#floor-next"),
		btnPrev: ("#floor-prev"),
		visible: 5,
		circular: false
	});
	
	// Click Thumb to swap out larger div...
	$("#floor-thumbs a").click(function() {
		
		// Do nothing if it's already the current image...
		if ($(this).hasClass("current")) {
			return (false);
		}
		
		// Toggle the 'current' class on the thumb...
		$("#floor-thumbs a.current").removeClass("current");
		$(this).addClass("current");
		
		// Get the sub-string past the dash...
		var whichFloor = $(this).attr("id");
		whichFloor = whichFloor.substring((whichFloor.indexOf("-")+1));

		// Hide the current Div and show the "whichFloor" id'd one...
		var floorId = "#floor-" + whichFloor;
		$("#floors-details div.current").addClass("hide");
		$("#floors-details div.current").removeClass("current");
		$(floorId).addClass("current");
		$(floorId).removeClass("hide");
		
		return(false);
		
	});
	
	
	// "Sign Up for Email" Modal Window...
	$(".enlarge").click(function (e) {
		e.preventDefault();
		$('#floorEnlarged').modal({overlayClose:true});
		
		$(this).removeClass('enlarge');
				
		var imageName = '/images/floors/zoom-' + $(this).attr('class') + '.jpg';

		$(this).addClass('enlarge');
		
		$('#floorEnlarged img').attr('src', imageName);
		
		return(false);
	});
	
	
	
	
	// Email Sign Up AJAX...
	$("#emailSignupBox #submit").click(function(){
		
		var randomNumber = parseInt(Math.random() * 10000);
		
		$.post("/emailSignUp", $("#emailSignUpForm").serialize());
		
		$("#emailSignUpForm").addClass("hide");
		$("#emailSignUpThankYou").removeClass("hide");
		
		// Google Analytics Capture:
		try {
			pageTracker._trackPageview("/emailSignUp");
		} catch(e) { }
		
		return(false);
	
	});
	
	
	// For all of the Prev/Next buttons, make them not do anything now that circular: false on the carousel...
	$("#photos-next, #photos-prev, #tools-next, #tools-prev, #floor-next, #floor-prev").click(function(){
		return false;
	});
	
	// Email Sign Up Validate Email Field...
	$("#signupInputEmail").blur(function(){
		if ($(this).val() == '') {
			$("#signupLabelEmail").css("color", "#dd0000");
		} else {
			$("#signupLabelEmail").css("color", "#808181");
		}
	});
	
	
	// Design Tips Page collapse tips...
	
	$("#design-tips li a").click(function(){
		
		// First, reset the page back to all collapsed...
		$("#design-tips .details").slideUp();
		$("#design-tips .preview").slideDown();
		
		// Second, hide this preview and show this details...
		$(this).closest(".preview").hide();
		$(this).closest("li").children(".details").slideDown();
		return(false);
	});
	
});


// Fix for Windows and the JW Player that keeps playing when it's hidden...
function stopAllVideos() {
	try {
		player.sendEvent("STOP");
	} catch(e) { }
	return false;
}


// Makes global variable 'player' the active JW Player so it can be controlled.

var player;
function playerReady(obj) {
	//alert('the videoplayer '+obj['id']+' has been instantiated');
	player = document.getElementById(obj['id']);
};

