/* 
Warehouse Agency NYC 2010 
MouseEvents - Control
*/

//---------------------------------------------------------------------------
//					APPOINTMENT SECTION
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------Validate user input on submit button click

//var thisValue;
var firstNameRegex = /^[a-zA-Z '-]{1,40}$/;
var lastNameRegex = /^[a-zA-Z '-]{1,40}$/;
var phoneRegex = /^\+?[0-9\(\)\s-]{1,19}$/;
//var phoneRegex = /^\(*[0-9]{3}(\)|-)*\s*[0-9]{3}(\s|-)*[0-9]{4}$/;
var emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
var zipRegex = /^[0-9]{5}$/;


function chkUsrInpt(){
	if(!(firstNameRegex.test($("#first-name").val()))||$("#first-name").val() == "First Name"){
		alert("Please re-enter your first name");
//		$("#first-name").focus();
		return false;
	}
	else if(!(lastNameRegex.test($("#last-name").val()))||$("#last-name").val() == "Last Name"){
		alert("Please re-enter your last name");
//		$("#last-name").focus();
		return false;
	}
	else if(!(phoneRegex.test($("#appt-phone").val()))||$("#appt-phone").val() == "Telephone"){
		alert("Please re-enter your telephone number");
//		$("#appt-phone").focus();
		return false;
	}
	else if(!(emailRegex.test($("#appt-email").val()))||$("#appt-email").val() == "Email"){
		alert("Please re-enter your email address");
//		$("#appt-email").focus();
		return false;
	}
	else if(!(zipRegex.test($("#zip-code").val()))||$("#zip-code").val() == "Zip Code"){
		alert("Please re-enter your zip code");
//		$("#zip-code").focus();
		return false;
	}
	else if($("#appt-how-did-you-hear").val() == "How did you hear about us"){
		alert("How did you hear about us?");
		return false;	
	}
	else{
		$("#appt-submit-btn").attr("disabled","disabled");
	}
	
}


function reSize(){
	$("#slide-show").css("width","100%");  
	$("#psuedo-1, #psuedo-2, #psuedo-3, #psuedo-4, #psuedo-5, #psuedo-6, #psuedo-7").css("width","100%");
}



$(window).resize(function(){
		reSize();
});



$(document).ready(function() { 





var isAboutTabOpen = 0;
$("#about-tab-wrapper").click(function(){
	if(isAboutTabOpen == 0){
		isAboutTabOpen = 1;
		$(this).animate({'width':500});		
	}
	else{
		isAboutTabOpen = 0;
		$(this).animate({'width':45});		
	}
});

//---------------------------------------------

	$('#legal-notice-wrapper').hide();	
	$("#acc-body1,#acc-body2,#acc-body3,#hotel-condos-wrapper").hide();
	
	$(window).load(function () {	
		
		$('#slide-show').cycle({
			fx: 'fade',
			speed: '2000',
			timeout: '6000',
			cssBefore: 'reSize()'
		});

	$('#show-legal-info-top, #show-legal-info-btm').click(function(){$('#legal-notice-wrapper').slideToggle(800);});	
											
	
$(".sub-nav-li").click(function(){	
		$('.sub-nav-li').css('color', '#FFF');
			$(this).css('color', '#009899');
	});
								   

$('a[href*=#]').click(function() {    
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {        
            var $target = $(this.hash);            
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');            
            if ($target.length) {            
                var targetOffset = $target.offset().top;                
                $('html,body').animate({scrollTop: targetOffset}, 1000);                    
                return false;                
            }            
        }        
    });  
	
//----------Appointment Include----------------
function disableCityState(){
	if(document.getElementById('appt-country').value!=='United States'){
		alert("hello"); 
/*		document.getElementById('appt-state').disabled='true';
		document.getElementById('appt-city').style.color="#555555";
		document.getElementById('appt-state').style.color="#555555";*/
		}
		else{
		document.getElementById('appt-city').disabled='false'; 
/*		document.getElementById('appt-state').disabled='false';
		document.getElementById('appt-city').style.color="#555555";
		document.getElementById('appt-state').style.color="#555555";*/
	}
}
	
//Residences page sub-nav click functions

//	$("#res-balcony").fadeTo(0, 0.5); //Fade 1st option on window load

	
	$("#res-balcony").click(function(){
//		$("#res-balcony").fadeTo(0, 0.5);
//		$(".sub-nav-li a:not(#res-balcony)").fadeTo(0, 1);	
				
		$("#res-content img:not(#res-img-balcony)").hide(0,function() {
			$("#res-img-balcony").fadeIn(400);
		});
		$("#selector-wrapper div:not(#balcony-div)").fadeOut(0,function(){
			$("#balcony-div").fadeIn(500);	
				});	
				
				
	});	
	$("#res-living").click(function(){
//		$("#res-living").fadeTo(0, 0.5);
//		$(".sub-nav-li a:not(#res-living)").fadeTo(0, 1);
		
		$("#res-content img:not(#res-img-living)").hide(0,function() {
		  		$("#res-img-living").fadeIn(400);
		});
		$("#selector-wrapper div:not(#living-div)").fadeOut(0,function(){
			$("#living-div").fadeIn(500);	
				});			
				
	});		
	$("#res-kitchen").click(function(){
//		$("#res-kitchen").fadeTo(0, 0.5);
//		$(".sub-nav-li a:not(#res-kitchen)").fadeTo(0, 1);
		
		$("#res-content img:not(#res-img-kitchen)").hide(0,function() {
		  		$("#res-img-kitchen").fadeIn(400);
		});	
		$("#selector-wrapper div:not(#kitchen-div)").fadeOut(0,function(){
			$("#kitchen-div").fadeIn(500);	
				});	
				
	});
	$("#res-bathroom").click(function(){
//		$("#res-bathroom").fadeTo(0, 0.5);
//		$(".sub-nav-li a:not(#res-bathroom)").fadeTo(0, 1);
		
		$("#res-content img:not(#res-img-bathroom)").hide(0,function() {
		  		$("#res-img-bathroom").fadeIn(400);
		});	
		$("#selector-wrapper div:not(#bath-div)").fadeOut(0,function(){
			$("#bath-div").fadeIn(500);	
				});	
	});
	$("#res-bedroom").click(function(){
//		$("#res-bedroom").fadeTo(0, 0.5);
//		$(".sub-nav-li a:not(#res-bedroom)").fadeTo(0, 1);
		
		$("#res-content img:not(#res-img-bedroom)").hide(0,function() {
		  		$("#res-img-bedroom").fadeIn(400);
		});	
		$("#selector-wrapper div:not(#bedroom-div)").fadeOut(0,function(){
			$("#bedroom-div").fadeIn(500);	
				});	
	});		
	
//------------------------------Explore -----------------------------
		
//$("#avail-subnav-residences").fadeTo(0, 0.5); //Fade 1st option on window load


isClassSchedOpen = 0;
$("#class-sched").click(function(){
	if(isClassSchedOpen == 0){
		isClassSchedOpen = 1;
		$(this).animate({'width':190});		
	}
	else{
		isClassSchedOpen = 0;
		$(this).animate({'width':35});		
	}
});

$(".class-sched-p").click(function(){
	window.open('http://canyonranch.com/miamibeach/book_a_stay/plan_your_stay/');
});

$("#avail-subnav-residences").click(function(){
//	$("#avail-subnav-residences").fadeTo(0, 0.5);
//	$(".sub-nav-li:not(#avail-subnav-residences)").fadeTo(0, 1);
		
	$("#hotel-condos-wrapper").hide();
	$("#accordion-wrapper").show();
});	
$("#avail-subnav-hotel-condos").click(function(){
//	$("#avail-subnav-hotel-condos").fadeTo(0, 0.5);
//	$(".sub-nav-li:not(#avail-subnav-hotel-condos)").fadeTo(0, 1);
	
	$("#hotel-condos-wrapper").show();
	$("#accordion-wrapper").hide();
});	

$("#acc-head1").click(function(){
	$("#acc-body1").slideToggle();
	$("#acc-body2,#acc-body3").slideUp();
	$('html,body').animate({scrollTop: 0}, 1000);
});
$("#acc-head2").click(function(){
	$("#acc-body2").slideToggle();
	$("#acc-body1,#acc-body3").slideUp();
	$('html,body').animate({scrollTop: 0}, 1000);
});
$("#acc-head3").click(function(){
	$("#acc-body3").slideToggle();
	$("#acc-body1,#acc-body2").slideUp();
	$('html,body').animate({scrollTop: 0}, 1000);
});	

$(".avail-thumbnail").click(function(){
	var thumbnailImgName = $(this).attr("src");
	var lightboxImgName = thumbnailImgName.replace("/thumbnails","");
	
	$("#lightbox-front img").attr("src",lightboxImgName);
	
	$("#lightbox-back").fadeIn(100,function(){
			$("#lightbox-front").slideDown();
				$('html,body').animate({scrollTop: "#nav-div"}, 1000);                    
		});
	});

$("#lightbox-back").click(function(){
$("#lightbox-front img").attr("src",null);
		$("#lightbox-front").slideUp(function(){
		$("#lightbox-back").fadeOut(100);
		});
	});

	
$(".viewIcon").click(function(){
	var floorplanName = $(this).attr("id");
	window.open("http://www.canyonranchlivingmiamibeach.com/images/availability/floorplans/"+floorplanName+".jpg");
	});
	
	});	
});	



