var googleMap = {
	bounds: null,
	map: null
}

googleMap.init = function(selector, latLng, zoom) {
  	var myOptions = {
		zoom:zoom,
		center: latLng,
		mapTypeId: google.maps.MapTypeId.HYBRID
  	}
  	this.map = new google.maps.Map($(selector)[0], myOptions);
  	this.bounds = new google.maps.LatLngBounds();
}

googleMap.placeMarkers = function(filename) {
	$.get(filename, function(xml){
		$(xml).find("marker").each(function(){
			var name = $(this).find('name').text();
			// create a new LatLng point for the marker
			var lat = $(this).find('lat').text();
			var lng = $(this).find('lng').text();
			var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
			// extend the bounds to include the new point
			googleMap.bounds.extend(point);
			// add the marker itself
			var marker = new google.maps.Marker({
				position: point,
				map: googleMap.map
			});
			// create the tooltip and its text
			var infoWindow = new google.maps.InfoWindow();

			var html = "<b>" + name + "</b>";
			if ($(this).find('info')) {
				//test = $(this).find('info').first().children().first();
				html += $(this).find('info').text();
			}
			// add a listener to open the tooltip when a user clicks on one of the markers
			google.maps.event.addListener(marker, 'click', function() {
				infoWindow.setContent(html);
				infoWindow.open(googleMap.map, marker);
			});
		});
		// Fit the map around the markers we added:
		googleMap.map.fitBounds(googleMap.bounds);
	});
}

function gmap_initialize(divid) {
	var myLatLng = new google.maps.LatLng(17.74033553, 83.25067267);
  	googleMap.init('#' + divid, myLatLng, 11);
    googleMap.placeMarkers('/scripts/location.xml');
}

