// JavaScript Document
//ABQIAAAAcvbUJIZuwVCY-oARk54yQBRlfEFKqGgjnWOYpvLyN-KPqjzlHRSLXXuszSZ5bMlbxFVjx1wUeew7Lg

function createMarker(point,html) {
	var icon = new GIcon();
	icon.image = 'images/house.gif';
	icon.iconSize = new GSize(15, 15);
	icon.iconAnchor = new GPoint(icon.iconSize.width / 2, icon.iconSize.height / 2);
	icon.infoWindowAnchor = new GPoint(icon.iconSize.width / 2, 6);
	var marker = new GMarker(point,icon);
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
	return marker;
}

function initialize() {
	if (GBrowserIsCompatible()) {
    	map = new GMap2(document.getElementById("map_canvas"));
        map.setMapType(G_HYBRID_MAP);
		var startLong=-23.866994;
		var startLat= 35.540105;
		var startZoom=11;
		map.setCenter(new GLatLng(startLong,startLat), startZoom);
        map.setUIToDefault();
    }
	
	var bounds = map.getBounds();
	var southWest = bounds.getSouthWest();
	var northEast = bounds.getNorthEast();
	var lngSpan = northEast.lng() - southWest.lng();
	var latSpan = northEast.lat() - southWest.lat();
	
	var divMarkersDiv=document.getElementById("divMarkers");
	var loc;
	if(divMarkersDiv) var childDivs=divMarkersDiv.getElementsByTagName("div");
	if(childDivs && childDivs.length>0){
		var coOrds;
		var gCoords;
		var txt;
		for (var i=0;i<childDivs.length;i++){
			if (childDivs[i].id != "dummyMarker"){
				loc=childDivs[i].id.replace("div","");	
				coOrds=getCoOrds(loc);
				gCoords = new GLatLng(coOrds.lat, coOrds.long);
				txt=childDivs[i].innerHTML;
				map.addOverlay(createMarker(gCoords,txt));
			}
		}
	}
}

function zoomTo(z){
	// zoom in function, not zoom to...
	var maxZoom=18;
	var currentZoom=map.getZoom();
	var newZoom;
	
	if (arguments.length==0){
		newZoom=Math.floor((maxZoom-currentZoom)/2)+currentZoom;
	}else{
		newZoom=z;
	}
	if (newZoom>maxZoom) newZoom=maxZoom;
	map.setZoom(newZoom);
}

function setLoc(propName){
	var latLong=getCoOrds(propName);
	map.setCenter(new GLatLng(latLong.lat,latLong.long), map.getZoom());
	//zoomTo();
}


function getCoOrds(theName){
	var o=new Object();
	// These 4 co-ordinates are done for you...
	o.Nordineslodge={lat:-23.851910,long:35.543577};
	o.Tomstofohouse={lat:-23.865039,long:35.550642};
	o.Inhambane={lat:-23.867933,long:35.385579};
	o.Albatrozroadhouse={lat:-23.856375,long:35.548099};
	o.Woodenescapes={lat:-23.862743,long:35.548781};
	o.Aidassemidetached={lat:-23.859571,long:35.548477};
	o.Complexotofino={lat:-23.862517,long:35.547756};
	o.All={lat:-18.646245,long:33.222656};


/*
	copy 1 line like this for example 	o.Tofo={lat:-18.646245,long:33.222656};
	but change the Tofo part after the . (dot) without a space, to the proper name of the place.
	and put the propert co-ordinates in the lat, and long parts.
	DO NOT change anything else.!!!

*/


	for (var locName in o){
		if (locName==theName){
			return o[locName];
		}
    }
	// if theName doesnt exists, return this...
	return {lat:-18.646245,long:33.222656};
}


