//<![CDATA[
	
    if (GBrowserIsCompatible()) {
      var side_bar_html = "";
      var gmarkers = [];
      var htmls = [];
	  var html2s = [];
	  var html3s = [];
      var i = 0;
	  
	  
		 var medium = new GIcon();
		 medium.iconSize=new GSize(32,32);
		 medium.shadowSize=new GSize(56,32);
		 medium.iconAnchor=new GPoint(16,32);
		 medium.infoWindowAnchor=new GPoint(16,0);
	  
	  var gicons = [];
	  var other = new GIcon(medium, "map_icon/Icon_MyPhuketMap.png", null, null);
	  // ==================================================
      

      // A function to create the marker and set up the event window
      function createMarker(point,i,name,html,icontype,logo) {
        var marker = new GMarker(point, {icon:icontype});
		
		gmarkers[i] = marker;
        htmls[i] = html;
		logo[i] = logo;
		
		marker.tooltip = '<div class="tooltip">'+name+'<\/div>';		
		if(logo){
				
			side_logo_html += '<p><a href="javascript:myclick(' + i + ')"  onmouseout="mymouseout()" ><img src="'+logo+'" border="0" /></a></p>';
			
		}
		
		side_bar_html += '<li><a href="javascript:myclick(' + i + ')"  onmouseout="mymouseout()">'+name+'<\/a></li>';	
	
		
		
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });  
		
		GEvent.addListener(marker,"mouseover", function() {
          showTooltip(marker);
        });
		
        GEvent.addListener(marker,"mouseout", function() {
		tooltip.style.visibility="hidden"
        });
		
        return marker;
      }
	  // A function to create a tabbed marker and set up the event window
	  
      function createTabbedMarker(point,i,name,html1,html2,html3,label1,label2,label3,icontype,logo) {
		
        var marker = new GMarker(point, {icon:icontype});
		marker.tooltip = '<div class="tooltip">'+name+'<\/div>';
	
        GEvent.addListener(marker, "click", function() {
		  if(html3){
          marker.openInfoWindowTabsHtml([new GInfoWindowTab(label1,html1), new GInfoWindowTab(label2,html2), new GInfoWindowTab(label3,html3)]);
		  }else{
			  marker.openInfoWindowTabsHtml([new GInfoWindowTab(label1,html1), new GInfoWindowTab(label2,html2)]);
			  }
        });
		
		
		gmarkers[i] = marker;
        htmls[i] = html1;
		html2s[i] = html2;
		html3s[i] = html3;
		if(logo){
				
			side_logo_html += '<p><a href="javascript:myTabs(' + i + ')"  onmouseout="mymouseout()" ><img src="'+logo+'" border="0" /></a></p>';
			
		}
		
		side_bar_html += '<li><a href="javascript:myTabs(' + i + ')"  onmouseout="mymouseout()">' + name + '<\/a></li>';
		
		GEvent.addListener(marker,"mouseover", function() {
          showTooltip(marker);
        });
		
        GEvent.addListener(marker,"mouseout", function() {
		tooltip.style.visibility="hidden"
        });
		
        return marker;
      }
      // ==================================================
	  function showTooltip(marker) {
      	tooltip.innerHTML = marker.tooltip;
		var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
		var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
		var anchor=marker.getIcon().iconAnchor;
		var width=marker.getIcon().iconSize.width;
		var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
		pos.apply(tooltip);
		tooltip.style.visibility="visible";
      }
	function mymouseover(i) {	
		showTooltip(gmarkers[i]);
		
	}
	function mymouseout() {
		tooltip.style.visibility="hidden";
    }


      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
      }
	  
	  
	  function myTabs(i) {
		 if(html3s[i]){
        gmarkers[i].openInfoWindowTabsHtml([new GInfoWindowTab("Contact",htmls[i]), new GInfoWindowTab("Overview",html2s[i]), new GInfoWindowTab("Webcam",html3s[i])]);
		 }else{
		gmarkers[i].openInfoWindowTabsHtml([new GInfoWindowTab("Contact",htmls[i]), new GInfoWindowTab("Overview",html2s[i])]);
		 }
      }

      // create the map
      var map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(7.895855,98.370186), 12);

	  var tooltip = document.createElement("div");
      document.getElementById("map").appendChild(tooltip);
      tooltip.style.visibility="hidden";

      // A function to read the data
      function readMap(url,area) {
		var end = new Date();
	  	var url="_kml_cctv.php"+url+"&ts="+end.getTime();
        var request = GXmlHttp.create();
        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = request.responseXML;
            // obtain the array of markers and loop through it
            var markers = xmlDoc.documentElement.getElementsByTagName("marker");
            
            // hide the info window, otherwise it still stays open where the removed marker used to be
            map.getInfoWindow().hide();
            
            map.clearOverlays();
            
            // empty the array
            gmarkers = [];

            // reset the side_bar
             side_bar_html="";
          	 side_logo_html="";
            for (var i = 0; i < markers.length; i++) {
              // obtain the attribues of each marker
              var lat = parseFloat(markers[i].getAttribute("lat"));
              var lng = parseFloat(markers[i].getAttribute("lng"));
              var point = new GLatLng(lat,lng);
              var html = markers[i].getAttribute("html");
              var label = markers[i].getAttribute("label");
			  var label2 = markers[i].getAttribute("label2");
			  var icontype = markers[i].getAttribute("icontype");
			  var cat = markers[i].getAttribute("cat");
			  var logo = markers[i].getAttribute("logo");
			  var cctv = markers[i].getAttribute("cctv");
			  var marker = createTabbedMarker(point,i,label, html,label2,cctv, "Contact", "Overview", "Webcam",other,logo);
			  
              map.addOverlay(marker);
			  
            }
			
            // put the assembled side_bar_html contents into the side_bar div
			document.getElementById("logo_side").innerHTML = side_logo_html;
			
            document.getElementById("cctv").innerHTML = side_bar_html;
			
			//document.getElementById("logo_side").innerHTML = side_logo_html;
          }else{
		  document.getElementById(area).innerHTML = "<div class='loading'><img src='images/loading-stream2.gif' /></div>";
		  }
        }
        request.send(null);
      }
      
      // When initially loaded, use the data from "map11.php?q=a"
      readMap(url,null);
      
    }

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

    //]]>
