﻿	
	
	
	//Price slider JS
	
	$(function() {
		
		$("#slider-tobuy").slider({
			range: true,
			min: 0,
			step: 20,
			max: 1000,
			values: [0, 1000],
			slide: function(event, ui) {
				
				$("#amount-tobuy").val('£' + ui.values[0] + 'k' + ' - £' + ui.values[1]  + 'k');
				
				if (ui.values[1] == 1000 ) {
					$("#amount-tobuy").val('£' + ui.values[0] + 'k' + ' - £1m+');
				} 
			}
		});
		
		if ($("#slider-tobuy").slider("values", 1) == 1000){
			$("#amount-tobuy").val('£' + $("#slider-tobuy").slider("values", 0) + 'k' + ' - £1m+');		
		} else {
			$("#amount-tobuy").val('£' + $("#slider-tobuy").slider("values", 0) + 'k' + ' - £' + $("#slider-tobuy").slider("values", 1) + 'k');		
		}
		
		
		$("#slider-torent").slider({
			range: true,
			min: 0,
			step: 5,
			max: 150,
			values: [0, 150],
			slide: function(event, ui) {
				$("#amount-torent").val('£' + $("#slider-torent").slider("values", 0) + 'k' + ' - £' + ui.values[1]+'k');	
				if (ui.values[1] == 150 ) {
					$("#amount-torent").val('£' + ui.values[0] + 'k' + ' - £150k+');
				} 
			}
		});
		
		if ($("#slider-torent").slider("values", 1) == 150){
			$("#amount-torent").val('£' + $("#slider-torent").slider("values", 0) + 'k' + ' - £150k+');		
		} else {
			$("#amount-torent").val('£' + $("#slider-torent").slider("values", 0) + 'k' + ' - £' + $("#slider-torent").slider("values", 1) + 'k');		
		}
		
			
		
		$("#tenure").change(function () {
			var selectedTenure =  $("#tenure option:selected").text();
			
			if (selectedTenure == 'To Buy'){
			
				$("#torentdiv").hide();
				$("#tobuydiv").show();
			} else if (selectedTenure == 'To Rent'){
			
				$("#torentdiv").show();
				$("#tobuydiv").hide();
			} else if (selectedTenure == 'To Buy/To Rent'){
				$("#torentdiv").hide();
				$("#tobuydiv").hide();
				$("#tenureh3").addClass('.tenureh3');
			}
		
		});
		
		
		// set up slide and hide search options JS
		
		
		
		
		$(".open").click(function () {
			$("#searchcrit").slideToggle("slow");
			if ($(".open").text() == 'HIDE Search Options')
			{
				$(".open").text('SHOW Search Options');
		
				$("#contentleft2").height('auto');
				$("#propfields input").attr("disabled", "");
				$("#propfields select").attr("disabled", "");				

			} else {
				$(".open").text('HIDE Search Options');
				var fixedheight = $("#main").height();
				$("#contentleft2").height(fixedheight);
				
				$("#propfields input").attr("disabled", "disabled");
				$("#propfields select").attr("disabled", "disabled");
			}
			
		});
		
		//scroll to top JS

		$(document).ready(function() {

		$('.backtotop').click(function(){

		$('html, body').animate({scrollTop:0}, 'slow'); return false; 

			});

		})
		
		// rel external js
		
		function externalLinks() {
		if (!document.getElementsByTagName) return;
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		   anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
		}
		}
		window.onload = externalLinks;	
		
		//create fixed hieghts on divs whose content doesnt fill screen
		//var fixedheight = $("#main").height();
		//$("#contentleft, #contentleft2").height(fixedheight);
		
		if ($("#contentleft").height() < 600){
			var fixedheight = $("#main").height();
			$("#contentleft").height(fixedheight);
		}
		if ($("#contentleft2").height() < 600){
			var fixedheight = $("#main").height();
			$("#contentleft2").height(fixedheight);
		}
		
		$('.cltop').cycle({ 
			timeout: 10000 
		});
		
	});