
try {
    $(document).ready(function() {
		categoryshowmore()
		resourceshowmore()
		externallinks()
		shiftmap()
	});
} catch (e) {
    console.log (e.message);    //this executes if jQuery isn't loaded
}


function shiftmap() {
	$("#switch-map").click(function() {
		var whatclass = $("#content-extra").attr("class");
		switch (whatclass){
			case 'expanded': {
				$(".more-link").show(); // show contact a with this class
				$("#content-extra").removeClass('expanded'); // shrink the sidebar back down
				$("#content-main").show(); // show the map full again
				$("#addlist span").addClass('hidden-details'); // hide the extra details
				$("#addlist span").removeClass('show-details'); // hide the extra details
				$("#switch-map").text('<< Hide map');
				$("#switch-map").attr("title", "Hide map and extend details");
				break 
			}
			default: { 
				$(".more-link").hide(); // hide contact a with this class
				$("#content-extra").addClass('expanded'); // expand the sidebar to full screen
				$("#content-main").hide(); // hide the map comletely
				$("#addlist span").removeClass('hidden-details'); // show extra details
				$("#addlist span").addClass('show-details'); // show extra details
				$("#switch-map").text('Show map >>');
				$("#switch-map").attr("title", "Show map and shrink details");
				break
			}
		}
	});
}

//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");
		},
		function () {
			$("#othertags").slideUp("slow");
			$("#content-secondary .showmore, #filter-category .showmore").text("Show more");
		}
	);
}

//slide to show resource details
function resourceshowmore() {
	$(".resource .details").css("display", "none");
	$(".resource .showmore").toggle(
		function () {
			$(this).parent().children(".details").slideDown("slow");
			$(this).text("Show less");
		},
		function () {
			$(this).parent().children(".details").slideUp("slow");
			$(this).text("Show more");
		}
	);
}


function usePointFromPostcode(postcode, miles) {
	localSearch.setSearchCompleteCallback(null, 
		function() {
			if (localSearch.results[0])
			{		
				var resultLat = localSearch.results[0].lat;
				var resultLng = localSearch.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('Address not found!');
			}
		});	
	localSearch.execute(postcode);
	return false;
}

function usePointFromPostcodeUK(postcode, miles) {
	localSearch.setSearchCompleteCallback(null, 
		function() {
			if (localSearch.results[0])
			{		
				var resultLat = localSearch.results[0].lat;
				var resultLng = localSearch.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 {
				document.getElementById("mapbox").src = '/pages/site.asp?action=googlemaps&fail=true';
			}
		});	
	localSearch.execute(postcode + ', UK');
	return false;
}


// add target="blank" for external links
function externallinks() {
	$("a[rel='external']").attr("target", "_blank");
}
