// JavaScript Document

function gmapLoad() {
  if (GBrowserIsCompatible()) {
		
		map = new GMap2(document.getElementById("map"));
		pano = new GStreetviewPanorama(document.getElementById("street"), { latlng:point });
		
		var icon = new GIcon(); 
		icon.image = url+"img/gmarker.png"; 
		icon.shadow = url+"img/gshadow.png"; 
		icon.shadowSize = new GSize(80,56); 
		icon.iconSize = new GSize(80,55); 
		icon.iconAnchor = new GPoint(24,55); 
		icon.infoWindowAnchor = new GPoint(40,27); 
		
		map.addControl(new GMapTypeControl());
    map.addControl(new GOverviewMapControl());
		map.addControl(new GSmallMapControl());
		//map.addControl(new GLargeMapControl());
		map.setCenter(mapCenter, 16);
		
		shop = new GMarker(point, {'icon':icon, title:msgbody});
    map.addOverlay(shop);
		//shop.openInfoWindowHtml(msgbody);
		GEvent.addListener(shop, "click", function() {
			shop.openInfoWindowHtml(msgbody);
		});
		
		var markerIcon = new GIcon();
		markerIcon.image = url+"img/man_arrow.png";
		markerIcon.iconSize = new GSize(49, 52);
		markerIcon.iconAnchor = new GPoint(25, 35);  // near base of guy's feet
		markerIcon.infoWindowAnchor = new GPoint(25, 5);  // top of guy's head
		
		marker = new GMarker(point2, {icon:markerIcon, draggable:true, bouncy:false});
		GEvent.addListener(marker,"dragend", moveMarker);
    map.addOverlay(marker);
		
		var street = new GStreetviewOverlay();
    map.addOverlay(street);
		
		pano.setLocationAndPOV(point);
		
		
		client = new GStreetviewClient();
		client.getNearestPanorama(point, getPoint);
		
		//GEvent.addListener(map, "click", moveCenter);
		GEvent.addListener(pano, "initialized", moveMap);
  }
}

function moveCenter(overlay, point){
  map.panTo(point);
  pano.setLocationAndPOV(point);
  pano.show();
  marker.setLatLng(point);
}

function moveMap(loc){
  map.panTo(loc.latlng);
  marker.setLatLng(loc.latlng);
}

function moveMarker(){
  var movepoint = marker.getLatLng();
	
	client.getNearestPanorama(movepoint, getPoint);
	
	//map.panTo(p);
  //pano.setLocationAndPOV(p);
  //pano.show();
}

function getPoint(data){
  if (data.code != 200) {
		pano.hide();
	
	} else {
		var newpoint = data.location.latlng;
		pano.setLocationAndPOV(newpoint);
		marker.setLatLng(newpoint);
		map.panTo(newpoint);
	}
	//pano.show();
}


