$(document).ready(function() {
	//Initiate Data Structure holding all image src's and associated area data
	var mapImages = new Object();
	mapImages["national"] = ["../map.gif", "National", "Choose a region to the right, to view more information"];
	mapImages["bradford"] = ["Bradford.gif", "Bradford", "including Keighley, Bingley, Shipley"];
	mapImages["derbyshire"] = ["Derbyshire.gif", "Derbyshire", ""];
	mapImages["gateshead"] = ["Gateshead.gif", "Gateshead", ""];
	mapImages["kirklees"] = ["Kirklees.gif","Kirklees", "including Huddersfield, Dewsbury, Batley, Cleckheaton, Holmfirth"];
	mapImages["lancashire"] = ["Lancashire.gif","Lancashire", "except Blackpool, Blackburn and Darwen"];
	mapImages["leeds"] = ["Leeds.gif","Leeds", ""];
	mapImages["merseyside"] = ["Merseyside.gif","Merseyside", "except St. Helens"];
	mapImages["oldham"] = ["Oldham.gif","Oldham", ""];
	mapImages["peterborough"] = ["PeterCambs.gif","Peterborough and Central Cambridgeshire", "including Peterborough, Wisbech, Whittlesey, March, Chatteris, Huntingdonshire"];
	mapImages["wolverhampton"] = ["Wolverhampton.gif","Wolverhampton", ""];
	mapImages["yorkshire"] = ["Southyorks.gif","South Yorkshire", "including Rotherham, Sheffield, Doncaster and Barnsley"];
	mapImages["telford"] = ["TelfWreak.gif","Telford and Wrekin", ""];
	mapImages["barking"] = ["London.gif","London Borough of Barking and Dagenham", ""];
	mapImages["havering"] = ["London.gif","London Borough of Havering", ""];
	mapImages["bedfordshire"] = ["Bedfordshire.gif","Bedfordshire", ""];
	mapImages["croydon"] = ["London.gif","London Borough of Croydon", ""];
	mapImages["merton"] = ["London.gif","London Borough of Merton", ""];
	mapImages["richmond"] = ["London.gif","London Borough of Richmond", ""];
	mapImages["sutton"] = ["London.gif","London Borough of Sutton", ""];
	mapImages["middlesbrough"] = ["London.gif","Middlesbrough", ""];


	
	//If url already contains map data then load that map
	var myUrl = $(document).url()
	if(myUrl.attr('hash') != null)
	{
		$("div#mapimagecontainer").html(generateMapContent(myUrl.attr('hash')));
	}
	
	//Add a # to each of the internal links for jquery goodness!
	$("a.mapLink").each(function(){
		$(this).attr('href', '#'+$(this).attr('href'));
	});
	
	//Deal with hover over a map link, load relevent map
	$("a.mapLink").hoverIntent(function(){
		var mapID = $(this).attr('href').substr(1);
		myUrl.attr('hash',mapID);
		$("div#mapimagecontainer").hide();
		$("div#mapimagecontainer").html(generateMapContent(mapID));
		$("div#mapimagecontainer").fadeIn("slow");
		return false;
	}, function(){});
	
	
	//When the mouse is no longer in the focus of the content area, switch back to map of UK
	$("div#content-wrapper").hoverIntent(function(){},function(){
		$("div#mapimagecontainer").hide();
		$("div#mapimagecontainer").html(generateMapContent("national"));
		$("div#mapimagecontainer").fadeIn("slow");
	});

	
	//Function to generate map data and contents from key
	function generateMapContent(mapID)
	{
		var link = "<a href='/where/"+mapID+"/'>View more information about "+mapImages[mapID][1]+" schemes</a>";
		return ["<h2>"+mapImages[mapID][1]+"</h2>",
		"<img src='"+templateDir+"/style/images/areas/"+mapImages[mapID][0]+"' />",
		"<p class='extraInfo'>"+mapImages[mapID][2]+"</p>", link].join('');
	}
});