function DESemail(emailname,emailserver) {
	document.write("<a href='mailto:" + emailname + "@" + emailserver +"'>");
	document.write(emailname + "@" + emailserver); 
	document.write("</a>"); 
}

// Accessible Pop Ups
function DESopen(url,width,height,toolbar,scroll) {
	window.open(url, "", "scrollbars="+scroll+",toolbar="+toolbar+",height="+ height +",width="+width);
	return false;
}



var price_num_to_range = {
	"0" : "£1,000",
	"1" : "£5,000",
	"2" : "£10,000",
	"3" : "£20,000",
	"4" : "£30,000",
	"5" : "£40,000",
	"6" : "£50,000+"
};

var price_range_to_num = {
	"£1,000" : "0",
	"£5,000" : "1",
	"£10,000" : "2",
	"£20,000" : "3",
	"£30,000" : "4",
	"£40,000" : "5",
	"£50,000+" : "6"
};

var dimensions_num_to_range = {
	"0" : "20ft²",
	"1" : "100ft²",
	"2" : "500ft²",
	"3" : "1,000ft²",
	"4" : "5,000ft²",
	"5" : "10,000ft²",
	"6" : "20,000ft² +"
};


var dimensions_range_to_num = {
	"20ft²" : "0",
	"100ft²" : "1",
	"500ft²" : "2",
	"1,000ft²" : "3",
	"5,000ft²" : "4",
	"10,000ft²" : "5",
	"20,000ft² +" : "6"
};



/* Slider Stuff */

$(window).bind("load",function(){
	
	// Price Slider
	if (document.getElementById("price_slider")) {
		$('#price_slider').slider({
			steps: 6,
			handles: [{start:0, min:0, max:6, id:"price1"}, {start:6, min:1,max:6, id:"price2"}], 
			min: 0,
			max: 6, 
			range: true,
			slide: function(e,ui) {
				var handleId = ui.handle.attr("id");
				var handleVal = price_num_to_range[ui.value];
				if (handleId=='price1') { $("#price1_val").val(handleVal); }
				else { $("#price2_val").val(handleVal); }
			}
		});
	}
	
	// Dimensions Slider
	if (document.getElementById("dimensions_slider")) {
		$('#dimensions_slider').slider({
			steps: 6,
			handles: [{start:0, min:0, max:6, id:"dimen1"}, {start:6, min:1,max:6, id:"dimen2"}], 
		min: 0,
		max: 6, 
			range: true,
			slide: function(e,ui) {
				var handleId = ui.handle.attr("id");
				var handleVal = dimensions_num_to_range[ui.value];
				if (handleId=='dimen1') { $("#dimen1_val").val(handleVal); }
				else { $("#dimen2_val").val(handleVal); }
			}
		});
	}
	
	/* check current slider vals and update the values
	(need to do the second handle first apparently... not sure why!)
	*/
	
	if (document.getElementById("price_slider")) {
		var price2_val = price_range_to_num[$("#price2_val").val()];
		$('#price_slider').slider('moveTo',price2_val,1);
		
		var price1_val = price_range_to_num[$("#price1_val").val()];
		$('#price_slider').slider('moveTo',price1_val,0);
	}
	
	if (document.getElementById("dimensions_slider")) {
		var dimen2_val = dimensions_range_to_num[$("#dimen2_val").val()];
		$('#dimensions_slider').slider('moveTo',dimen2_val,1);
		
		var dimen1_val = dimensions_range_to_num[$("#dimen1_val").val()];
		$('#dimensions_slider').slider('moveTo',dimen1_val,0);
	}
	
	// hide cabinsearch if required
	if (document.getElementById("cabinsearch")) {
		if ($("#cabinsearch").hasClass("hidden")) {
			$("#cabinsearch").hide();
		}
	}
	
});



$(document).ready(function(){

	$("#blog_months").change( function() {
		var pageLoc = $(this).val();
		window.location=pageLoc;
	});
	
	$("#showfilters").click(function() {
		if ($(this).hasClass('hide')) {
			$(this).removeClass('hide');
			$(this).text("Show Filters");
			//$("#cabinsearch").hide();
			$("#cabinsearch").slideUp("fast");
		}
		else {
			$(this).addClass('hide');
			$(this).text("Hide Filters");
			$("#cabinsearch").slideDown("fast");
		}
		return false;
	});
	
	if (document.getElementById("home_bullets")) {
		$('#home_bullets').cycle({ 
		    fx: 'scrollVert',
		    speed: 500, 
	    	timeout: 6000 
		});
		$('#home_bullets').hover(
			function() {
				 $('#home_bullets').cycle('pause');
				 $(this).addClass('hovered');
			},
			function() {
				$('#home_bullets').cycle('resume');
				$(this).removeClass('hovered');
			}
		);
		$('#home_bullets').click(
			function() {
				window.location='/buyers-guide/advantages-of-second-hand-buildings/';
			}
		);
	}
	
	if ($('#main').get(0)) {
		$('#main ul').cycle({ 
			fx: 'scrollDown',
			speed: 500, 
			timeout: 5000,
			pager:  '#productthumbs', 
			pagerAnchorBuilder: function(idx, slide) { 
				// return selector string for existing anchor 
				return '#productthumbs li:eq(' + idx + ')'; 
			}
		});
		
		$("#productthumbs a").click (function(){	
			$('#main ul').cycle('pause'); 
		});
	}
	
	

});