﻿


$(function(){

    if ($("div.office-map").length > 0)
    {
        $("div.office-map").each(function(){
            
            var officeId = $(this).attr("id").replace("id_","");
            var map = null;
            $.ajax({
                type: "GET",
                url: "/xml/mapOfficeXML.aspx?officeid=" + officeId,
                dataType: "xml",
                success: function(xml){
                    $(xml).find('office').each(function(){
                        var name = $(this).find("name").text();
                        var address = $(this).find("address").text();
                        var latitude = $(this).find("latitude").text();
                        var longitude = $(this).find("longitude").text();
                        
                        if (latitude != "" && longitude != "")
                        {
                        
                            var latlng = new google.maps.LatLng(latitude, longitude);
                            var myOptions = {
                                zoom: 16,
                                center: latlng,
                                mapTypeId: google.maps.MapTypeId.ROADMAP
                            };
                            map = new google.maps.Map(document.getElementById("id_" + officeId),
                                myOptions);
//                            initializeMap(map,officeId,latitude,longitude);
                        
                            var marker = new google.maps.Marker({
                                position: new google.maps.LatLng(latitude, longitude),
                                map: map,
                                title: name                                
                                
                            });
                            
                            var contentString = "<div class=\"gmapsOfficeAddress\">" + name + "<br /><strong>"+address+"</strong></div>";
                            //initialise a new popup with the inner text
                            var infowindow = new google.maps.InfoWindow({
                                content: contentString
                            });
                         
                            

                            //attach the popup to the marker and set to appear on click of marker
                            google.maps.event.addListener(marker, 'click', function() {
                                //deleteWindows();
                                //if (marker.position)
                                infowindow.open(map, marker);
                                map.setCenter(marker.position);
                            });
                            
                        }
                    
                    });
                }            
            
            
            
            });
        
        });
    }
    
    $(".gmapsOfficeAddress").parent().parent().css("overflow","visible");


});





function initializeMap(officeMap, officeId, latitude, longitude) {

        
        
      

    //clusterer = new clusterer(map);
        
//    google.maps.event.addListener(map, 'click', function(event) 
//        {             placeMarker(event.latLng);         });          
//        
}
