var map;
var centerLatitude = 26.379185;
var centerLongitude = -80.088959;
var startZoom = 12;


/* [listing 6-15] */
var deselectCurrent = function() {};

function initializePoint(pointData) {
	var point = new GLatLng(pointData.latitude, pointData.longitude);
	var icon = new GIcon();
	if (pointData.iconcounter == '0')
		{
				icon.image = "http://interactive.sun-sentinel.com/crime_news/red-dot1.png";
		}
	if (pointData.iconcounter == '1')
		{
				icon.image = "http://interactive.sun-sentinel.com/crime_news/red-dot2.png";
		}
	if (pointData.iconcounter == '2')
		{
				icon.image = "http://interactive.sun-sentinel.com/crime_news/red-dot3.png";
		}
	if (pointData.iconcounter == '3')
		{
				icon.image = "http://interactive.sun-sentinel.com/crime_news/red-dot4.png";
		}
	if (pointData.iconcounter == '4')
		{
				icon.image = "http://interactive.sun-sentinel.com/crime_news/red-dot5.png";
		}
	if (pointData.iconcounter == '5')
		{
				icon.image = "http://interactive.sun-sentinel.com/crime_news/red-dot6.png";
		}
		//icon.image = "http://interactive.sun-sentinel.com/crime_news/blue-dot.png";
		//icon.iconSize = new GSize(13, 30);
		
		
		//icon.shadowSize = new GSize(22, 20);
		//icon.iconAnchor = new GPoint(6, 20);
	
        icon.iconAnchor = new GPoint(5, 5);
        icon.infoWindowAnchor = new GPoint(25, 7);

		
		
		
		//icon.infoWindowAnchor = new GPoint(5, 1);
	var marker = new GMarker(point,{icon:icon});
	var listItem = document.createElement('li');
	var listItemLink = listItem.appendChild(document.createElement('a'));
	listItemLink.href = "#";
	listItemLink.innerHTML = '<table><tr><td><img src="' + icon.image + ' "border="0" width="25px"/></td>' +
	'<td><strong>' + pointData.crime_type + '</div></strong><span>' + pointData.address + '<br/></td></tr></table>';
	
	var focusPoint = function() {
		deselectCurrent();
		listItem.className = 'current';
		deselectCurrent = function() { listItem.className = ''; }
		if (pointData.city == '') {
	marker.openInfoWindowHtml('<table width="190"><tr><td><small style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; line-height: 10px;">' + '<b>' + pointData.crime_type.toUpperCase() + '</b>' + '<br/>' + pointData.address + '<br/>' + pointData.height + ', ' + pointData.elevation + '<br/>' + pointData.description + '</small></td></tr></table>');
	
}
else {
marker.openInfoWindowHtml('<table width="190"><tr><td><small style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; line-height: 10px;">' + '<b>' + pointData.crime_type.toUpperCase() + '</b>' + '<br/>' + pointData.address + '<br/>' + pointData.height + ', ' + pointData.elevation + '<br/>' + pointData.description + '</small></td></tr></table>');
}
		map.panTo(point);
		return false;
	}

	GEvent.addListener(marker, 'click', focusPoint);	
	listItemLink.onclick = focusPoint;

	document.getElementById('sidebar-list').appendChild(listItem);

	map.addOverlay(marker);
}
/* [listing 6-15 end] */

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 handleResize() {
	var height = windowHeight() -0;
	document.getElementById('map').style.height = height + 'px';
	document.getElementById('sidebar').style.height = height + 'px';
}

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

function init() {
	//document.getElementById('button-sidebar-hide').onclick = function() { return changeBodyClass('sidebar-right', 'nosidebar'); };
	//document.getElementById('button-sidebar-show').onclick = function() { return changeBodyClass('nosidebar', 'sidebar-right'); };
	handleResize();
	
	map = new GMap(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
	
	for(id in markers) {
		initializePoint(markers[id]);
	}
}

window.onresize = handleResize;
window.onload = init;





