// JavaScript Document

    //<![CDATA[ 

var marker;    

    var iconTrain = new GIcon(); 
    iconTrain.image = 'images/icons/train.png';
    iconTrain.iconSize = new GSize(30, 34);
    iconTrain.iconAnchor = new GPoint(16, 34);
    iconTrain.infoWindowAnchor = new GPoint(5, 1);

    var iconHome = new GIcon(); 
    iconHome.image = 'images/icons/home.png';
    iconHome.iconSize = new GSize(30, 34);
    iconHome.iconAnchor = new GPoint(16, 34);
    iconHome.infoWindowAnchor = new GPoint(5, 1);
	
    var iconHotel3stele = new GIcon(); 
    iconHotel3stele.image = 'images/icons/hotel3stele.png';
    iconHotel3stele.iconSize = new GSize(30, 34);
    iconHotel3stele.iconAnchor = new GPoint(16, 34);
    iconHotel3stele.infoWindowAnchor = new GPoint(5, 1);

    var iconIzvor = new GIcon(); 
    iconIzvor.image = 'images/icons/izvor.png';
    iconIzvor.iconSize = new GSize(30, 34);
    iconIzvor.iconAnchor = new GPoint(16, 34);
    iconIzvor.infoWindowAnchor = new GPoint(5, 1);

    var iconPrimaria = new GIcon(); 
    iconPrimaria.image = 'images/icons/primaria.png';
    iconPrimaria.iconSize = new GSize(30, 34);
    iconPrimaria.iconAnchor = new GPoint(16, 34);
    iconPrimaria.infoWindowAnchor = new GPoint(5, 1);

    var iconBiserica = new GIcon(); 
    iconBiserica.image = 'images/icons/biserica.png';
    iconBiserica.iconSize = new GSize(30, 34);
    iconBiserica.iconAnchor = new GPoint(16, 34);
    iconBiserica.infoWindowAnchor = new GPoint(5, 1);

    var customIcons = [];
    customIcons["home"] = iconHome;
    customIcons["train"] = iconTrain;
    customIcons["hotel3stele"] = iconHotel3stele;
    customIcons["izvor"] = iconIzvor;
    customIcons["primaria"] = iconPrimaria;
    customIcons["biserica"] = iconBiserica;
	
	
	
    
      if (GBrowserIsCompatible()) {

function load() {
	
	
      // == Display the map, with some controls and set the initial location 
	  var map ;
 map = new GMap2(document.getElementById("map"));
	map.addControl(new GLargeMapControl());
	map.enableScrollWheelZoom();

    	
	var copyright = new GCopyright(1,
	new GLatLngBounds(new GLatLng(0,0),new GLatLng(0,0) ),0, "Baile Herculane");   	
    	var copyrightCollection = new GCopyrightCollection('');
		copyrightCollection.addCopyright(copyright);
		
		var tilelayers = [new GTileLayer(copyrightCollection , 13, 17)];
		tilelayers[0].getTileUrl = CustomGetTileUrl;
		
		var custommap = new GMapType(tilelayers, G_SATELLITE_MAP.getProjection(), "Custom Layer", {errorMessage:"No chart data available"});
		map.addMapType(custommap);
		
	  // Set Center of the map
	  map.setCenter(new GLatLng(33.215005, -87.492540),13, custommap);


        GDownloadUrl("database.php", function(data) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
            var nume = markers[i].getAttribute("nume");
            var poza = markers[i].getAttribute("poza");
            var type = markers[i].getAttribute("type");
            var links = markers[i].getAttribute("links");
            var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                    parseFloat(markers[i].getAttribute("lng")));
            var marker = createMarker(point, nume, poza, links, type);
            map.addOverlay(marker);
          }
        });
		
		
      }
    }
    function CustomGetTileUrl(a,b) {
		 if (b==13 && a.x>=2104 && a.x<=2106 && a.y>=3293 && a.y<= 3294){
		return "http://cazarelaherculane.ro/harta/images/tiles/13_"+a.x+"_"+a.y+".jpg";
		}
		else if (b==14 && a.x>=4208 && a.x<=4212 && a.y>=6587 && a.y<= 6588){
		return "http://cazarelaherculane.ro/harta/images/tiles/14_"+a.x+"_"+a.y+".jpg";
		}
		else if (b==15 && a.x>=8416 && a.x<=8424 && a.y>=13174 && a.y<= 13177){
		return "http://cazarelaherculane.ro/harta/images/tiles/15_"+a.x+"_"+a.y+".jpg";
		}
		else if (b==16 && a.x>=16832 && a.x<=16848 && a.y>=26349 && a.y<= 26354){
		return "http://cazarelaherculane.ro/harta/images/tiles/16_"+a.x+"_"+a.y+".jpg";
		}
		else if (b==17 && a.x>=33665 && a.x<=33696 && a.y>=52699 && a.y<= 52708){
		return "http://cazarelaherculane.ro/harta/images/tiles/17_"+a.x+"_"+a.y+".jpg";
        } else {
          return "http://cazarelaherculane.ro/harta/images/tiles/blank.jpg";
        }
	}

    function createMarker(point, nume, poza, links, type) {
      var marker = new GMarker(point, customIcons[type]);
      var html = '<b>' + nume + '</b><br/><img src="/harta/images/info/' + poza + '.jpg" width=100 height=100><br/><a href="http://cazarelaherculane.ro/' + links + '">Afla mai multe -></a>';
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }
    //]]>
