var map;

var centerLatitude = 43.6939;

var centerLongitude = -116.3569; 

var startZoom = 12;

var streetviewClient;
var panorama;




var deselectCurrent = function() {};


var iconGreen=new GIcon();iconGreen.image="Icons/Remax.png";iconGreen.iconSize=new GSize(15,20);iconGreen.iconAnchor=new GPoint(6,20);iconGreen.infoWindowAnchor=new GPoint(5,1);

var customIcons=[];customIcons["Eagle"]=iconGreen;
	

function initializePoint(pointData) {

	var point = new GLatLng(pointData.latitude, pointData.longitude);

	var marker = new GMarker(point, customIcons["Eagle"]);
        
        

	var listItem = document.getElementById('list');

	var listItemLink = document.getElementById('link');

	var visible = false;

	

	// ====== set up marker mouseover tooltip div ======

      var tooltip = document.createElement("div");

      map.getPane(G_MAP_FLOAT_PANE).appendChild(tooltip);

      tooltip.style.visibility="hidden";

	

	 // === store the name so that the tooltip function can use it ===

        marker.tooltip = '<div class="tooltip"><nobr>'+pointData.neighborhood+'</nobr></div>';



	      // ===== This function is invoked when the mouse goes over an entry in the side_bar =====

      // It launches the tooltip on the icon 

	listItemLink.onmouseover = function() { 

	                  showTooltip(marker);

        }; 

		

	   // ===== This function is invoked when the mouse leaves an entry in the side_bar =====

      // It hides the tooltip 

		listItemLink.onmouseout = function() { 

	                  tooltip.style.visibility="hidden";

        }; 

		


	

	var focusPoint = function() {

		deselectCurrent();

		listItem.className = 'current';

		deselectCurrent = function() { listItem.className = ''; }

		marker.openInfoWindowHtml(pointData.html);
		var myPano = new GStreetviewPanorama(document.getElementById("pano"));
                fenwayPark = new GLatLng(pointData.lat,pointData.lng);
                myPOV = {yaw:(pointData.streetpov),pitch:(pointData.streetpitch)};
                myPano.setLocationAndPOV(fenwayPark, myPOV);
		var nbinfo = (document.getElementById("message"));
		nbinfo.innerHTML = '<strong>' + pointData.neighborhood + '&nbsp;Neighborhood</strong><span>&nbsp;&nbsp;-&nbsp;&nbsp;' + pointData.city + ',&nbsp;Idaho';
	        tooltip.style.visibility="hidden";
                return false;

	}

 
			


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

	listItemLink.onclick = focusPoint;

	

	 //  ======  The new marker "mouseover" and "mouseout" listeners  ======

        GEvent.addListener(marker,"mouseover", function() {

          showTooltip(marker);

        });        

        GEvent.addListener(marker,"mouseout", function() {

		tooltip.style.visibility="hidden"

        });        

		

	 // ====== This function displays the tooltip ======

      // it can be called from an icon mousover or a side_bar mouseover

      function showTooltip(marker) {

      	tooltip.innerHTML = marker.tooltip;

	var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0,0),true),map.getZoom());

	var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());

	var anchor=marker.getIcon().iconAnchor;

	var width=marker.getIcon().iconSize.width;

	var height=tooltip.clientHeight;

	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 

	pos.apply(tooltip);

	tooltip.style.visibility="visible";

      }

	pointData.show = function() {

		if (!visible) {

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

			map.addOverlay(marker);

			visible = true;

		}

	}

		pointData.show();

}



function changeBodyClass(from, to) {

	document.body.className = document.body.className.replace(from, to);

	return false;

}



function init() {

	var options = { searchFormHint : "Search for hospitals, schools.." }; 

	

	map = new GMap(document.getElementById("map")); 

      map.addControl(new GSmallMapControl());

      map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);

	for(id in markers) {

		initializePoint(markers[id]);

	}



	changeBodyClass('loading', 'standby');

}





window.onload = init;

window.onunload = GUnload;







   