/*
FREEZE FORM SUBMISSIONS FOR TESTING
$.validator.setDefaults({
	submitHandler: function() { alert("submitted!"); }
});
*/
$(function(){

	$("ul.nav_locations li").hover(function(){
		$(this).addClass("hover");
		$('ul:first',this).css('visibility', 'visible');
	}, function(){
		$(this).removeClass("hover");
		$('ul:first',this).css('visibility', 'hidden');
		//if($(this).parent().hasClass('nav_locations')){
		//	if($(this).siblings().hasClass('nav_locations')){
		//	}
		//	else{
		//		$("ul.nav_locations").hide();
		//	}
		//}
	});

});

$(document).ready(function(){
	// LOCATION NAVS
	//$(".nav_locations_country").hide();
	//$(".nav_locations_area").hide();
	
	// FACEBOX
	$('a[rel*=facebox]').facebox({
		loading_image : '/interface/images/facebox/loading.gif',
		close_image   : '/interface/images/facebox/closelabel.gif'
	})

	// CYCLE
	$('.header_images').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	
	// TOOLTIPS
	$(".trigger").tooltip({
		offset: [30, 80],
		effect: 'slide'
	// add dynamic plugin with optional configuration for bottom edge
	}).dynamic({ bottom: { direction: 'down', bounce: true } });

	// VALIDATION
	$("#lookingfor_form").validate();
	$("#property_enquiry1_form").validate();
	$("#property_enquiry2_form").validate();
	
	// PROPERTY ENQUIRY SLIDERS
	$('div.property_enquiry').hide()
	$("h3.property_interested").click(function(){
		if ($(this).next().is(":hidden")) {
			$(this).next().slideDown("slow");
		} else {
			$(this).next().slideUp("slow");
		}
		return false;
	});

	// DATE PICKER
	$('.date_pick').datePicker({clickInput:true})
	$('.date_from').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('.date_to').dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	$('.date_to').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('.date_from').dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);

	// PROPERTY THUMBS
	$("#property_images .left a").click(function(){
		$("#property_images .left li").removeClass('selected');
		$("#property_images .left a").removeClass('selected');
		$(this).parent().addClass('selected');
		$(this).addClass('selected');

		$("#property_images .right img").attr({
			src: $(this).attr("href")
		});
		return false;
	});

	// EMPTY INPUT FIELDS ON CLICK
	$('input[type="text"]').clearField();

});

$.fn.clearField = function(){
	return this.focus(function() {
		if( this.value == this.defaultValue){
			this.value = "";
		}
	}).blur(function(){
		if( !this.value.length){
			this.value = this.defaultValue;
		}
	});
};
