var centerLatitude = 19.166249;
var centerLongitude =73.072472;
var description = '';
var startZoom = 12;
var map;
var RonJonLogo = new GIcon();
RonJonLogo.image = 'wp-content/themes/casabylodha_v2/gmaps/bella_logo.jpg';
RonJonLogo.iconSize = new GSize(100, 14);
RonJonLogo.iconAnchor = new GPoint(12, 5);
RonJonLogo.infoWindowAnchor = new GPoint(12, 10);
var markers = [
{
'latitude': 19.166249,
'longitude':73.072472,
'name': '<table border=0 cellspacing=2 cellpadding=2 height=150 width=350><tr><td><img src=http://www.casabylodha.com/images/thumbs/logo_bella.jpg border=0 /></td><td>Casa Bella,<br/>Near Khidkaleshwar Temple,<br/>Kalyan Shil Road,<br/> Dombivalli(E) ,<br/> Mumbai,<br/> India</td></tr></table>'

}
	];

function addMarker(latitude, longitude, description) {
var marker = new GMarker(new GLatLng(latitude, longitude), RonJonLogo);
GEvent.addListener(marker, 'mouseover',function() {
marker.openInfoWindowHtml(description); } );
map.addOverlay(marker);

}
//start storeMarker
function storeMarker(){
var lng = document.getElementById("longitude").value;
var lat = document.getElementById("latitude").value;



var getVars = "?names=" + document.getElementById("names").value
+ "&location=" + document.getElementById("location").value
+ "&icon=" + document.getElementById("icon").value
+ "&lng=" + lng
+ "&lat=" + lat ;
var request = GXmlHttp.create();

//open the request to storeMarker.php on your server
request.open('GET', 'storeMarker.php' + getVars, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
//the request is complete
var xmlDoc = request.responseXML;
//retrieve the root document element (response)
var responseNode = xmlDoc.documentElement;
//retrieve the type attribute of the node
var type = responseNode.getAttribute("type");
//retrieve the content of the responseNode
var content = responseNode.firstChild.nodeValue;
//check to see if it was an error or success
if(type!='success') {
alert(content);
} else {
//create a new marker and add its info window
var latlng = new GLatLng(parseFloat(lat),parseFloat(lng));
var iconImage = responseNode.getAttribute("icon");
var marker = createMarker(latlng, content, iconImage);
map.addOverlay(marker);
map.closeInfoWindow();
}
}
}
request.send(null);
return false;
}
function createMarker(latlng, html,iconImage) {
	if(iconImage!='') {
var icon = new GIcon();
icon.image = iconImage;
icon.iconSize = new GSize(25, 25);
icon.iconAnchor = new GPoint(14, 25);
icon.infoWindowAnchor = new GPoint(14, 14);

var marker = new GMarker(latlng,icon);
} else {
var marker = new GMarker(latlng);
}
var marker = new GMarker(latlng);
GEvent.addListener(marker, 'mouseover', function() {
var markerHTML = html;

marker.openInfoWindowHtml(markerHTML);
});
return marker;
}

//end storeMarker
//start retrieveMarkers
function retrieveMarkers() {
var request = GXmlHttp.create();
//tell the request where to retrieve data from.
request.open('GET', 'retrieveMarkers.php', true);
//tell the request what to do when the state changes.
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = request.responseXML;
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var lng = markers[i].getAttribute("lng");
var lat = markers[i].getAttribute("lat");
//check for lng and lat so MSIE does not error
//on parseFloat of a null value
if(lng && lat) {
var latlng = new GLatLng(parseFloat(lat),parseFloat(lng));
var html = '<div><b>Name</b> '
+ markers[i].getAttribute("names")
+ '</div><div><b>Location</b> '
+ markers[i].getAttribute("location")
+ '</div>';

var iconImage = markers[i].getAttribute("icon");
var marker = createMarker(latlng, html,iconImage);
map.addOverlay(marker);
}
} //for
} //if
} //function
request.send(null);
}

// end retrieveMarkers

function init()
{
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
retrieveMarkers();

map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
var location = new GLatLng(centerLatitude, centerLongitude);

map.setCenter(location, startZoom);
//to retrivrive data


//close
//addMarker(centerLatitude, centerLongitude, description);
//for(id in markers) {
addMarker(markers[0].latitude, markers[0].longitude, markers[0].name);
//}

}

}
window.onload = init;
window.onunload = GUnload;

