var centerLatitude = 33.9382000;
var centerLongitude = -83.3851000; 
var startZoom = 11;
var map;

//var iconx = '../images/parker-mapicon.png';
var deselectCurrent = function() {};


function initializePoint(pointData, iconImage) {
	var point = new GLatLng(pointData.latitude, pointData.longitude);
	var marker = new GMarker(point);

	if(iconImage != '')
	{
		var icon = new GIcon();
		icon.image = iconImage;
		icon.iconSize = new GSize(25, 25);
		icon.iconAnchor = new GPoint(14, 25);
		icon.infoWindowAnchor = new GPoint(14,14);
		var marker = new GMarker(point, icon);
	}
	else
	{
		var marker = new GMarker(point);
	}
	var listItem = document.createElement('li');
	var visible = false;

	/// listItem.innerHTML = '<table width="650" cellpadding="10" cellspacing="0" border="0" style="padding: 15px;"><tr><td width="250" valign="top" style="border-bottom: 0px solid black"><h2 style="margin-top:5px;"><a href="#" class="mapx" style="text-decoration:none; color: #660000;">' + pointData.name + '</a></h2><p style="margin-top:0px;">' + pointData.address + '<br />' + pointData.city + ', ' + pointData.state + ' '</td></tr></table>';
	
	var focusPoint = function() {
		deselectCurrent();
		listItem.className = 'current';
		deselectCurrent = function() { listItem.className = ''; }

		var desc = '';


			//desc = desc + '<div style="width: 310px; height: 100%; padding-top: 5px;"><strong>' + pointData.name + '</strong>';
			//desc = desc + '<br />' + pointData.address;
			//desc = desc + '<br />' + pointData.city + ', ' + pointData.state;
			//desc = desc + '<br /><a href="../portfolio/' + pointData.shortcode + '">View Project</a></div>';
			//desc = desc + '<div align="center" style="width: 400px; height: 100%; padding-top: 5px; padding-right: 10px; padding-left: 10px; padding-bottom: 5px;"><img src="/beta/portfolio3/photos/' + pointData.image + '" border="0" width="' + pointData.width + '" align="left" /></div>';

			//desc = desc + '<img src="/beta/portfolio/photos/' + pointData.image + '" border="0" width="' + pointData.width + '" align="left" style="padding-right: 10px; padding-bottom: 20px;" />';
			//desc = desc + '<strong>' + pointData.name + '</strong>';
			//desc = desc + '<br />' + pointData.address;
			//desc = desc + '<br />' + pointData.city + ', ' + pointData.state;
			//desc = desc + '<br /><a href="detail.php">View Property</a></div>';


			//desc = desc + '<div style="background-color: #FFFFFF;"><img src="/beta/portfolio3/photos/' + pointData.image + '" border="0" height="' + pointData.width + '" align="left" /><span class="title"><br />' + pointData.name + '</span>';
			//desc = desc + '<br />' + pointData.address;
			//desc = desc + '<br />' + pointData.city + ', ' + pointData.state;
			//desc = desc + '<a href="../portfolio/' + pointData.shortcode + '">View Project</a></div>';
	
			desc = desc + '<table border="0" cellpadding="3" cellspacing="0" width="400">';
			desc = desc + '<tr valign="top"><td align="left" width="150">';
			desc = desc + '<a href="details.php?id=' + pointData.identifier2 + '"><img src="/images/properties/' + pointData.directory + '/' + pointData.image + '" border="0" width="' + pointData.width + '" height="' + pointData.height + '" /></a>';
			desc = desc + '</td>';
			desc = desc + '<td width="250" align="left">';
			desc = desc + '<strong>' + pointData.name + '</strong>';
			desc = desc + '<br />' + pointData.address;
			
			if(pointData.city != "")
			{
				desc = desc + '<br />' + pointData.city + ', ' + pointData.state;
			}

			desc = desc + '<br />';
			desc = desc + '<br /><a href="details.php?id=' + pointData.identifier2 + '">View Property</a>';
			desc = desc + '</td></tr>';
			desc = desc + '</table>';


		marker.openInfoWindowHtml(desc, {maxWidth: '400'});
		map.panTo(point);
		return false;
	}

	GEvent.addListener(marker, 'click', focusPoint);

	listItem.onclick = focusPoint;

	if(pointData.showv == "show") {
		var	desc2 = '';
			//desc2 = '<span class="title" style="padding:10px"><br />' + pointData.name + '</span>';
			//desc2 = desc2 + '<br />' + pointData.address;
			//desc2 = desc2 + '<br />' + pointData.city + ', ' + pointData.state;
			//desc2 = desc2 + '<a href="#' + pointData.idv + '"></a>';
			desc2 = desc2 + '<table border="0" cellpadding="3" cellspacing="0" width="400">';
			desc2 = desc2 + '<tr valign="top"><td align="left" width="150">';
			desc2 = desc2 + '<a href="../portfolio/' + pointData.shortcode + '"><img src="/beta/portfolio/photos/' + pointData.image + '" border="0" width="' + pointData.width + '" height="' + pointData.height + '" /></a>';
			desc2 = desc2 + '</td>';
			desc2 = desc2 + '<td width="250" align="left">';
			desc2 = desc2 + '<strong>' + pointData.name + '</strong>';
			desc2 = desc2 + '<br />' + pointData.address;
		
			if(pointData.city != "")
			{
				desc2 = desc2 + '<br />' + pointData.city + ', ' + pointData.state;
			}

			desc2 = desc2 + '<br />';
			desc2 = desc2 + '<br /><a href="../portfolio/' + pointData.shortcode + '">View Project</a>';
			desc2 = desc2 + '</td></tr>';
			desc2 = desc2 + '</table>';

		marker.openInfoWindowHtml(desc2);
		map.panTo(point);
	}

	pointData.show = function() {
		if (!visible) {
			//document.getElementById('sidebar-list').appendChild(listItem);
			map.addOverlay(marker);
			visible = true;
		}
	}
	pointData.hide = function() {
		if (visible) {
		///	document.getElementById('sidebar-list').removeChild(listItem);
			map.removeOverlay(marker);
			visible = false;
		}
	}

	pointData.show();
}

