//  Modal Windows

$().ready(function() {
	$('#interest-list').jqm({
		trigger: 'a.interest-list-t',
		overlay: 50
	});
	$('#broker-sign-up').jqm({
		trigger: 'a.broker-sign-up-t',
		overlay: 50
	});
	$('#tell-a-friend').jqm({
		trigger: 'a.tell-a-friend-t',
		overlay: 50
	});
	$('#virtualTourEVid').jqm({
		trigger: 'a.virtualTourET',
		overlay: 75
	});
	$('#virtualTourFVid').jqm({
		trigger: 'a.virtualTourEF',
		overlay: 75
	});
	$('#marjorie-finish').jqm({
		trigger: 'a.marjorieT',
		overlay: 75
	});
	$('#elmer-finish').jqm({
		trigger: 'a.elmerT',
		overlay: 75
	});
	
	// Marjorie Finish
	
	$("#marjorie-finish a").tooltip({ 
	    bodyHandler: function() { 
	        return $($(this).attr("href")).html(); 
	    }, 
	    showURL: false 
	});
	
	// Elmer Finish
	
	$("#elmer-finish a").tooltip({ 
	    bodyHandler: function() { 
	        return $($(this).attr("href")).html(); 
	    }, 
	    showURL: false 
	});
	
});

// Suckerfish / Drop Down Menus

$(document).ready(function () {
  var li = $('#actual-nav li');
  li.mouseover(function () {
    $(this).addClass('over');
  });
  li.mouseout(function () {
    $(this).removeClass('over');
  });
});



// FORM VALIDATION //////////////////////////////////////////////////////////////////////////////////


function validate(mode){
	
	
	var baseURL = 'http://www.bluwatercrossing.com/wp-content/themes/bwc-theme/';
	
	var mode = mode.toString();
	
	
	switch(mode){
		
		
		case 'interest':
			
			var params = new Array('firstname','lastname','address1','address2','city','state','zip','source','other','email','phone','interested','comment'); 
		
			$.ajax({
				type: "POST",
				url: baseURL+'ajax.php',
				data: buildQuery(params,'interest'),
				async: false,
				success: handleResponseInterest
			});

		break;
		
		
		case 'broker':
			
			var params = new Array('firstname','lastname','address1','address2','city','state','zip','email','phone','comment','broker_office','care_number','source','other'); 
		
			$.ajax({
				type: "POST",
				url: baseURL+'ajax.php',
				data: buildQuery(params,'broker'),
				async: false,
				success: handleResponseBroker
			});

		break;
		
		
		case 'friend':
			
			var params = new Array('firstname','email','other','comment'); 
		
			$.ajax({
				type: "POST",
				url: baseURL+'ajax.php',
				data: buildQuery(params,'friend'),
				async: false,
				success: handleResponseFriend
			});

		break;
		
	}
	
}


function buildQuery(params,mode){
	
	var output = 'mode=' + mode;
	
	for (var i in params){
		
		var val = $('#' + mode + '_' + params[i]).val();

		output += '&' + params[i] + '=' + val ;
	}
	
	return output;
	
}

function handleResponseInterest(msg){
	
	//alert(msg);
	
	handleResponse(msg,'interest');
}


function handleResponseBroker(msg){
	
	//alert(msg);
	
	handleResponse(msg,'broker');
}

function handleResponseFriend(msg){
	
	//alert(msg);
	
	handleResponse(msg,'friend');
}


function handleResponse(msg,mode){
	
	var parts = msg.split('|'); 
	
	if (parts[0].toString() == '1'){
		
		$('#form_'+mode).html('<p>&nbsp;</p>');
		
		switch(mode){
			
			case 'interest':
			
				$('#'+mode+'_message').html('<p>Thanks for being part of the movement toward balanced living. We\'ll be sending you regular updates on our progress. <br><br>In order to ensure the receipt of Bluwater Crossing property updates, please be sure to add <b>bluwater_crossing@mail.vrsp.com</b> to your address book. <br><br>In the meantime, if you\'ve got a friend who you believe is ready to embrace balance, please feel free to refer them to Bluwater Crossing. They\'ll probably thank you for it later.</p> <img height="1" width="1" border="0" src="http://www.googleadservices.com/pagead/conversion/1036380293/?label=m1CbCIvYZxCF0ZfuAw&amp;script=0"/> <img src="https://cts.vresp.com/s.gif?h=47bf3b7d52" height="1" width="1"/> ');
				
				pageTracker._trackPageview('/goal/signup/');
				
				conversion();
			
			break;
			
			
			case 'broker':
			
				$('#'+mode+'_message').html('<p>Thanks for being part of the movement toward balanced living. We\'ll be sending you regular updates on our progress. <br><br>In order to ensure the receipt of Bluwater Crossing property updates, please be sure to add <b>bluwater_crossing@mail.vrsp.com</b> to your address book. <br><br>In the meantime, if you\'ve got a client who you believe is ready to embrace balance, please feel free to refer them to Bluwater Crossing. They\'ll probably thank you for it later.</p> <img height="1" width="1" border="0" src="http://www.googleadservices.com/pagead/conversion/1036380293/?label=m1CbCIvYZxCF0ZfuAw&amp;script=0"/> <img src="https://cts.vresp.com/s.gif?h=47bf3b7d52" height="1" width="1"/>  ');
			
				pageTracker._trackPageview('/goal/signup/');
				
				conversion();
				
			break;
			
			default:
			
				$('#'+mode+'_message').html('<p>Thanks for sharing the movement toward balanced living.</p> <img src="https://cts.vresp.com/s.gif?h=47bf3b7d52" height="1" width="1"/>  ');
			
			break;
		}
		
		

	}
	
	else {
		
		$('#'+mode+'_message').html('<p style="color:#CC0000"><b>'+parts[1]+'</b></p>');
		
		$('fieldset').removeClass('error');
		
		$('#f_'+mode+'_'+parts[2]).addClass('error');

	}
}



function conversion() {
	
	var iframe = document.createElement('iframe');

	iframe.style.width = '0px';
	
	iframe.style.height = '0px'; 
	
	document.body.appendChild(iframe); 
	
	iframe.src = 'http://www.bluwatercrossing.com/pixel.php';

};


function bluewater(){
	
	window.location = 'http://www.bluwatercrossing.com';
}


	
function pop(url,width,height) { 

	day = new Date();

	eval("page" + day.getTime() + " = window.open(url, '" + day.getTime() + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left = " + ($(window).width() - width)/2 + ",top = " + ($(window).height() - height)/2 + "');"); 

}


