$(document).ready(
	function(){
    
		toggleStores();
		changeText("#store-locator .instructions p","<p>To choose your local store select the region closest to you by rolling over the map to the right. Then choose your local New World from the menu that will appear.</p>");

	}
);

// Replace text inside matched element
function changeText(match,text){
	if($(match).length > 0){
		$(match).replaceWith(text);
	} 
}


// Show list of stores when click on map region
function toggleStores(){
	$("#store-locator > .map > map > area").click(
		function(){
			
			// Hide any displayed store lists
			$("#store-locator > .map > .stores").remove();
			
			// Get ID attribute to target Store Locations
			var region = $(this).attr("id");
			
			// Create new store list
			$("#store-locator > .map").append("<div class=\"stores\">"+
				"<a class=\"close\" href=\"close\">close</a>"+
				$("#store-locations li."+region).html()+
				"</div>");
				
			// Bind close link to remove store list
			$("#store-locator .map .stores a.close").bind("click",closeStores);
			return false;
		}
	);
}

// Remove the displayed stores module
function closeStores(){
	$("#store-locator .map .stores").remove();
	return false;
}