// JavaScript Document for common routines

// jquery onload actions
$(document).ready(function(){
	categoryshowmore()
	resourceshowmore()
	externallinks()
});

//slide to show other categoies
function categoryshowmore() {
	$("#othertags").css("display", "none");
	$("#content-secondary .showmore, #filter-category .showmore").toggle(
		function () {
			$("#othertags").slideDown("slow");
			$("#content-secondary .showmore, #filter-category .showmore").text("Show less categories");
			$(this).css("background-image", "url(/site/images/bullet_toggle_minus.png)");
		},
		function () {
			$("#othertags").slideUp("slow");
			$("#content-secondary .showmore, #filter-category .showmore").text("Show more categories");
			$(this).css("background-image", "url(/site/images/bullet_toggle_plus.png)");
		}
	);
}

//slide to show resource details
function resourceshowmore() {
	$(".resource .details").css("display", "none");
	$(".resource .showmore").toggle(
		function () {
			$(this).parent().children(".details").slideDown("slow");
			$(this).text("Hide details");
			$(this).css("background", "url(/site/images/bullet_toggle_minus.png) no-repeat 480px 7px");
		},
		function () {
			$(this).parent().children(".details").slideUp("slow");
			$(this).text("Show details");
			$(this).css("background", "url(/site/images/bullet_toggle_plus.png) no-repeat 480px 7px");
		}
	);
}


function usePointFromPostcode(postcode,miles) {
	
	newlocalSearch.setSearchCompleteCallback(null, 
		function() {
			if (newlocalSearch.results[0])
			{		
				var resultLat = newlocalSearch.results[0].lat;
				var resultLng = newlocalSearch.results[0].lng;
				document.getElementById("mapbox").src = "/pages/site.asp?action=googlemaps&lat=" + resultLat + "&long=" + resultLng + "&postcode=" + postcode + "&miles=" + miles;
				document.getElementById("mapbox").height = "600";
			}else{
				alert("Postcode not found!");
			}
		});	
	
	newlocalSearch.execute(postcode + ", UK");
	return false;
}


// add target="blank" for external links
function externallinks() {
	$("a[rel='external']").attr("target", "_blank");
}