
//<![CDATA[	
 
 
 if (GBrowserIsCompatible()) {
      var gmarkers = [];
      var gicons = [];
 
    var icon = new GIcon(); 
    icon.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    icon.iconSize = new GSize(12, 20);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);

    var icon2 =new GIcon();
    icon2.iconSize = new GSize(25,23);
    icon2.iconAnchor = new GPoint(6, 20);
    icon2.infoWindowAnchor = new GPoint(5, 1);

     gicons["Institucione Shteterore"] = new GIcon(icon,"http://labs.google.com/ridefinder/images/mm_20_blue.png");
     gicons["Institucione Kulturore,Fetare dhe Sportive"] = new GIcon(icon,"http://labs.google.com/ridefinder/images/mm_20_green.png");
     gicons["Hoteleri-Turizem"] = new GIcon(icon,"http://labs.google.com/ridefinder/images/mm_20_red.png");
     gicons["Institucione Shendetsore"] = new GIcon(icon,"http://labs.google.com/ridefinder/images/mm_20_white.png");
     gicons["Institucione Arsimore"] = new GIcon(icon,"http://labs.google.com/ridefinder/images/mm_20_yellow.png");
     gicons["Institucione Financiare"] = new GIcon(icon,"http://labs.google.com/ridefinder/images/mm_20_brown.png");
     gicons["Unaza"] = new GIcon(icon2,"bus1.png");
     gicons["Kinostudio-Kombinat"] = new GIcon(icon2,"bus2.png");
     gicons["Tufine"] = new GIcon(icon2,"bus3.jpg");
     gicons["Porcelani"] = new GIcon(icon2,"bus4.png");
     gicons["Ish-Uzina e Autotraktoreve"] = new GIcon(icon2,"bus5.png");
     gicons["Sauk-Sanatorium"] = new GIcon(icon2,"bus6.png");
     gicons["Tirana e Re"] = new GIcon(icon2,"bus7.png");
     gicons["Laprake"] = new GIcon(icon2,"bus8.png");
     gicons["Kamez"] = new GIcon(icon2,"bus9.png");

function createMarker(point, name, foto, category, detaje, adress) {
      
    var marker = new GMarker(point, gicons[category]);
        marker.mycategory = category;                                 
        marker.myname = name;
        marker.details = detaje;
        var html = "<b>" + name + "</b> <br/><a href='"+ foto +"' rel='lightbox'><img src='"+ foto +"' width='220' height='180'></a><br/><b>Adress: </b>"+ adress +"<br/>For more information go to <a href='http://clicktirana.com/galery/Gallery.html'>Gallery</a>";
        marker.html = html;
      GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        gmarkers.push(marker);
        return marker;
      }


