/**************Default text plugin****************/
(function($){
	$.fn.extend({ 
		defaultText: function(text) {
			return this.each(function() {
				if($(this).val() == ''){
					$(this).addClass("default-text");
					$(this).val(text);
				}

				$(this).focus(function(){
					if($(this).val() == text){
						$(this).val("");
						$(this).removeClass("default-text");
					}
				})

				$(this).blur(function(){
					if($(this).val() == ""){
						$(this).addClass("default-text");
						$(this).val(text);
					}
				})
			});
		}
	});
})(jQuery);




function closePopup(){
	$.prettyPhoto.close();
}



function populate(name,value){

	var field = $('*[name="fields['+name+']"]');
	var type = field.attr('type');
	
	switch(type){
		case 'checkbox':
			if(value == 'No'){
				field.attr('checked', false);
			}else{
				field.attr('checked', true);
			}
			break;
		default:
			field.val(value);
	}
}



$(document).ready(function() {
	/* menu lavalamp */
	if($("#main-menu li a.active").length == 1){
		$("#main-menu").lavaLamp({
			target:'li.menu-item',
			fx: "backout", 
			speed: 700
		});
	}

	/* form data */
	$('#form-data li').each(function(){
		populate($(this).attr('class'),$(this).html());
	});

	
	/* further detail */
	var furtherDetailText = "Please provide as much relevant information as possible...\n   -nature of query\n   -details of property\n   -location\n   -approx. value etc.";
	var furtherDetailField = $('#quickform textarea#further-detail');
	
	furtherDetailField.defaultText(furtherDetailText);
	
	
	/* form submit */
	$('#quickform form .submit').click(function(){
		if(furtherDetailField.val() == furtherDetailText){
			furtherDetailField.val('');
		}

		$('#quickform form #submit-hidden').click();

		return false;
	})
});



