var map = null;
var mgr = null;

function setupMap() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		centerPoint = locations[0].GeoCode.split(",")
		map.setCenter(new GLatLng(centerPoint[0], centerPoint[1]), 10);
		window.setTimeout(setupMarkers, 0);
		}
	}

function Marker () {
	var i = arguments[0];
	var loc = locations[i].GeoCode.split(",");
	var m = new GMarker(new GLatLng(loc[0], loc[1]));
	var desc = "<h5>" + locations[i].StoreName + "<\/h5>"
		desc += locations[i].Address + "<br />"
		desc += locations[i].Suburb + " " + locations[i].PostCode + " " + locations[i].State + "<br />"
		desc += "PH : " + locations[i].Phone
	GEvent.addListener(m, "mouseover", function() {if (map.getZoom() > 15) {m.openInfoWindowHtml(desc);}  });  
	return m
	}	
	
function getMarkers() {
	var batch = [];
	
	for (var i = 0; i < locations.length; ++i) {
		batch.push(new Marker(i));
		}
	return batch;
	}
	
function setupMarkers() {
	mgr = new GMarkerManager(map);
	mgr.addMarkers(getMarkers(), 3);
	mgr.refresh();
	}
	
	
currentStore = null;
		
function loadStore(store) {
	thisStore = document.getElementById("store_" + store);
	if (currentStore != null) {
		currentStore.className = currentStore.className.replace("currentStore", "");
		}
	
	thisStore.className = thisStore.className + " currentStore ";
	
	currentStore = thisStore;
	document.getElementById("location-name").innerHTML = locations[store].StoreName.toLowerCase();
	document.getElementById("location-address").innerHTML = locations[store].Address.toLowerCase() + "<br />" + locations[store].Suburb.toLowerCase();
	document.getElementById("location-phone").innerHTML = locations[store].Phone;
	document.getElementById("location-fax").innerHTML = locations[store].Fax;
	document.getElementById("location-distance").innerHTML = locations[store].Distance > 0 ? ("Approximatly " + locations[store].Distance + " Kms") : "Under 1 Km";
	//alert(locations[store].GeoCode != "")
	if (locations[store].GeoCode != "" ) {
		document.getElementById("map").style.display = "block";
		document.getElementById("nomap").style.display = "none";
		centerPoint = locations[store].GeoCode.split(",")
		map.setCenter(new GLatLng(centerPoint[0], centerPoint[1]), 16);
		
		}
	else {
		document.getElementById("map").style.display = "none";
		document.getElementById("nomap").style.display = "block";
		}

	}