jQuery.preloadImages = function() {
  for(var i = 0; i<arguments.length; i++) {
  jQuery("<img>").attr("src", arguments[i]);
  }
}

$.preloadImages("/images/nav-amenities-on.gif", "/images/nav-apartments-on.gif","/images/nav-contact-on.gif","/images/nav-faq-on.gif","/images/nav-gallery-on.gif","/images/nav-location-on.gif","/images/nav-movein-on.gif","/images/schedule-tour-on.gif","/images/submit-app-on.gif","/images/benefits-on.gif","/images/easy-move-in-on.gif","/images/hear-more-on.gif");

$(function() {
	
	$('#nav ul li').mouseover(function() {
		$(this).css('z-index', '1');		
	});
	
	$('#nav ul li').mouseout(function() {
		$(this).css('z-index', '0');
		$('#amenities-on').css('z-index', '1');
		$('#apartments-on').css('z-index', '1');
		$('#gallery-on').css('z-index', '1');
		$('#location-on').css('z-index', '1');
		$('#faq-on').css('z-index', '1');
		$('#movein-on').css('z-index', '1');
		$('#contact-on').css('z-index', '1');
	});
		   
});

$(function() {
	
	$('#faq ul li a').click(function() {
		$(this).toggleClass('faq-on');
		$(this).next('.question-block').slideToggle('normal');
	});
		   
});

function openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


// SHARE THIS 

$(function() {
	
	$('#share').click(function() {	
	$('#share-this').slideToggle('normal');
	});
		   
});

  $(function() {
	
	$('.error').hide();
    $(".button").click(function() {
      // validate and process form here
	  
	  var sendit = $("input#sendit").val();
	  	  
	  var yemailtest = $("input#y-email").val();
	  var yfemailtest = $("input#yf-email").val();
	  
	  var yemail = $("input#y-email").val();
  		if (yemail == "") {
        $("label#y-email_error").show();
        $("input#y-email").focus();
        return false;
      }
	  
	  if (yemail != "") {
	  	if(isValidEmailAddress(yemailtest)) {
		}else{
		$("label#y-email_error").show();
		$("input#y-email").focus();
		return false;
		}
	  }
	  
	  var yfemail = $("input#yf-email").val();
  		if (yfemail == "") {
        $("label#yf-email_error").show();
        $("input#yf-email").focus();
        return false;
      }
	  
	  if (yfemail != "") {
	  	if(isValidEmailAddress(yfemailtest)) {
		}else{
		$("label#yf-email_error").show();
		$("input#yf-email").focus();
		return false;
		}
	  }
	  
	  var the_message = $("textarea#share-comments").val();
  		if (the_message == "") {
        $("label#comments_error").show();
        $("textarea#share-comments").focus();
        return false;
      }	
	  
	    var dataString = 'sendit='+ sendit + '&yemail=' + yemail + '&yfemail=' + yfemail + '&the_message=' + encodeURIComponent(the_message);
		  //alert (dataString);return false;
		  $.ajax({
			type: "POST",
			url: "/inc/share-process.php",
			data: dataString,
			success: function() {
			  
			  $('#share-this-form').fadeOut(1000);
			  $('#success-msg').html("<div id='message'></div>");
			  $('#message').html("Thank you, an email has been sent to your friend!")			  
			  .hide().fadeIn(1500).animate({top:0},2000).fadeOut(3000);	
			  
			  Site.trackConversion('share-this.html');
			  
			}
		  });
		  return false;
      
    });
  });
  
  
  function isValidEmailAddress(emailAddress) {
 		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
 		return pattern.test(emailAddress);
	}
	
// end SHARE THIS


// conversion function
var Site = { trackConversion:function(pageName){
        var iframe = document.createElement('iframe');
     iframe.style.width = '0px';       iframe.style.height = '0px';
      iframe.style.visibility = 'hidden';

     document.body.appendChild(iframe);
		
	 //alert('/conversions/'+pageName);	
     iframe.src = '/conversions/'+pageName;

 }   } 