function createStation(point, name, start, stop, wait) {
      
      var station = new GMarker(point, gicons[name]);
        station.mycategory = name;                        
        station.myname = name;
      var html = "<b>" + name + "<br/>Starts at :</b><i>"+ start +"</i><br/><b>Ends at: </b><i>"+ stop +"</i><br/><b>Wait for:  </b><i>"+ wait +"</i>";
        station.html = html;
      GEvent.addListener(station, "click", function() {
          station.openInfoWindowHtml(html);
        });
        gmarkers.push(station);
        return station;
      }

      
      function show(category) {
       if(category=="Streets"){
           map.addOverlay(rruge);
         }
       else{       
        for (var i=0; i<gmarkers.length; i++) {
          if (gmarkers[i].mycategory == category) {
            gmarkers[i].show();
          }
         }
        }
       document.getElementById(category).checked = true;
      }


      function hide(category) {
        if(category=="Streets"){
           map.removeOverlay(rruge);
         }
        else{
         for (var i=0; i<gmarkers.length; i++) {
          if (gmarkers[i].mycategory == category) {
            gmarkers[i].hide();
          }
         }
        }
        document.getElementById(category).checked = false;
        map.closeInfoWindow();
      }
      
        
      function boxclick(box,category) {
        if (box.checked) {
          show(category);
        } else {
          hide(category);
        }
        
        makeSidebar();
      }

   
    function myclick(i) {
        GEvent.trigger(gmarkers[i],"click");
      }


    function makeSidebar() {
        var html = "";
        for (var i=0; i<gmarkers.length; i++) {
          if (!gmarkers[i].isHidden()) {
            html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + '</a><br>';
          }
        }
        document.getElementById("side_bar").innerHTML = html;
      }

 
 function find_input(){
   var name=document.input_form.input_name.value.toLowerCase();
   var ugjet=false; var i=0;
  while(i<gmarkers.length && !ugjet){
      if(gmarkers[i].myname.toLowerCase()==name || gmarkers[i].myname.toLowerCase()+" "+gmarkers[i].details.toLowerCase()==name || gmarkers[i].details.toLowerCase()+" "+gmarkers[i].myname.toLowerCase()==name){
         gmarkers[i].show();
         gmarkers[i].openInfoWindowHtml(gmarkers[i].html);
         ugjet=true;
       }
       else{ 
        ugjet=false; 
        i++;
       } 
     }
    if(!ugjet){
     alert("This place is not in the map! Check your spelling!");
    }
    document.input_form.input_name.value="";  
  }


 function  find_distance(){
   
   var name1=document.distance_form.input1.value.toLowerCase();
   var name2=document.distance_form.input2.value.toLowerCase();
   var i=0; ugjet=false; distance=0;
    while(i<gmarkers.length && !ugjet){
      if(gmarkers[i].myname.toLowerCase()==name1){
         marker1=gmarkers[i];
         marker1.show();
         ugjet=true;
        }
       else{ 
        ugjet=false; 
        i++;
       } 
     }
    if(!ugjet){
     alert("This place is not in the map! Check your spelling!");
    }
    else{
      ugjet=false; i=0;
      while(i<gmarkers.length && !ugjet){
        if(gmarkers[i].myname.toLowerCase()==name2){
         marker2=gmarkers[i];
         marker2.show();
         ugjet=true;
         distance = marker1.getPoint().distanceFrom(marker2.getPoint())/1000; 
         }
        else{ 
          ugjet=false; 
          i++;
         } 
        }
        if(distance!=0){
          var polyline = new GPolyline([marker1.getPoint(),marker2.getPoint()], "#ff0000", 3);
          map.addOverlay(polyline);
          document.distance_form.input1.value="";
          document.distance_form.input2.value="";
          document.getElementById("result").innerHTML ='The distance between <b>'+ name1.toUpperCase()+ '</b> and <b>'+name2.toUpperCase()+ '</b> is <b> : ' + distance.toFixed(3)+ ' km.</b>';
         }
       else{
           alert("This place is not in the map! Check your spelling");
          }
      }
  }
    


//the creation of the map
     
    var rruge = new GGeoXml("http://clicktirana.com/Faqja2/rruget.kmz");
    var map = new GMap2(document.getElementById("map_Tirana"));
	map.setCenter(new GLatLng(41.3275, 19.8188889), 13); 
	map.enableScrollWheelZoom();
	map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.addOverlay(rruge);
        map.addControl(new GOverviewMapControl(new GSize(150,150)));

     
        GDownloadUrl("data.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 foto = markers[i].getAttribute("foto");
            var type = markers[i].getAttribute("type");
            var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                    parseFloat(markers[i].getAttribute("lng")));
            var detaje = markers[i].getAttribute("detaje");
            var adress = markers[i].getAttribute("adresa");
            var marker = createMarker(point, name, foto, type, detaje, adress);
            map.addOverlay(marker);
           
           }
           var stations = xml.documentElement.getElementsByTagName("station");
           for (var i = 0; i < stations.length; i++) {
            var name = stations[i].getAttribute("names");
            var start = stations[i].getAttribute("start");
            var stop = stations[i].getAttribute("stop");
            var wait = stations[i].getAttribute("wait");
            var point = new GLatLng(parseFloat(stations[i].getAttribute("lats")),
                                    parseFloat(stations[i].getAttribute("lngs")));
            var station = createStation(point, name, start, stop, wait);
            map.addOverlay(station);
           
           }  
        hide("Institucione Shteterore");
        hide("Institucione Kulturore,Fetare dhe Sportive");
        hide("Hoteleri-Turizem");
        hide("Institucione Shendetsore");
        hide("Institucione Arsimore");
        hide("Institucione Financiare");
        hide("Streets");
        hide("Unaza");
        hide("Kinostudio-Kombinat");
        hide("Tufine");
        hide("Porcelani");
        hide("Ish-Uzina e Autotraktoreve");
        hide("Sauk-Sanatorium");
        hide("Tirana e Re");
        hide("Laprake");
        hide("Kamez");
        makeSidebar();
       });
      
               
    }

    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }

    //]]>

