function GMap_computeAngle(endLatLng, startLatLng) {
	var DEGREE_PER_RADIAN = 57.2957795;
	var RADIAN_PER_DEGREE = 0.017453;
	
	var dlat = endLatLng.lat() - startLatLng.lat();
	var dlng = endLatLng.lng() - startLatLng.lng();
	// We multiply dlng with cos(endLat), since the two points are very closeby,
	// so we assume their cos values are approximately equal.
	var yaw = Math.atan2(dlng * Math.cos(endLatLng.lat() * RADIAN_PER_DEGREE), dlat)
	     * DEGREE_PER_RADIAN;
	return GMap_wrapAngle(yaw);
}

function GMap_wrapAngle(angle) {
	if (angle >= 360) {
	  angle -= 360;
	} else if (angle < 0) {
	 angle += 360;
	}
	return angle;
};
function createStreetViewControl2() {
	var container = document.createElement("div");
	var streetViewBtn= document.createElement("div");
	streetViewBtn.title= "Open Street View";
	streetViewBtn.className= "GoogleMapButton";
	container.appendChild(streetViewBtn);
	var streetViewBtnText=document.createElement("div");
	streetViewBtnText.className="GoogleMapButton_text";
	streetViewBtn.appendChild(streetViewBtnText);
	streetViewBtnText.appendChild(document.createTextNode("Street View"));
    google.maps.event.addDomListener(streetViewBtn, 'click', function() {
    	openGoogleStreetView2();
	});
	return container;
}
function removeStreetView() {
	$('#gStreetView').remove();
}
function createGoogleMapMakerIcon(iconFiles, iconSize, shadowSize) {
	var iconWidth=iconSize?iconSize[0]:32;
	var iconHeight=iconSize?iconSize[0]:37;
	var shadowWidth=iconSize?iconSize[0]:51;
	var shadowHeight=iconSize?iconSize[0]:37;
	var image = new google.maps.MarkerImage(iconFiles.image,
			new google.maps.Size(iconWidth, iconHeight),
			new google.maps.Point(0, 0),
			new google.maps.Point(parseInt(iconWidth/2), iconHeight-2));
	var shadow = new google.maps.MarkerImage(iconFiles.shadow,
		new google.maps.Size(shadowWidth, shadowHeight),
		new google.maps.Point(0, 0),
		new google.maps.Point(parseInt(iconWidth/2), shadowHeight-2));
	return {image:image,shadow:shadow};	
}
function createGoogleMapManMakerIcon(iconFiles) {
	var image = new google.maps.MarkerImage(iconFiles.image,
			new google.maps.Size(32, 32),
			new google.maps.Point(0, 0),
			new google.maps.Point(16, 32));
	var shadow = new google.maps.MarkerImage(iconFiles.shadow,
		new google.maps.Size(49, 32),
		new google.maps.Point(0, 0),
		new google.maps.Point(16, 32));
	return {image:image,shadow:shadow};	
}
function createGoogleMapMarker(map, myLatlng, title, popupId, markerIcons) {
	var marker;
	if (markerIcons) {
		marker=new google.maps.Marker({
	        position: myLatlng, 
	        map: map,
	        icon: markerIcons.image,
	        shadow: markerIcons.shadow,
	        title: title
	    }); 
	}  else {
		marker=new google.maps.Marker({
	        position: myLatlng, 
	        map: map,
	        title: title
	    }); 
	}
	if (popupId) {
		if (typeof popupId=="function") {
		    google.maps.event.addListener(marker, 'click', function() {
		        popupId();
		    });			
		} else {
			var infowindow = new google.maps.InfoWindow({
			    content: document.getElementById(popupId).innerHTML
			});
	    	if (!map.infowindowList) {
	    		map.infowindowList = [];
	    	}
	        map.infowindowList.push(infowindow);
			
		    google.maps.event.addListener(marker, 'click', function() {
		    	for (var no in map.infowindowList) {
		    		map.infowindowList[no].close();
		    	}
		        infowindow.open(map,marker);
		    });
		}
	}
}
function centerAndZoomOnPoints(map, points) {
	var bounds = new google.maps.LatLngBounds();
	for (var no in points) {
		bounds.extend(points[no]);
	}
	map.fitBounds(bounds);
}
//IGA
function createIGAGoogleMapMarkerIcon(iconFiles) {
	var image = new google.maps.MarkerImage(iconFiles.image,
			new google.maps.Size(64, 74),
			new google.maps.Point(0, 0),
			new google.maps.Point(32, 73));
	var shadow = new google.maps.MarkerImage(iconFiles.shadow,
		new google.maps.Size(60, 44),
		new google.maps.Point(0, 0),
		new google.maps.Point(5, 42));
	return {image:image,shadow:shadow};	
}
function getIGAMarkerIcons(storeType) {
	return createIGAGoogleMapMarkerIcon(getIGAGoogleMapMakerIconFile(storeType));
}
// end of IGA
