// JavaScript Document
// Author Virtualtour Ltd.
// Coded by K.Mekvabishvili

var iconBlue = new GIcon(); 
    iconBlue.image = 'http://virtualtour.ge/map/images/marker_outdoor.png';
    iconBlue.shadow = 'http://virtualtour.ge/map/images/marker_shadow.png';
    iconBlue.iconSize = new GSize(20, 34);
    iconBlue.shadowSize = new GSize(22, 20);
    iconBlue.iconAnchor = new GPoint(6, 20);
    iconBlue.infoWindowAnchor = new GPoint(5, 1);

    var iconRed = new GIcon(); 
    iconRed.image = 'http://virtualtour.ge/map/images/marker_indoor.png';
    iconRed.shadow = 'http://virtualtour.ge/map/images/marker_shadow.png';
    iconRed.iconSize = new GSize(20, 34);
    iconRed.shadowSize = new GSize(22, 20);
    iconRed.iconAnchor = new GPoint(6, 20);
    iconRed.infoWindowAnchor = new GPoint(5, 1);

    var customIcons = [];
    customIcons["outside"] = iconBlue;
    customIcons["inside"] = iconRed;

    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setUIToDefault();
		map.removeMapType(G_NORMAL_MAP); 
		map.removeMapType(G_SATELLITE_MAP); 
		map.removeMapType(G_HYBRID_MAP);
		map.setCenter(new GLatLng(42.10392840256859,43.3355712890625), 7);
		map.setMapType(G_HYBRID_MAP);
        map.enableDoubleClickZoom();

       GDownloadUrl("/map/markers_en.php", function(data) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
            var name = markers[i].getAttribute("name");
            var cat = markers[i].getAttribute("cat");			
            var type = markers[i].getAttribute("type");
            var views = markers[i].getAttribute("views");
            var panoDate = markers[i].getAttribute("panoDate");
            var panoID = markers[i].getAttribute("panoID");            
            var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")));
            var marker = createMarker(point, name, cat, type, views, panoDate, panoID);
            map.addOverlay(marker);
          }
        });
      }
    }

    //function createMarker(point, name, address, type, subheading, panoDate, panoID){

    function createMarker(point, name, cat, type, views, panoDate, panoID){
      var marker = new GMarker(point, customIcons[type]);      
      
      GEvent.addListener(marker, 'click', function() {
      		// panoID, panoTitle, panoViews, PanoPublish
			//showPano(panoID);
			window.location = 'view.php?pano=' + panoID + '&lang=en';
		    
	  });
	  
      GEvent.addListener(marker, 'mouseover', function() {
      		// panoID, panoTitle
			tooltip.show('<div style="width: 120px;"><img src="http://virtualtour.ge/thrumbs/120x80/c'+cat+'/'+panoID+'.jpg" height="80"><br/><strong>'+name+'</strong></div>');
	  });

      GEvent.addListener(marker, 'mouseout', function() {
      		// panoID, panoTitle
			tooltip.hide();
	  });

	  
      return marker;
    }

