<!--

	//================================================================================================
	// VARIABLES DECLARATION
	//================================================================================================


	//================================================================================================
	// AJAX FUNCTIONS
	//================================================================================================
	function sendContact(name,email,phone,messageorenquiry,news)
	{
		var url = "process.php";

    $.post( url, { "process": "contact", "name": name, "email": email, "phone": phone, "messageorenquiry": $.URLDecode(messageorenquiry), "news": news },
      function( data ) {
      	alert(data);
        cleanUpContactForm();
      }
    ).error(function() { alert("Error connecting to server. Please refresh this page..."); });
	}

	function sendNews(name,email)
	{
		var url = "process.php";

    $.post( url, { "process": "news", "name": name, "email": email },
      function( data ) {
      	alert(data);
        cleanUpNewsForm();
      }
    ).error(function() { alert("Error connecting to server. Please refresh this page..."); });
	}

	//================================================================================================
	// FORM FUNCTIONS
	//================================================================================================
	function submitContact()
	{
		var form = document.contactusform;
		var message = "";
		var name = form.name.value;
		var email = form.email.value;
		var phone = form.phone.value;
		var news = form.news.value;
		var messageorenquiry = form.messageorenquiry.value;

		var valid = true;
		
		if ((name == "") || (name == "Name")) 
		{
			valid = false;
			message = message + "Please make sure you have entered your Name.\n";
		}
		else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)))
		{
			valid = false;
			message = message + "Please make sure you have entered a valid e-mail address.\n";
		}
		else if ((phone == "") || (phone == "Phone")) 		
		{
			valid = false;
			message = message + "Please enter your phone number.\n";
		}
		else if ((messageorenquiry == "") || (messageorenquiry == "Message or Enquiry")) 		
		{
			valid = false;
			message = message + "Please enter your message or enquiry.\n";
		}
		
		if (valid == true) 
		{
			//alert(name + email + phone + messageorenquiry);
			sendContact(name, email, phone, messageorenquiry, news);
		}
		else
		{
			alert(message);
		}
	}

	function cleanUpContactForm()
	{
		var form = document.contactusform;

		form.name.value = "Name";
		form.email.value = "Email";
		form.phone.value = "Phone";
		form.messageorenquiry.value = "Message or Enquiry";
	}

	function submitNews()
	{
		var form = document.newsform;
		var message = "";
		var name = form.name.value;
		var email = form.email.value;

		var valid = true;
		
		if ((name == "") || (name == "Name")) 
		{
			valid = false;
			message = message + "Please make sure you have entered your Name.\n";
		}
		else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)))
		{
			valid = false;
			message = message + "Please make sure you have entered a valid e-mail address.\n";
		}
		
		if (valid == true) 
		{
			//alert(name + email + phone + messageorenquiry);
			sendNews(name, email);
		}
		else
		{
			alert(message);
		}
	}

	function cleanUpNewsForm()
	{
		var form = document.newsform;

		form.name.value = "Name";
		form.email.value = "Email";
	}

	//================================================================================================
	// LAYOUT FUNCTIONS
	//================================================================================================
	function setupSlideshows()
	{
		$('.rotating-images').cycle({
			fx: 'fade',
			speed: '3000'
		});
	}

	//================================================================================================
	// EVENTS FUNCTIONS
	//================================================================================================
	//URL ENCODE AND URL DECODE FUNCTION
	$.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
	  while(x<c.length){var m=r.exec(c.substr(x));
	    if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
	    }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
	    o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
	URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
	  while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
	  t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
	});

	function setupActions()
	{
		$('ul#main-nav').delegate('a', 'hover', function(){
			$(this).find('.main-nav-hover').toggleClass("hidden");
		});

		$('#btn-check').click(function(){
			//$(this).children().toggleClass("hidden");
			if ($(this).find('img').hasClass('hidden')){
				//not checked
				$(this).children('img').toggleClass('hidden');
				$('#receive-news').val('true');
			}else{
				//checked
				$(this).children().toggleClass('hidden');
				$('#receive-news').val('false');
			}
		});

		$('.sticky-note').click(function(){
			window.location = $(this).attr('id') + '.php';
		});

		$('.sticky-note-orange').click(function(){
			window.location = 'home-buyers-top-tips.php';
		});

		$('.sticky-note-calculators').click(function(){
			window.location = 'calculators.php';
		});

		$('#ico-hlhc').hover(function(){
			//alert($(this).next().eq(1).attr('src'));
			$(this).children().eq(0).addClass('hidden');
			$(this).children().eq(1).removeClass('hidden');
		}, function(){
			$(this).children().eq(0).removeClass('hidden');
			$(this).children().eq(1).addClass('hidden');
		});
	}

	//================================================================================================
	// SCALLING BACKGROUND
	//================================================================================================
	jQuery(function($){
		var mainBG = 'images/site/bg-header.jpg';
		$.supersized({
			//Functionality
			performance : 2, //0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)
			//Size & Position
			min_width : 1000, //Min width allowed (in pixels)
			min_height : 150, //Min height allowed (in pixels)
			vertical_center : 1, //Vertically center background
			horizontal_center : 1, //Horizontally center background
			fit_portrait : 1, //Portrait images will not exceed browser height
			fit_landscape : 1, //Landscape images will not exceed browser width
			//Background image
			slides	:  [ { image : mainBG } ]					
		});
	});

	//================================================================================================
	// START THIS WHEN PAGE DOM READY
	//================================================================================================
	$(document).ready(function(){
		setupActions();
		setupSlideshows();
	});

//-->
