// JavaScript Document
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];      
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}   
	}
	return (arrReturnElements)
}

function ChangePhotoTab(p) {
	
	var CurrentOn;
	//Set Link
	CurrentOn = getElementsByClassName(document.getElementById('photo'), 'span', 'photo-link on');
	for (i in CurrentOn) {
		CurrentOn[i].className = 'photo-link';
	}
	document.getElementById('photo-link-' + p).className = 'photo-link on';
	// Set Photo
	CurrentOn = getElementsByClassName(document.getElementById('photo'), 'a', 'property-photo active');
	for (i in CurrentOn) {
		CurrentOn[i].className = 'property-photo not-active';
	}
	document.getElementById('photo-' + p).className = 'property-photo active';
}

function showMap(GeoLat, GeoLong, PageTitle){
	document.getElementById('map-outer').style.display = 'block';
	document.getElementById('photo').style.display = 'none';
	document.getElementById('photos-tab').className = '';
	document.getElementById('map-tab').className = 'on';
	load(GeoLat, GeoLong, PageTitle);
}

function showPhoto(){
	document.getElementById('map-outer').style.display = 'none';
	document.getElementById('photo').style.display = 'block';
	document.getElementById('photos-tab').className = 'on';
	document.getElementById('map-tab').className = '';
	onunload="GUnload()"
}

function load(GeoLat, GeoLong, Title) {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		var bounds = new GLatLngBounds();
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(GeoLat, GeoLong), 13);
					
		// Create a base icon for all of our markers that specifies the shadow, icon dimensions, etc.
		var baseIcon = new GIcon();
		baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		baseIcon.iconSize = new GSize(20, 34);
		baseIcon.shadowSize = new GSize(37, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		baseIcon.infoShadowAnchor = new GPoint(18, 25);
		
		// Creates a marker whose info window displays the letter corresponding to the given index.
		function createMarker(point, message) {
		var icon = new GIcon(baseIcon);
		icon.image = "http://www.google.com/mapfiles/marker.png";
		var marker = new GMarker(point, icon);
		
		GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(message);
		});
		return marker;
		}
		
		var point;
		var msg;		
		point = new GLatLng(GeoLat, GeoLong);
		map.addOverlay(createMarker(point, Title));
		map.setCenter(new GLatLng(GeoLat, GeoLong), 13);
		
	}	
}