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

	var promo_moving = false;
	var hover_on = false;
	var promo_timeout = null;

	function show_promo_dropdown() {
		if(!promo_moving && hover_on) {
			promo_moving = true;
			$(this).find("div.rollover").slideDown(200,function() {
				promo_moving = false;
			});
			promo_timeout = null;
		}
	}

	var xp_section_moving = false;
	var join_newsletter_moving = false;

	function CheckEmail(email) {

		AtPos = email.indexOf("@")
		StopPos = email.lastIndexOf(".")

		if (AtPos == -1 || StopPos == -1) {
			return false;
		} else {
			return true;
		}

	}

	var newsletter_text = "";

	function return_newsletter_text() {
		$("#join_newsletter_on div.right_content").html(newsletter_text);
		set_up_newsletter();
	}

	function set_up_newsletter() {

		$("input#newsletter_email").focus(function() { if($(this).val() == "E-mail Address") { $(this).val(""); } });
		$("input#newsletter_email").blur(function() { if($(this).val() == "") { $(this).val("E-mail Address"); } });
		$("input#newsletter_email2").focus(function() { if($(this).val() == "Confirm E-mail Address") { $(this).val(""); } });
		$("input#newsletter_email2").blur(function() { if($(this).val() == "") { $(this).val("Confirm E-mail Address"); } });

		$("input#newsletter_submit").click(function() {

			// verify email
			var email = $("input#newsletter_email").val();
			var email2 = $("input#newsletter_email2").val();
			if( !CheckEmail(email) || email.length == 0 || (email != email2) ) {
				newsletter_text = $("#join_newsletter_on div.right_content").html();
				$("#join_newsletter_on div.right_content").html("<p><strong>SIGN UP FOR E-MAIL</strong></p><p>&nbsp;</p><p>Error processing your request: Please confirm that your email address is valid and that is is correctly entered in both email fields.<br><br><br><a href=\"#return\" onclick=\"return_newsletter_text();\">Go back</a></p>");
			} else {

				// verify select of newsletter
				if(!$("input#newsletter_pe").attr("checked")) {
					newsletter_text = $("#join_newsletter_on div.right_content").html();
					$("#join_newsletter_on div.right_content").html("<p><strong>SIGN UP FOR E-MAIL</strong></p><p>&nbsp;</p><p>Error processing your request: Please select what newsletter you would like to join.<br><br><br><a href=\"#return\" onclick=\"return_newsletter_text();\">Go back</a></p>");
				} else {

					// submit
					$("#newsletter_message").css("display","block").html("Processing...");
					$(this).css("display","none");
					$.ajax({
						type: "POST",
						url: "/ajax/newsletter.php",
						data: "email="+$("input#newsletter_email").val()+"&newsletter=pe",
						success: function(msg){
							$("#join_newsletter_on div.right_content").html(msg);
						}
					});

				}

			}

		});

	}

	$(document).ready(function(){

			// JOIN NEWSLETTER
			$("#join_newsletter_container").hover(function() {
				if(!join_newsletter_moving) {
					join_newsletter_moving = true;
					$(this).find("#join_newsletter_on").slideDown(350,function() {
						join_newsletter_moving = false;
					});
				}
		    },function() {
				$(this).find("#join_newsletter_on").slideUp(150);
		    });

			set_up_newsletter();

			// show promo section
			$("#header .promo").hover(function(){
				hover_on = true;
				promo_timeout = setTimeout("show_promo_dropdown()",300);
			},function() {
				hover_on = false;
				if(promo_timeout != null) {
					clearTimeout(promo_timeout);
					promo_timeout = null;
				}
				$(this).find("div.rollver").stop();
				$(this).find("div.rollover").slideUp(200);
			});

			/* contact us thickbox
			$("a#contactUs").click(function() {
				tb_show("Contact Us","/contact-us.php?TB_iframe=true&height=500&width=710",0);
			});

			// contact us thickbox
			$("a.contactUsThickbox").click(function() {
				tb_show("Contact Us","/contact-us.php?TB_iframe=true&height=500&width=710",0);
			}); */

			// its personal thickbox
			$("a.its_personal_more_info").click(function() {
				tb_show("It's Personal","/its-personal-request.php?TB_iframe=true&height=500&width=710",0);
			});

			/* contact us js fix
			$("a#contactUs").attr("href","#lifestyle");

			// schedule a tour thickbox
			$("a#scheduleClick").click(function() {
				tb_show("Schedule A Tour","/communities/schedule-a-tour.php?TB_iframe=true&height=500&width=710",0);
			}); */

			// apply online thickbox
			$("a.applyOnlineThickbox").click(function() {
				tb_show("Apply Online","/apply-online.php?TB_iframe=true&height=520&width=725",0);
			});

			// rent payment thickbox

			$("a.payRentThickbox").click(function() {
				tb_show("Pay Rent Online","/pay-rent.php?TB_iframe=true&height=300&width=500",0);
				return false;
			});
			// xp section dropdown
			$("#xp_section_dropdown_container").hover(function() {
				if(!xp_section_moving) {
					xp_section_moving = true;
					$(this).find("#xp_section_dropdown").slideDown(350,function() {
						xp_section_moving = false;
					});
				}
		    },function() {
				$(this).find("#xp_section_dropdown").slideUp(150);
		    });



	});
