//
var gmarkers = [];
var clinicResults = [];

var useGeocoder = false;
var searchLat;
var searchLon;
var map;
var clusterer;

// initLocator called on page load, check for passed url params to load map or disp blank
function initLocator() {
	// GERMANY & UK ONLY set the active country
	Locator.setActiveCountry();

    var urlDataExists = Locator.checkInitData();

    // Init search form
    Locator.initFormValues();
    Locator.checkInitData();
	
	
    /* Display treatment type input if enabled
    if (!Locator.Config.hideTreatmentTypes){
        document.getElementById("selectTreatment").style.visibility = "visible";
    }*/
    // check for data in url passed from callout and validate
    Locator.showLoader(true);
    Locator.showMap(false);
    if (urlDataExists) {
    	var valid2 = Locator.validateSearch();
		if (valid2){
			Locator.refineSearch();
		}
		else{
			createEmptyMap(false);
		}
        
    } else {
        // either no data passed or data didn't check out.. =(
		// set the active country index:
		
        createEmptyMap(false);
	}
}

function createEmptyMap(errorMsg, i) {
	// if not passed, default countryIndex is the activeIndex
	if(!i){ i = Locator.Config.activeIndex; }
    // Creates an empty map obj and centers on uk
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(Locator.Config.defaultCoords[i][0], Locator.Config.defaultCoords[i][1]), Locator.Config.defaultZoom[i]);
        map.addControl(new GLargeMapControl());
        map.addControl(new GScaleControl());
        map.addControl(new rosettaMapTypeControl());
    }
    // If init page blank [no init data to display] then:
    // Change footer image so results reflection does not display
    document.getElementById('reflection').style.backgroundImage = "url(/Style%20Library/images/half_reflection.jpg)";
    
    document.getElementById('btnGo').disabled = false;
    if (errorMsg) {
        Locator.showErrorMsg(errorMsg);
    } 
    Locator.showLoader(false);
    Locator.showMap(true);
}

