﻿/// <reference path="jquery-1.3.2.min-vsdoc.js"/>

var map;
var markers = [];
var requestqs ="-1";



$(document).ready(function() {


        
  requestqs= $.jqURL.get("business") ? $.jqURL.get("business"): "-1";
     
     
     if (GBrowserIsCompatible()) {
        // get the marker management javascript
        $.getScript("/Media/js/GmapsMarkerManager.js",
        function(){
        
        // Initialize the map.
        map = new GMap2(document.getElementById("gmaps"));
        map.setCenter(new GLatLng(54.224701,-4.577179), 10);
        map.setMapType(G_NORMAL_MAP);

        /*-----
            Adding a large number of markers to a Google map may both slow down rendering
            of the map and introduce too much visual clutter,
            especially at certain zoom levels. 
            The marker manager utility provides a solution to both of these issues, 
            allowing efficient display of hundreds of markers on the same map and the ability
            to specify at which zoom levels markers should appear.
        ----*/
        var mgr = new MarkerManager(map);
        var mgrOptions = { borderPadding: 25, maxZoom: 15, trackMarkers: true };
       
        //default UI for Google maps 
        map.setUIToDefault();
       
        //base configuration for marker pins
        var baseIcon = new GIcon(G_DEFAULT_ICON);
        baseIcon.image ="/media/images/marker.png";
        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(18, 27);
        baseIcon.shadowSize = new GSize(33, 30);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
        
            //ajax call to get xml data for placing marker pins
        $.ajax({ type: "GET", url: "/content/controls/maps/markers.aspx?" + createTimestamp() + "&bid=" + requestqs, dataType: "xml",
			    success:function(data,textStatus) {
				    $("marker",data).each(function() {
					    // Attributes for each marker.
           			    var lat = parseFloat($(this).attr("lat"));
           			    var lng = parseFloat($(this).attr("lng"));
           			    var point = new GLatLng(lat,lng);
           			    var html = $("html",this).text();
               			
           			    var marker = createMarker(point,baseIcon,html)
                            mgr.addMarker(marker); 
                           map.addOverlay(marker);
                            
                        if(requestqs!="-1"){
                             map.setCenter(new GLatLng(lat,lng), 13);
                        }
				    });
			    },
			    error:function(XMLHTTPRequest,textStatus,errorThrow){
				    alert("There was an error retrieving the location information.");
			    }});
                
                
                mgr.refresh();
         }
        
                
        );
        
    }
        
 });
    


//
function createMarker(point,baseIcon,html){
  var MarkerIcon = new GIcon(baseIcon);
      markerOptions = { icon:MarkerIcon };
  var marker = new GMarker(point,markerOptions)
  
  GEvent.addListener(marker, "click", function() {
						marker.openInfoWindowHtml(html);
			        });
  return marker;
}

function createTimestamp() {
    return "timestamp=" + new Date().getTime().toString();
};


$(document.body).unload(function() {
    if (GBrowserIsCompatible()) {
        GUnload();
    }
});






