
$(document).ready(function(){

	// contact us
	if($('#contact_us').length){
		$("#contact_us").validate();
		$("#submit").click(function() {

			if($("#contact_us").valid())
			{
				var data_string = $("#contact_us").serialize();

				$.ajax({
					type: "POST",
					url: "/contact/contact_agent",
					data: data_string,
					success: function() {
						$('#contact_us').html("<div id='reponse'></div>");
						$('#reponse').html("<h2>Thank you</h2>")
						.append("<p>We will be in touch shortly.</p>")
						.hide()
						.fadeIn(1500);
					}
				});

				return false;
			}
			return false;
		});
	}

	// contact agent regarding a property from full details page
	if($('#register').length){
		$("#register").validate();
		$("#submit").click(function() {

			if($("#register").valid())
			{
				var data_string = $("#register").serialize() + '&name=' + $("input#firstname").val() + ' ' +  $("input#lastname").val();

				$.ajax({
					type: "POST",
					url: "/contact/contact_agent",
					data: data_string,
					success: function() {
						$('#register').html("<div id='reponse'></div>");
						$('#reponse').html("<h2>Thank you</h2>")
						.append("<p>We will be in touch shortly.</p>")
						.hide()
						.fadeIn(1500);
					}
				});

				return false;
			}
			return false;
		});
	}

	//email a friend
	if($('#email_friend').length){
		$("#email_friend").validate();
		$("#submit").click(function() {

			if($("#email_friend").valid())
			{
				var data_string = $("#email_friend").serialize();

				$.ajax({
					type: "POST",
					url: "/contact/email_friend",
					data: data_string,
					success: function() {
						$('#email_friend').html("<div id='reponse'></div>");
						$('#reponse').html("<h2>Thank you</h2>")
						.append("<p>Your message has been sent successfully.</p>")
						.hide()
						.fadeIn(1500);
					}
				});

				return false;
			}
			return false;
		});
	}

	// freetext default value
	if($('#freetext').length)
	{
		var default_value = 'Street / Postcode';
		$('#freetext').focus(function() {
			$(this).css({'color':'#000'});
			if(this.value == default_value) {
				this.value = '';
			}
		});

		$('#freetext').blur(function() {
			if(this.value == '') {
				$(this).css({'color':'#666'});
				this.value = default_value;
			}
		});
	}

	// full pressroom pdf
	$('a.pressroom_pdf').click(function(){
		$(".pressroom_pdf").colorbox({width:"80%", height:"80%", iframe:true});
	});

	// property images slideshow
	 $('a.photo').click(function(){
	 	var class_name = $(this).attr('rel');
		$("a[rel='"+ class_name +"']").colorbox({slideshow:true});
	});

   $('a.floorplan').click(function(){
	 	var class_name = $(this).attr('rel');
	 	var image_path = $(this).attr('href');

		$("a[rel='"+ class_name +"']").colorbox({
		    slideshow:false,
		    height:"100%",
		    maxWidth: "100%"
		});
	});

	$('a.brochure').click(function(){
        window.open($(this).attr('href'));
        return false;
	});

	// property location map
	$('a.map').click(function(){
		$("a.map").colorbox({width:"80%", height:"80%", iframe:true});
	});

	// contact agent
	$('a.contact_agent').click(function(){
		$("a.contact_agent").colorbox({width:"450", height:"460px", iframe:true});
	});

	// property EPC
	$('a.epc').click(function(){
	 	var class_name = $(this).attr('rel');
		$("a[rel='"+ class_name +"']").colorbox({height:"400px"});
	});

	// property brochure
	$('a.brochure').click(function(){
        $("a.brochure").colorbox({width:"80%", height:"80%", iframe:true});
	});

	// email a friend
	$('a.email').click(function(){
		$("a.email").colorbox({width:"600px", height:"450px", iframe:true});
	});

	// owner's insight
	$('a.owners_insight').click(function(){
		var owners_insight_id = $(this).attr('rel');
		$('a.owners_insight').colorbox({width:"50%", inline:true, href:"#" + owners_insight_id + ""});
	});

	// request appraisal
	$('a.request_appraisal').click(function(){
		$(".request_appraisal").colorbox({width:"450", height:"400px", iframe:true});
	});
});
