//jQuery functions

//jQuery functions

$(document).ready(function() {
	
//sign up & footer reveals
$(".footer").hover(function() {
  $('.footer').animate({"bottom": "0px"}, 500);
  },function(){
	 $('.footer').animate({"bottom": "-242px"}, 100);
});

$("a.navSignup").click(function() {
  $(".navigation .overlay").slideToggle(300);
});

$(".navigation .overlay a").click(function() {
  $(".navigation .overlay").slideToggle(200);
});

//page scroll function
$(".container").click(function() {
  $.scrollTo( 0, 800 );
});

$(".primaryNav").hover(function() {
  //$('.menu').slideToggle(400);
  $('.menu').show(0);
  },function(){
	 //$('.menu').slideToggle(200);
	 $('.menu').hide(0);
});


//secondary nav drop down
	$("ul.navMain li").hover(function ()
	{
		$(this).children("ul.navSub").slideDown(200);
		//$(this).children("ul.navSub").show(0);
		$(this).children("a:not(ul.subnav li a)").toggleClass("navOver");
	}, function ()
	{
		//$(this).children("ul.navSub").slideUp(200);
		$(this).children("ul.navSub").hide(0);
		$(this).children("a:not(ul.subnav li a)").toggleClass("navOver");
	});
	
	
//form validation & form population
$("#footerForm").validate({
	submitHandler: function(form) {
	   $('#footerForm button.send').addClass("btnAnimate");
	   $(form).ajaxSubmit(function() { 
			$('#footerForm').fadeOut('fast');
			$('.own span').fadeOut('fast');
			$('.footerFormThanks').fadeIn('slow'); 
			_gaq.push(['_trackEvent', 'Web Forms', 'Submit', 'Footer Form']);
			ppcFooterConversion();
		});
 }
});

//signup form conversion function
//called upon jax form submission
function ppcFooterConversion() {
	var iframe = document.createElement('iframe');
	iframe.style.width = '0px';
	iframe.style.height = '0px';
	document.body.appendChild(iframe);
	iframe.src = 'http://www.whollywoodresidence.com/homepage/footer-form-thx';
};


//adds freeform sign up code if opt-in checkbox is checked

$("#footerForm #news").change(function() {
		if ($('#footerForm #news').attr('checked')) {
			$('#footerForm #mailingListNews').attr('name', 'mailinglist[]');
			$('#footerForm #mailingListNews').attr('value', 'news_list');
		} else {
			$('#footerForm #mailingListNews').attr('name', '');
			$('#footerForm #mailingListNews').attr('value', '');
		}
});
$("#footerForm #pricing").change(function() {
		if ($('#footerForm #pricing').attr('checked')) {
			$('#footerForm #mailingListPricing').attr('name', 'mailinglist[]');
			$('#footerForm #mailingListPricing').attr('value', 'pricing_list');
		} else {
			$('#footerForm #mailingListPricing').attr('name', '');
			$('#footerForm #mailingListPricing').attr('value', '');
		}
});

$(".talkForm #news").change(function() {
		if ($('.talkForm #news').attr('checked')) {
			$('.talkForm #mailingListNews').attr('name', 'mailinglist[]');
			$('.talkForm #mailingListNews').attr('value', 'news_list');
		} else {
			$('.talkForm #mailingListNews').attr('name', '');
			$('.talkForm #mailingListNews').attr('value', '');
		}
});
$(".talkForm #pricing").change(function() {
		if ($('.talkForm #pricing').attr('checked')) {
			$('.talkForm #mailingListPricing').attr('name', 'mailinglist[]');
			$('.talkForm #mailingListPricing').attr('value', 'pricing_list');
		} else {
			$('.talkForm #mailingListPricing').attr('name', '');
			$('.talkForm #mailingListPricing').attr('value', '');
		}
});

$(".landingForm #news").change(function() {
		if ($('.landingForm #news').attr('checked')) {
			$('.landingForm #mailingListNews').attr('name', 'mailinglist[]');
			$('.landingForm #mailingListNews').attr('value', 'news_list');
		} else {
			$('.landingForm #mailingListNews').attr('name', '');
			$('.landingForm #mailingListNews').attr('value', '');
		}
});
$(".landingForm #pricing").change(function() {
		if ($('.landingForm #pricing').attr('checked')) {
			$('.landingForm #mailingListPricing').attr('name', 'mailinglist[]');
			$('.landingForm #mailingListPricing').attr('value', 'pricing_list');
		} else {
			$('.landingForm #mailingListPricing').attr('name', '');
			$('.landingForm #mailingListPricing').attr('value', '');
		}
});

$("#signupForm").validate({
	submitHandler: function(form) {
	   $('#signupForm button.signup').addClass("btnAnimate");
	   $(form).ajaxSubmit(function() { 
			$('.overlay .instructions').fadeOut('fast');
			$('#signupForm').fadeOut('fast');
			$('.overlay .thankyou').fadeIn('slow');
			_gaq.push(['_trackEvent', 'Web Forms', 'Submit', 'Sign Up Form']);
			ppcSignupConversion();
		});
 }
});

//signup form conversion function
//called upon jax form submission
function ppcSignupConversion() {
	var iframe = document.createElement('iframe');
	iframe.style.width = '0px';
	iframe.style.height = '0px';
	document.body.appendChild(iframe);
	iframe.src = 'http://www.whollywoodresidence.com/homepage/signup-form-thx';
};

$(".talkForm").validate({
   messages: {
     name: "Please enter your name",
	 zip: "Please enter your zip",
	 phone: "Please enter your phone",
     email: {
       required: "Please enter your email address",
       email: "Valid email address required"
     }	
   }
});
$(".landingForm").validate({
   messages: {
     name: "Name required",
	 zip: "Zip required",
     email: {
       required: "Email required",
       email: "Need valid email"
     }	
   }
});
$("#loginForm").validate({
   messages: {
     username: "Please enter your username",
     password: "Please enter your password"
   }
});
$(".infoForm").validate({
   messages: {
     name: "Please enter your name",
	 zip: "Please enter your zip",
     email: {
       required: "Please enter your email address.",
       email: "Valid email address required"
     }	
   },
   submitHandler: function(form) {
	   $('.infoForm button.send').addClass("btnAnimate");
	   $(form).ajaxSubmit(function() { 
			$('#infoForm span').fadeOut('fast');
			$('.infoForm').fadeOut('fast');
			$('#infoForm .infoThanks').fadeIn('slow');
			_gaq.push(['_trackEvent', 'Web Forms', 'Submit', 'Request Info Form']);
			ppcInfoConversion();
		});
 }
});

//floorplans more info conversion function
//called upon jax form submission
function ppcInfoConversion() {
	var iframe = document.createElement('iframe');
	iframe.style.width = '0px';
	iframe.style.height = '0px';
	document.body.appendChild(iframe);
	iframe.src = 'http://www.whollywoodresidence.com/your-home/floorplans-request-thx';
};

function showResponse(responseText, statusText, xhr, $form)  { 
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.'); 
}

// request info form overlay
$("a.info").colorbox({
	width:"400px",
	inline:true,
	href:"#infoForm",
	height: "550px",
	onComplete: function () { //set display to defaults
		$('#infoForm span').show(0);
		$('.infoForm').show(0);
		$('#infoForm .infoThanks').hide(0);
	},
	onOpen: function () { //reset form and data
		$('.infoForm').resetForm();
		var residenceUnit = $(this).siblings().eq(0).html();
		$("#infoForm strong").html(residenceUnit);
		$("#infoResidence").val(residenceUnit);
	}
});

//gallery angles

$(".shortEntry .gallery a, .ctaEntry .details a, .ctaEntry .more a, .landingEntry .gallery a").hover(function() {
  $(this).animate({"right": "0px"}, 300);
  },function(){
	 $(this).animate({"right": "-70px"}, 150);
});

$(".longEntry .gallery a").hover(function() {
  $(this).animate({"right": "0px"}, 300);
  },function(){
	 $(this).animate({"right": "-73px"}, 150);
});

$(".happeningEntry .gallery a, .floorplansEntry .gallery a").hover(function() {
  $(this).animate({"right": "0px"}, 300);
  },function(){
	 $(this).animate({"right": "-80px"}, 150);
});

$(".shortEntry .map a").hover(function() {
  $(this).animate({"right": "0px"}, 300);
  },function(){
	 $(this).animate({"right": "-45px"}, 150);
});

//scroll function
$(".backgroundViewer a").click(function() {
  $.scrollTo( 0, 800 );
});

//scrolliing



//move angle
/*
$window = $(window);

$(window).scroll(function(){
	var angleOffset = $(".angle").offset();	
	var angleTop = angleOffset.top;
	var newLeft = 0 - (angleTop*2);
	$(".angle").css('left',newLeft);
	
	//var navOffset = $(".primaryNav").offset();	
	//var navTop = navOffset.top;
	var newTop = 0 - (angleTop*2);
	$(".primaryNav").css('top',newTop);
});
*/

} );