function initializeSortTab(type) {
	var listItem = document.createElement('li');
	var listItemLink = listItem.appendChild(document.createElement('a'));

	listItemLink.href = "#";
	listItemLink.innerHTML = type;
	listItemLink.onclick = function() {
		changeBodyClass('standby', 'loading');

		for(id in markers) {
			//if (markers[id].type == type || 'All' == type)
				markers[id].show();
			//else
			//	markers[id].hide();	
		}

		changeBodyClass('loading', 'standby');

		return false;
	}

	//document.getElementById('filters').appendChild(listItem);
}

function windowHeight() {
	// Standard browsers (Mozilla, Safari, etc.)
	if (self.innerHeight)
		return self.innerHeight;
	// IE 6
	if (document.documentElement && document.documentElement.clientHeight)
		return document.documentElement.clientHeight;
	// IE 5
	if (document.body)
		return document.body.clientHeight;
	// Just in case.
	return 0;
}


function changeBodyClass(from, to) {
	document.body.className = document.body.className.replace(from, to);
	return false;
}

function init() {
	var type;
	var allTypes = { 'All':[] };
	
	
	map = new GMap(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GScaleControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
	
	for(id in markers) {
		initializePoint(markers[id], '');
		allTypes[markers[id].type] = true;
	}

	for(type in allTypes) {
		initializeSortTab(type);
	}

	changeBodyClass('loading', 'standby');
}


function regionalview() {
	var regionLat = 33.198247;
	var regionLon = -85.411377;
	var regionZoom = 6;
	map.setCenter(new GLatLng(regionLat, regionLon), regionZoom);

}

function stateview() {
	var stateLat = 33.065305;
	var stateLon = -83.491516; 
	var stateZoom = 7;
	map.setCenter(new GLatLng(stateLat, stateLon), stateZoom);

}

function localview() {
	var localLat = 33.95278;
	var localLon = -83.395772;
	var localZoom = 11;
	map.setCenter(new GLatLng(localLat, localLon), localZoom);

}

window.onload = init;
window.onunload = GUnload;