// gload called when all data validated and checked out
function gload(xmlPath, getTiers) {
	 document.getElementById('reflection').style.backgroundImage = "url(/Style%20Library/images/full_reflection.jpg)";
	 // Check compatibility
	 if (GBrowserIsCompatible()) {
	 
	    map = new GMap2(document.getElementById("map"));
	    var x, y, aXy, zoom;
	    aXy = Locator.Config.defaultCoords[Locator.Config.activeIndex];
	    x = aXy[0];
	    y = aXy[1];
	    zoom = Locator.Config.defaultZoom[Locator.Config.activeIndex];
        map.setCenter(new GLatLng(x,y), zoom);
        map.addControl(new GLargeMapControl());
        map.addControl(new GScaleControl());
        map.addControl(new rosettaMapTypeControl());
	    var bounds = new GLatLngBounds();
		
		// Set Clustering Defaults
		clusterer = new Clusterer(map);
		clusterer.SetMaxVisibleMarkers(1); // Marker count where clustering kicks in, default is 150
		clusterer.SetMinMarkersPerCluster(2); // Minimum number of markers for a cluster, default is 5
		
		// Create a base icon for all of our markers that specifies the
		// shadow, icon dimensions, etc.
		
		var baseIcon = new GIcon();
		baseIcon.iconSize = new GSize(41, 43);
		baseIcon.shadowSize = new GSize(41, 43);
		baseIcon.iconAnchor = new GPoint(16, 40);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		baseIcon.infoShadowAnchor = new GPoint(18, 25);
		
		var tierIcon = new GIcon();
		tierIcon.iconSize = new GSize(42, 46);
		tierIcon.shadowSize = new GSize(40, 46);
		tierIcon.iconAnchor = new GPoint(18, 43);
		tierIcon.infoWindowAnchor = new GPoint(9, 2);
		tierIcon.infoShadowAnchor = new GPoint(18, 25);
		
		// Creates a marker whose info window displays the letter corresponding
		// to the given index.
		
		function createMarker(point, officeObj) {
		
			// Create a lettered icon for this point using our icon class
		  	var letter = String.fromCharCode("a".charCodeAt(0) + officeObj.returnId());
	  	    
		  	
		  	var letter = String.fromCharCode("a".charCodeAt(0) + officeObj.returnId());
		  	if(officeObj.officeTier == "true"){
		  	    var icon = new GIcon(tierIcon);
		  	    icon.image = Locator.Config.pathToTierMarkers + letter + Locator.Config.markerExtension;
		  	    var marker = new GMarker(point, icon);
		  	} else {
		  	    var icon = new GIcon(baseIcon);
	  	        icon.image = Locator.Config.pathToMarkers + letter + Locator.Config.markerExtension;
	  	        var marker = new GMarker(point, icon);
		  	}
		  
			// Create the listener object for map clicks
		 
			GEvent.addListener(marker, "click", function() {
			    Locator.stopTimer()//clear any running intervals
				Locator.deactivate_markers();
			    selectedResult = "listresult" + officeObj.returnId();
			    pagenum = Math.floor(officeObj.returnId()/Locator.Config.resultLimit);
			    //Locator.buildResultSet(Locator.resultPages[pagenum]);
				//infoTabs = Locator.buildInfoTabs(clinicResults[officeObj.returnId()], officeObj.officeTitle);
				if(clinicResults[officeObj.returnId()].officeTierType == "a" || clinicResults[officeObj.returnId()].officeTierType == "b"){
			        infoTabs = Locator.buildInfoTabs(clinicResults[officeObj.returnId()], officeObj.officeTitle);
			    } else {
			        infoTabs = Locator.buildNTInfoTabs(clinicResults[officeObj.returnId()], officeObj.officeTitle);
			    }
				marker.openInfoWindowTabsHtml(infoTabs);
				Locator.trackClinic(officeObj.returnId(), "view");
				Locator.openWinId = officeObj.returnId();
				map.setCenter(point);
				var tmpToken = GEvent.addListener(map, "moveend", function() {
                  Locator.moveMap(0, 50);
                  GEvent.removeListener(tmpToken);
                });
				Element.addClassName("listresult" + officeObj.returnId(), 'selected');
				if (officeObj.officeHasPhoto == "True") {
			        Locator.showPanelPhoto();
			    }
	  		});
			
			gmarkers[officeObj.returnId()] = marker;
          	return marker;
		}
		
		function showAddress(officeObj) {
			var lat = parseFloat(officeObj.officeLat);
            var lng = parseFloat(officeObj.officeLong);
            var point = new GLatLng(lat,lng);
			map.setCenter(point, 8);
			var tmpMarker = createMarker(point, officeObj);
			//map.addOverlay(tmpMarker);
			clusterer.AddMarker(tmpMarker, officeObj.showDisplayName(), officeObj.returnId(), officeObj.officeTitle, officeObj);
			bounds.extend(tmpMarker.getPoint());
		}		 
		
		// This listener event redefines the default Google Overlay
		GEvent.addListener(map, "infowindowopen", function() {
		    Locator.firstTabSet = false;
			var divs = map.getContainer().getElementsByTagName("div");
			var imgs = map.getContainer().getElementsByTagName("img");
				
				// Replace the google images with our custom ones
				/*for(var x = 0; x<imgs.length; x++) {
				    var tmpSrcString = imgs[x].src;
				    if (tmpSrcString.indexOf("iw2.png") >= 0 ) {
				        imgs[x].src = "/Style%20Library/images/tabs/bg_overlay.png";
				    } else if (tmpSrcString.indexOf("iw_tabstub.png") >= 0 ) {
				        imgs[x].src = "/Style%20Library/images/tabs/iw_tabstub.png";
				    } else if (tmpSrcString.indexOf("iw_close.gif") >= 0 ) {
				        imgs[x].src = "/Style%20Library/images/tabs/close_overlay.gif";
				    }
				}*/
				
				// Add a class on our tabs for styling, and move them
				// If SC code is needed, add to Locator.tabClick() function in base_functions.js
				var tmpStartId = 0;
				for(var i = 0; i<divs.length; i++) {
				var height = divs[i].style.height;
				var width = divs[i].style.width;
				var border = divs[i].style.borderBottom;
					
					if(width=="103px" && height=="24px") {
					var tmpLeftPos = (parseInt(divs[i].parentNode.style.left) - 19) + "px";
					var tmpTopPos = (parseInt(divs[i].parentNode.style.top) + 1) + "px";
					//divs[i].parentNode.style.left = tmpLeftPos;
					//divs[i].parentNode.style.top = tmpTopPos;
					//divs[i].parentNode.style.textDecoration = "none";
					
					var newLabel = divs[i].innerHTML;
						if (Locator.firstTabSet != true) {
						var tabClass = "tab";
						Locator.firstTabSet = true;
						} else {
						var tabClass = "inactive";
						}
					var tmpTabId = "tab" + tmpStartId;
					var newText = '<a href="javascript:" id="' + tmpTabId + '" class="' + tabClass + '" onclick="Locator.tabClick(this.id,Locator.openWinId);">' + newLabel + '</a>';
					divs[i].innerHTML = newText;
					tmpStartId += 1;
					}
					/* Top and Bottom border Updates
					if(height=="24px") {
						if (divs[i].style.borderTop.indexOf("1px") != -1) {	
							divs[i].style.border = "solid " + Locator.Config.borderColor;
							divs[i].style.borderWidth = "2px 0px 0px";
						}
						if(divs[i].style.borderBottom.indexOf("1px") != -1) {
							divs[i].style.height = (parseInt(divs[i].style.height) - 1) + "px";
							divs[i].style.border = "solid " + Locator.Config.borderColor;
							divs[i].style.borderWidth = "0px 0px 2px 0px";
						}
					}*/
					/* Left and Right border updates
					if(divs[i].style.borderLeft.indexOf("1px") != -1 && divs[i].style.borderTop.indexOf("1px") == -1) {
					
						divs[i].style.borderLeft = "2px solid " + Locator.Config.borderColor;
						divs[i].style.overflow = "hidden";
					}
					if(divs[i].style.borderRight.indexOf("1px") != -1 && divs[i].style.borderTop.indexOf("1px") == -1) {
						divs[i].style.borderRight = "2px solid " + Locator.Config.borderColor;
						divs[i].style.overflow = "hidden";
					}
					if(divs[i].style.borderRight.indexOf("2px") != -1 && divs[i].style.borderTop.indexOf("1px") == -1) {
						var tmpWidth = parseInt(divs[i].style.width);
						divs[i].style.width = (tmpWidth - 2) + "px";
						divs[i].style.overflow = "hidden";
					}*/
				}
		});
		
		//GET XML
			
		GDownloadUrl(xmlPath, function(data, responseCode) {
		 	
		  	// To ensure against HTTP errors that result in null or bad data,
		  	// always check status code is equal to 200 before processing the data
		  	if (responseCode == 200) {
		  	    var xml = GXml.parse(data);
		  	    var offices = xml.documentElement.getElementsByTagName("office");
		  	    var servervars = xml.documentElement.getElementsByTagName("servervars");
    		    var tmpTotalResults = servervars[0].getAttribute("totalresults");
			    for (var i=0, o_len = offices.length; i < o_len; i++) {
    			
			        var officeObj = new Clinic();
			        officeObj.setId(i);
        			
			        // Set Return Vars 
			        officeObj.totalResults = servervars[0].getAttribute("totalresults");
        			
			        // Office Info
			        officeObj.officeMarker = offices[i].getAttribute("label");
			        officeObj.officePhoto = offices[i].getAttribute("logoUrl");
			        //officeObj.officeDescription = offices[i].getElementsByTagName("clinic_bio")[0].firstChild.nodeValue;
			        officeObj.officeInstitutionId = offices[i].getAttribute("institutionId");
			        officeObj.officeInstitutionName = offices[i].getAttribute("institutionName");
			        officeObj.officeDeptId = offices[i].getAttribute("physicianLocationId");
			        officeObj.officeDeptName = offices[i].getAttribute("departmentName");
			        officeObj.officeAddress  = offices[i].getAttribute("address");
			        officeObj.officeCity  = offices[i].getAttribute("city");
			        officeObj.officeCounty  = offices[i].getAttribute("county");
			        officeObj.officePostal = offices[i].getAttribute("postal");
			        officeObj.officeDistance = offices[i].getAttribute("distance");
			        officeObj.officeLat = offices[i].getAttribute("lat");
			        officeObj.officeLong = offices[i].getAttribute("long");
			        officeObj.officeContact = offices[i].getAttribute("contact");
			        officeObj.officePhone = offices[i].getAttribute("phone");
			        officeObj.officeFax = offices[i].getAttribute("fax");
			        officeObj.officeEmail = offices[i].getAttribute("email");
			        officeObj.officeWeb = offices[i].getAttribute("website");
			        officeObj.officeStartYear = offices[i].getAttribute("yearStarted");
			        officeObj.officeCTBC = offices[i].getAttribute("ctbc");
			        officeObj.officeCTBCemail = offices[i].getAttribute("ctbcEmail");
			        officeObj.offerAvailable = offices[i].getAttribute("freeOffer");
			        officeObj.officeBio = offices[i].getAttribute("bio");
			        //mike
				    //officeObj.officeSmile = offices[i].getAttribute("smile"); //???
			        officeObj.officeRecordId = offices[i].getAttribute("id");
			        //officeObj.officeTier = offices[i].getAttribute("tier");
			        officeObj.officeTier = offices[i].getAttribute("topTier");
			        officeObj.officeTierType = offices[i].getAttribute("tierValue");
			        officeObj.officeHasPhoto = offices[i].getAttribute("image");
        			
			        // Physician Info
			        officeObj.physicianId = offices[i].getAttribute("physicianId");
			        officeObj.physicianName = offices[i].getAttribute("physicianName");
			        officeObj.physicianUniversity = offices[i].getAttribute("university");
			        officeObj.physicianDegree = offices[i].getAttribute("degree");
        			
			        //Set Arrays
			        officeObj.services = [];
			        officeObj.specialties = [];
			        officeObj.languages = [];
			        officeObj.treatments = [];
			        officeObj.products = [];
			        officeObj.locations = [];
			        officeObj.hours = [];
        			
			        // Services
			        var tmpServices = offices[i].getElementsByTagName("service");
        				
			        for (var y = 0; y<tmpServices.length; y++) {
				        var servObj = {};
				        servObj.name = tmpServices[y].getAttribute("name");
				        officeObj.services.push(servObj);
			        }
        			
			        // Specialties
			        var tmpSpecialties = offices[i].getElementsByTagName("specialty");
        				
			        for (var e = 0; e<tmpSpecialties.length; e++) {
				        var specialObj = {};
				        specialObj.name = tmpSpecialties[e].getAttribute("name");
				        officeObj.specialties.push(specialObj);
			        }
        			
			        // Languages
			        var tmpLanguages = offices[i].getElementsByTagName("language");
        				
				        for (var f = 0; f<tmpLanguages.length; f++) {
				        var languageObj = new Object();
				        languageObj.name = tmpLanguages[f].getAttribute("name");
				        officeObj.languages.push(languageObj);
			        }
        			
			        // Treatments
			        var tmpTreatments = offices[i].getElementsByTagName("treatment");
        				
				        for (var g = 0; g<tmpTreatments.length; g++) {
				        var treatmentObj = new Object();
				        treatmentObj.name = tmpTreatments[g].getAttribute("name");
				        treatmentObj.id = tmpTreatments[g].getAttribute("id");
				        treatmentObj.category = tmpTreatments[g].getAttribute("category");
				        officeObj.treatments.push(treatmentObj);
			        }
        			
			        // Products
			        var tmpProducts = offices[i].getElementsByTagName("product");
        				
				        for (var h = 0; h<tmpProducts.length; h++) {
				        var productObj = new Object();
				        productObj.id = tmpProducts[h].getAttribute("id");
				        productObj.name = tmpProducts[h].getAttribute("name");
				        officeObj.products.push(productObj);
			        }
        			
			        // Locations
			        var tmpLocations = offices[i].getElementsByTagName("location");
        				
				        for (var j = 0; j<tmpLocations.length; j++) {
				        var locationObj = new Object();
				        locationObj.name = tmpLocations[j].getAttribute("name");
				        officeObj.locations.push(locationObj);
			        }
        			
			        // Hours of operation
			        var tmpHours = offices[i].getElementsByTagName("hour");
        			
			            for (var k = 0; k<tmpHours.length; k++) {
			            var hoursObj = new Object();
			            hoursObj.day = tmpHours[k].getAttribute("day");
			            hoursObj.time = tmpHours[k].getAttribute("time");
				        officeObj.hours.push(hoursObj);
        				
			        }
        			
			        // Add clinic object to our results array
			        clinicResults.push(officeObj);
        			showAddress(officeObj); //function plots the pin on the map
				        
			    }
			    // Now that we have all the pins on the map, lets get the bounds and zoom to that level.
                if (tmpTotalResults > 0) {	
			        map.setZoom(map.getBoundsZoomLevel(bounds));
			        map.setCenter(bounds.getCenter());
			        
		            document.getElementById("errorArea").innerHTML = "";
		            document.getElementById("errorArea").style.display = "none";
			        Locator.determinePagination(officeObj.totalResults, offices.length);
                    document.getElementById("locatorResults").style.backgroundImage = "url(/Style%20Library/images/bkg_results-after.jpg)";
                    
		            Locator.animateNewResults(Locator.resultPages[0]);//compiles the results list
		            // Re-enable go button (if disabled) now that everything is loaded
		            document.getElementById('btnGo').disabled = false;
		            Locator.showLoader(false);
		            Locator.showMap(true);
		            if(getTiers){
		                gloadTiers(xmlPath);
		            } else {
		                plotTiers();
		            }
		            
		        } else {
		            createEmptyMap(Locator.Config.msgNoResults);
		        }
			} else {
			    createEmptyMap();
			    alert("ERROR READING DATA!!");
			}
		 });
		 
	}	
}

