


$(document).ready(function() {

/*
 +-++-++-++-++-+
 |S||l||i||d||e|
 +-++-++-++-++-+
 */
	// Expand Panel
	$("#open").click(function(){
		$("div#panel").slideDown("slow");
	});	
	// Collapse Panel
	$("#close").click(function(){
		$("div#panel").slideUp("slow");	
	});		
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});	
	$(window).bind('resize', function() {
  		fnResize();
	});
  	fnResize();

/*
 +-++-++-++-++-++-++-++-++-++-+
 |V||a||l||i||d||a||t||i||o||n|
 +-++-++-++-++-++-++-++-++-++-+
*/
	$("form input[type='text']").bind('blur',function(){validateForm(false);});
	$("form input[type='submit']").bind('click',function(){return validateForm(true);});


/*
 +-++-++-+ +-++-+
 |P||o||p| |u||p|
 +-++-++-+ +-++-+
*/
	$("#button-residences").click(function(){
		loadPopupContents('flash.html',960,576);							   
										   
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});


});

var fnResize = function(){
	$('.login').css('left', $('#topbar').position().left-15);
	if ($(".home").length==0){
		$('#content').css('height', $(window).height()-160);
	} else {
		$('#topbar').css('margin-bottom', 0);
		$('#content').css('height', $(window).height()-125);
	}
}

function validateEmail(elementValue){  
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
	return emailPattern.test(elementValue);  
}

/*
Name: Sliding Login Panel with jQuery 1.3.2
Author: Jeremie Tisseau
Author URI: http://web-kreation.com/
Script URI: http://web-kreation.com/index.php/tutorials/nice-clean-sliding-login-panel-built-with-jquery/
Date: March 26, 2009
Version: 1.0

	The CSS, XHTML and design is released under Creative Common License 3.0:
	http://creativecommons.org/licenses/by-sa/3.0/

*/ 

/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#popupBackground").css({
			"opacity": "0.7"
		});
		$("#popupBackground").fadeIn("slow");
		$("#popupContent").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#popupBackground").fadeOut("slow");
		$("#popupContent").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContent").height();
	var popupWidth = $("#popupContent").width();
	//centering
	$("#popupContent").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2-15
	});
	//only need force for IE6
	
	$("#popupBackground").css({
		"height": windowHeight
	});
}


function loadPopupContents(url,wd,ht){
	//if ($.browser.msie) $('#popupContent').css('width',"1px")
	
	$('#popupContent .inner').css('width',wd).css('height',ht).load(url);	
	//CLOSING POPUP
	//Click the x event!
	$("#popupContentClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#popupBackground").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});	
}




function validateForm(displayMessage){
		$("form input[type='text']").each(function(){
			$(this).removeClass('highlight');
		});

		var message="";
		var els = [];
		if ($("form input[name='FirstName']").attr('value')==""){ message+="* First name required\n"; els[els.length]=$("form input[name='FirstName']");}
		if ($("form input[name='LastName']").attr('value')==""){  message+="* Last name required\n"; els[els.length]=$("form input[name='LastName']");}
		if ($("form input[name='Email']").attr('value')==""){ message+="* Email required\n";els[els.length]=$("form input[name='Email']"); } 
			else {
				if (!validateEmail($("form input[name='PersonEmail']").attr('value'))){ message+="* Correct email address format required\n"; els[els.length]=$("form input[name='PersonEmail']");}
			}
		if (message!=""){
			for (var i=0;i<els.length;i++)
				els[i].addClass('highlight');
			if (displayMessage) alert("The following form fields are incorrect:\n\n"+message);			
			return false;

		} else {
			return true;	
		}
}