﻿
function iMap(map, table, wColumn, wValue, stages, hlpn){
  var http_request = false;
  var id = 'iMap';
  if (window.XMLHttpRequest) { 
	http_request = new XMLHttpRequest();
	if (http_request.overrideMimeType) {
	  http_request.overrideMimeType('text/xml');
	}
  } 
  else if (window.ActiveXObject) {
	try {
	  http_request = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) {
	  try {
	    http_request = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  catch (e) {}
	}
  }
  if (!http_request) {
	return false;
  }
 http_request.onreadystatechange = function() { setSelect(map, http_request, table, wColumn, wValue, stages, hlpn); };
 http_request.open('GET', 'mapData.php?target=index&table=' + table + '&wColumn=' + wColumn + '&wValue=' + wValue + '&stages=' + stages, true);
 http_request.send(null);
}
          
function setSelect(map, http_request, table, wColumn, wValue, stages, hlpn) {
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
      xmldoc = http_request.responseXML;
      load(map, table, xmldoc, hlpn);
	}
    else {
      alert('There was a problem with the request.');
    }
  }
}

//*****************************************************************************************************************8
function load(map, table, xmldoc, hlpn) {

  domain = 'baltimore-maryland.org';
  cname = 'hotels';
  cd = document.getElementById("mapFACont");
  md = document.getElementById("iMap");
  im = document.getElementById("mapFAI");
  smc = new GSmallMapControl();
  lmc = new GLargeMapControl();
  mtc = new GMapTypeControl();
  msc = new GScaleControl();
  map.addControl(smc);
  map.addControl(mtc);
  map.enableContinuousZoom();
  map.enableDoubleClickZoom();
  map.setCenter(new GLatLng(39.287412, -76.612815), 9);
  getData(map, xmldoc);
   GEvent.addListener(map, "click", function(overlay, point) {
      if (overlay){	// marker clicked
       window.location = 'http://www.' + domain + '/' + hlpn + '?name=' + overlay.name;
       //window.location = 'http://www.' + domain + '/' + hlpn + '?table=' + table + '&landmark=' + overlay.name; 
	  }
	  else if (point) {	// background clicked
	    /*if(md.style.width == '288px'|| md.style.width == ''){
	      changeSize();
	    } */
      }
   });
 
}

function getData(map, xmldoc){
   map.clearOverlays();
   var baseIcon = new GIcon();

  baseIcon.shadow = "/images/shadowB.png";
  baseIcon.iconSize = new GSize(21, 31);
  baseIcon.shadowSize = new GSize(52, 29);
  baseIcon.iconAnchor = new GPoint(7, 31);
  baseIcon.infoWindowAnchor = new GPoint(9, 2);
  baseIcon.infoShadowAnchor = new GPoint(18, 25);
  baseIcon.image = "/images/star.png";
// baseIcon.iconSize = new GSize(20, 34);
/*   baseIcon.shadowSize = new GSize(37, 34);
   baseIcon.iconAnchor = new GPoint(9, 34);
   baseIcon.infoWindowAnchor = new GPoint(9, 2);
   baseIcon.infoShadowAnchor = new GPoint(18, 25); */
   var icon = new GIcon(baseIcon);
   var bicon = new GIcon(baseIcon);
   icon.image = "http://www.google.com/mapfiles/marker.png";
   bicon.image = baseIcon.image;
   markers = new Array();
   locations = xmldoc.documentElement.getElementsByTagName("poi");
     for (var i = 0; i < locations.length; i++) { // cycle thru locations
	     markers[i] = new GMarker(new GLatLng(locations[i].getAttribute("la"),locations[i].getAttribute("lo")), {icon:bicon, title:locations[i].getAttribute("na")});
		 markers[i].name = locations[i].getAttribute("na");
		 map.addOverlay(markers[i]);
	 }
 }

