
function applyst() {
    load();
    if( window.XTRonload ) { window.XTRonload(); }
}
function savest() {
    GUnload();
    if( window.XTRonunload ) { window.XTRonunload(); }
}

//load handling adapted from
//http://www.brothercake.com/site/resources/scripts/onload/
if( window.addEventListener ) {
    window.addEventListener( 'load', applyst, false );
    window.addEventListener( 'unload', savest, false );
} else if( document.addEventListener ) {
    document.addEventListener('load' , applyst, false );
    document.addEventListener( 'unload', savest, false );
} else if( window.attachEvent ) {
    window.attachEvent( 'onload', applyst );
    window.attachEvent( 'onunload', savest );
} else {
    if( window.onload ) { window.XTRonload = window.onload; }
    if( window.onunload ) { window.XTRonunload = window.onunload; }
    window.onload = applyst;
    window.onunload = savest;
}

var bubble =  "	<div id='map_bubble'> \
							<h3>Anna Perena</h3> \
							10a High Street East<br/> \
							Glossop<br/> \
							Derbyshire<br/> \
							SK13 8DA<br /> \
							ENGLAND<br /> \
							<br /> \
							<form onSubmit=\"getDirections(); return false;\" action=\"getDirections(); return false;\"> \
							<div id=\"get_directions\">Get directions: <a href=\"javascript:directionsToHere();\">To here</a> - <a href=\"javascript:directionsFromHere();\">From here</a>&nbsp;</div> \
							<div id=\"directions\"  style=\"display:none;\"> \
									<div id=\"d_text\">Start address:</div> \
									<input type=\"text\" id=\"address\" size=\"18\" /> \
									<input type=\"button\" value=\"Go\" onClick=\"getDirections();\" /> <br />\
									<a href=\"javascript:directionsBack();\">&laquo; Back</a> \
							</div> \
							<div id=\"directions_placeholder\"><br /><br /><br /></div> \
							</form> \
						</div>";	
    //<![CDATA[
	
	
    function load() {
      if (GBrowserIsCompatible()) {
      	var center = new GLatLng(53.44328, -1.948206);
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(center, 7);
        marker = new GMarker(center)
        GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(bubble);
		});
		map.addOverlay(marker);
		marker.openInfoWindowHtml(bubble);
        
      }
    }

    //]]>

var directionsTo = true;

function convert(input) {
					var output = "";
					for (var i = 0; i < input.length; ++i) 
					{
						var temp = input.charAt(i); if (temp == " ") temp = "+";
						output += temp;
					}
					return output;
				}

function getDirections() {
	if (document.getElementById('address').value != "") {
		var address = convert(document.getElementById('address').value);
		if (directionsTo == true) {
			window.open('http://maps.google.com/maps?saddr='+address+'&daddr=10a+High+St+East,+Glossop,+Derbyshire,+SK13+8DA+(Anna+Perena)+%4053.443154,-1.948206');
		}
		else {
			window.open('http://maps.google.co.uk/maps?saddr=10a+High+St+East,+Glossop,+Derbyshire,+SK13+8DA+(Anna+Perena)+%4053.443154,-1.948206&daddr='+address);
		}
	}
}

function directionsToHere() {
	document.getElementById('get_directions').innerHTML = "<b>Get directions</b>: To here - <a href=\"javascript:directionsFromHere();\">From here</a>";
	document.getElementById('d_text').innerHTML = "Start address:";
	document.getElementById('directions_placeholder').style.display = "none";
	document.getElementById('directions').style.display = "inline";
	directionsTo = true;
}
function directionsFromHere() {
	document.getElementById('get_directions').innerHTML = "<b>Get directions</b>: <a href=\"javascript:directionsToHere();\">To here</a> - From here";
	document.getElementById('d_text').innerHTML = "End address:";
	document.getElementById('directions_placeholder').style.display = "none";
	document.getElementById('directions').style.display = "inline";
	directionsTo = false;
}
function directionsBack() {
	document.getElementById('get_directions').innerHTML = "Get directions: <a href=\"javascript:directionsToHere();\">To here</a> - <a href=\"javascript:directionsFromHere();\">From here</a>";
	document.getElementById('directions').style.display = "none";
}