// FUNCTIONS COPIED FROM TIER_PARSER.JS !!!!!!!!!!!!!!!
var tmarkers = [];
var tierResults = [];

// parses tier results and places missing tiers on the map
// this will be called AFTER the first gload only once 
// map and clusterer objects have already been created..
function gloadTiers(xmlPath) {
    xmlPath = xmlPath + "&tier=a";
	tierResults.length = 0;
	//GET XML
		
	GDownloadUrl(xmlPath, function(data, responseCode) {
	 	
	  	// To ensure against HTTP errors that result in null or bad data,
	  	// always check status code is equal to 200 before processing the data
	  	if (responseCode == 200) {
	  	    var xml = GXml.parse(data);
	  	    var offices = xml.documentElement.getElementsByTagName("office");
	  	    var servervars = xml.documentElement.getElementsByTagName("servervars");
		    var tmpTotalResults = servervars[0].getAttribute("totalresults");
		    for (var i = 0, officesLength = offices.length; i < officesLength; i++) {
			
		        var officeObj = new Clinic();
		        officeObj.setId(i + Locator.Config.resultLimit);
    			
		        // Set Return Vars 
		        officeObj.totalResults = servervars[0].getAttribute("totalresults");
    			
		        // Office Info
		        officeObj.officeMarker = offices[i].getAttribute("label");
		        officeObj.officePhoto = offices[i].getAttribute("logoUrl");
		        //officeObj.officeDescription = offices[i].getElementsByTagName("clinic_bio")[0].firstChild.nodeValue;
		        officeObj.officeInstitutionId = offices[i].getAttribute("institutionId");
		        officeObj.officeInstitutionName = offices[i].getAttribute("institutionName");
		        officeObj.officeDeptId = offices[i].getAttribute("physicianLocationId");
		        officeObj.officeDeptName = offices[i].getAttribute("departmentName");
		        officeObj.officeAddress  = offices[i].getAttribute("address");
		        officeObj.officeCity  = offices[i].getAttribute("city");
		        officeObj.officeCounty  = offices[i].getAttribute("county");
		        officeObj.officePostal = offices[i].getAttribute("postal");
		        officeObj.officeDistance = offices[i].getAttribute("distance");
		        officeObj.officeLat = offices[i].getAttribute("lat");
		        officeObj.officeLong = offices[i].getAttribute("long");
		        officeObj.officeContact = offices[i].getAttribute("contact");
		        officeObj.officePhone = offices[i].getAttribute("phone");
		        officeObj.officeFax = offices[i].getAttribute("fax");
		        officeObj.officeEmail = offices[i].getAttribute("email");
		        officeObj.officeWeb = offices[i].getAttribute("website");
		        officeObj.officeStartYear = offices[i].getAttribute("yearStarted");
		        officeObj.officeCTBC = offices[i].getAttribute("ctbc");
		        officeObj.officeCTBCemail = offices[i].getAttribute("ctbcEmail");
		        officeObj.offerAvailable = offices[i].getAttribute("freeOffer");
		        officeObj.officeBio = offices[i].getAttribute("bio");
		        //mike
		        officeObj.officeSmile = offices[i].getAttribute("smile");
		        officeObj.officeRecordId = offices[i].getAttribute("id");
		        officeObj.officeTier = offices[i].getAttribute("topTier");
		        //officeObj.officeTier = offices[i].getAttribute("tier");
		        officeObj.officeTierType = offices[i].getAttribute("tierValue");
		        officeObj.officeHasPhoto = offices[i].getAttribute("image");
    			
		        // Physician Info
		        officeObj.physicianId = offices[i].getAttribute("physicianId");
		        officeObj.physicianName = offices[i].getAttribute("physicianName");
		        officeObj.physicianUniversity = offices[i].getAttribute("university");
		        officeObj.physicianDegree = offices[i].getAttribute("degree");
    			
		        //Set Arrays
		        officeObj.services = [];
		        officeObj.specialties = [];
		        officeObj.languages = [];
		        officeObj.treatments = [];
		        officeObj.products = [];
		        officeObj.locations = [];
		        officeObj.hours = [];
    			
		        // Services
		        var tmpServices = offices[i].getElementsByTagName("service");
    				
			        for (var y = 0; y<tmpServices.length; y++) {
			        var servObj = new Object();
			        servObj.name = tmpServices[y].getAttribute("name");
			        officeObj.services.push(servObj);
			        }
    			
		        // Specialties
		        var tmpSpecialties = offices[i].getElementsByTagName("specialty");
    				
			        for (var e = 0; e<tmpSpecialties.length; e++) {
			        var specialObj = new Object();
			        specialObj.name = tmpSpecialties[e].getAttribute("name");
			        officeObj.specialties.push(specialObj);
			        }
    			
		        // Languages
		        var tmpLanguages = offices[i].getElementsByTagName("language");
    				
			        for (var f = 0; f<tmpLanguages.length; f++) {
			        var languageObj = new Object();
			        languageObj.name = tmpLanguages[f].getAttribute("name");
			        officeObj.languages.push(languageObj);
		        }
    			
		        // Treatments
		        var tmpTreatments = offices[i].getElementsByTagName("treatment");
    				
			        for (var g = 0; g<tmpTreatments.length; g++) {
			        var treatmentObj = new Object();
			        treatmentObj.name = tmpTreatments[g].getAttribute("name");
			        treatmentObj.id = tmpTreatments[g].getAttribute("id");
			        treatmentObj.category = tmpTreatments[g].getAttribute("category");
			        officeObj.treatments.push(treatmentObj);
		        }
    			
		        // Products
		        var tmpProducts = offices[i].getElementsByTagName("product");
    				
			        for (var h = 0; h<tmpProducts.length; h++) {
			        var productObj = new Object();
			        productObj.name = tmpProducts[h].getAttribute("name");
			        officeObj.products.push(productObj);
		        }
    			
		        // Locations
		        var tmpLocations = offices[i].getElementsByTagName("location");
    				
			        for (var j = 0; j<tmpLocations.length; j++) {
			        var locationObj = new Object();
			        locationObj.name = tmpLocations[j].getAttribute("name");
			        officeObj.locations.push(locationObj);
		        }
    			
		        // Hours of operation
		        var tmpHours = offices[i].getElementsByTagName("hour");
    			
		            for (var k = 0; k<tmpHours.length; k++) {
		            var hoursObj = new Object();
		            hoursObj.day = tmpHours[k].getAttribute("day");
		            hoursObj.time = tmpHours[k].getAttribute("time");
			        officeObj.hours.push(hoursObj);
    				
		        }
    			
		        // Add clinic object to our results array
		        tierResults.push(officeObj);
    			//showAddress(officeObj); //function plots the pin on the map and sets event listener for the info window
		    }
		    plotTiers();
		} else {
		    alert("ERROR READING TIER XML!!");
		}
	 });	
}
// Function plots tiers on the map that are missing from the current result set
function plotTiers() {
    // Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	var tierIcon = new GIcon();
	tierIcon.iconSize = new GSize(42, 46);
	tierIcon.shadowSize = new GSize(40, 46);
	tierIcon.iconAnchor = new GPoint(18, 43);
	tierIcon.infoWindowAnchor = new GPoint(9, 2);
	tierIcon.infoShadowAnchor = new GPoint(18, 25);
	
	// Creates a marker and listener for map clicks
	function createMarker(point, officeObj) {
		// Create a lettered icon for this point using our icon class
  	    var icon = new GIcon(tierIcon);
  	    icon.image = Locator.Config.blankTierMarker;
  	    var marker = new GMarker(point, icon);
	  	
		// Create the listener object for map clicks
		GEvent.addListener(marker, "click", function() {
			infoTabs = Locator.buildInfoTabs(tierResults[officeObj.returnId() - Locator.Config.resultLimit], officeObj.officeTitle);
			marker.openInfoWindowTabsHtml(infoTabs);
			Locator.trackClinic(officeObj.returnId(), "view");
			map.setCenter(point);
			var tmpToken = GEvent.addListener(map, "moveend", function() {
              Locator.moveMap(0, 50);
              GEvent.removeListener(tmpToken);
            });
            if (officeObj.officeHasPhoto == "True") {
			    Locator.showPanelPhoto();
			}
  		});
		
		tmarkers[officeObj.returnId() - Locator.Config.resultLimit] = marker;
      	return marker;
	}
	
	function showAddress(officeObj) {
		var lat = parseFloat(officeObj.officeLat);
        var lng = parseFloat(officeObj.officeLong);
        var point = new GLatLng(lat,lng);
		//map.setCenter(point, 8);
		var tmpMarker = createMarker(point, officeObj);
		//map.addOverlay(tmpMarker);
		clusterer.AddMarker(tmpMarker, officeObj.showDisplayName(), officeObj.returnId(), officeObj.officeTitle, officeObj);
	}
    
    for(m=0;m<tierResults.length;m++){
        var plotme = true;
        // check that result is not part of current result set before plotting
        for(n=0;n<clinicResults.length;n++){
            if(clinicResults[n].officeRecordId == tierResults[m].officeRecordId){
                plotme = false;
            }
        }
        // not a dupe, plot it
        if(plotme){
            //tmpToPlot += 1;
            showAddress(tierResults[m]);
        } 
    }
}
