	var closeLocations = new Array();
	var mapPointers = new Array();
	var maxCloseLocations  = 30;
	var closeFound = 0;
	var zip = getQueryVariable('zipCode');
	var zoom = getQueryVariable('radius');
	var directions = null;
	var bookings = 'https://ratnertest.mylocalsalon.com/onlinebooking/?';
	//var degrees = 1;
	
		
	function mapsInitialize() {
		var mapDiv =document.getElementById("map_canvas")
	
		if(mapDiv!=null){
			if (GBrowserIsCompatible()) {
				var map = new GMap2(mapDiv);
				var geocoder = new GClientGeocoder();
				var directionsPanel =document.getElementById("route");
				directions =  new GDirections(map, directionsPanel);
	
				var degrees = 1;
				var nolocation  = 0;
	
				if(!zip || zip ==''){ 
					map.setCenter(new google.maps.LatLng(38.75,-76.5), 7);
					map.setUIToDefault();
					return;
				}
				zoom = parseInt(zoom);
				//var degrees = miles/ 45;
				switch(zoom)
				{
					case 14:degrees = .2;break;
					case 13:degrees = .3;break;
					case 12:degrees = .4;break;
					case 11:degrees = .5;break;
					case 10:degrees = .75;break;
					default:degrees = 1;break;
				}
	 
	
	
				geocoder.getLatLng(zip,
				function(point) {
					if (!point) {
						alert("We're sorry, we could not locate " + zip);
	
	
						} else {
							var tinyIcon = new GIcon();
							tinyIcon.image = "http://labs.google.com/ridefinder/images/mm_20_green.png";
							tinyIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
							tinyIcon.iconSize = new GSize(12, 20);
							tinyIcon.shadowSize = new GSize(22, 20);
							tinyIcon.iconAnchor = new GPoint(6, 20);
							tinyIcon.infoWindowAnchor = new GPoint(5, 1);
	
	
							var marker = new GMarker(point,tinyIcon);
							map.addOverlay(marker);
							//marker.openInfoWindowHtml(zip);
							var json = getPoints();
	
	
							for(place in json.locations){
								getStore(map,directions, json.locations[place],degrees,point,zip);
							}
	
							var closeLocationsDiv = document.getElementById('routedefault');
	
							if(closeLocations.length > 0){
								//map.clearOverlays();
								closeLocationsDiv.style.display = 'block';
								closeLocationsDiv.innerHTML="<b>Locations Near You</b><br /><hr>";
								closeLocations.sort(sortDistance);
	
								for(var jj=0;jj<closeLocations.length;jj++){
									if (jj <maxCloseLocations){
										var place = closeLocations[jj];
	
										var tinyIcon = new GIcon();
											tinyIcon.image = '/global/images/maps/hc0'+(jj+1)+'.png';
											//tinyIcon.image = '/global/images/maps/hc01.png';
											tinyIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
											tinyIcon.iconSize = new GSize(35, 35);
									
											tinyIcon.shadowSize = new GSize(27, 27);
											tinyIcon.iconAnchor = new GPoint(6, 20);
											tinyIcon.infoWindowAnchor = new GPoint(5, 1);
											
										
										var store = new GMarker(place[2],tinyIcon);
	
										
										closeLocationsDiv.innerHTML+=
										"<table id='pointer-"+(jj+1)+"'><tr>"+ 
										'<td style="width:100px;text-align:center;" onclick="storeClick(\''+jj+'\')"; >'+
										'<img src="/global/images/maps/hc0'+(jj+1)+'.png"   />'+
										//'<img src="/global/images/maps/hc01.png"   />'+
										"<br/>Approx.<br/>"+place[0]+" miles </td>"+
										'<td style="width:200px;" onclick="storeClick(\''+jj+'\')"; >' + place[1]+ "</td></tr></table><hr>"
										
										addStore(map,store,zip,place[1],place[3],(jj+1));
										
									}
								}
							}
							if(closeFound ==0 ){
								closeLocationsDiv.innerHTML="We're sorry, but there are no Hair Cuttery salons that match your search";
							}
							map.setCenter(point, zoom-1);
						}
					}
					);
				}
				map.setUIToDefault();
			}
		}
		function sortDistance(a, b){
			return a[0] - b[0];
		}
		function getStore(map,directions, the_location,absdegrees,point,start){
	
			if(Math.abs(the_location.lat-point.y) > absdegrees||
			Math.abs (the_location.long-point.x) > absdegrees){ return;}
			closeFound = 1;
	
			var latlng = new google.maps.LatLng(the_location.lat, the_location.long);
			
			var endClick ='directionsClick("' +  the_location.street+' ' + the_location.city+ ' ' +the_location.state+' ' +the_location.zip +'")';
			
			var end = the_location.street+ ' ' + the_location.city+ ' ' +the_location.state+' ' +the_location.zip ;
			//var clean ="<b><a href='#' onclick='" + endClick + "' >" + the_location.storename + "</a></b><br/>"+
			var linkStr = "http://maps.google.com/maps?saddr=" + zip + "&daddr=" + end.replace(/\s/g,"+");
			var clean ="<b>" + the_location.storename + "</b><br/>"+
			the_location.street + "<br/>"+
			the_location.city + ", "+
			the_location.state + " "+
			the_location.zip + "<br/>" +
			the_location.phone + "<br/>" +
			"<a target='_blank' href=" + linkStr + ">Directions</a>";
			
			
			//if(the_location.siteid !=''){
//				clean+=" &nbsp;&nbsp;&nbsp;<a target='_blank' class='book-link' href='"+bookings +"siteid=" + the_location.siteid + "&event="+the_location.event + "' ><img src='/global/images/maps/book-it.png' class='book-it' />  </a>"+ "<br/>";
//			}else{
//				clean+="<br/>";
//			}
			
				
			if(Math.abs(the_location.lat-point.y) < .5 && Math.abs (the_location.long- point.x) < .5){
			 	var distance =Math.round(point.distanceFrom(latlng) * 0.00621371192 ,2)/10;
				//var distance = point.distanceFrom(latlng, 3959).toFixed(1);

				closeLocations.push( new Array(distance,clean,latlng,end));
			}
			
		}
		function addStore(map,store,zip,info,end,resultIndex){
			map.addOverlay(store);
			
			GEvent.addListener(store, "click", function() {
				for(var i = 0; i < maxCloseLocations; i++){
					var elem = document.getElementById('pointer-'+(i+1));
					if(elem!=null){elem.style.backgroundColor='transparent';}
				}
			
			store.openInfoWindowHtml("<img src='/global/images/logo/logo_reflect.jpg' alt='hc logo' class='gm_hc_logo' /><br/>" + info);
			document.getElementById('pointer-'+resultIndex).style.backgroundColor='#999999';
			
			});
			
			mapPointers.push(store);
		}
		function storeClick(storeIndex){
			GEvent.trigger(mapPointers[storeIndex], "click");
			
		}
		function directionsClick(end){
 
			directions.load("from: "+zip +" to: " +end);
			document.getElementById('routedefault').style.display = 'none';
			document.getElementById('route').style.display = 'block';
			document.getElementById('links').style.display= 'block';
			document.getElementById('print').onclick = function(){window.open("http://maps.google.com/maps?f=d&source=s_d&saddr="+zip +"&daddr="+end +"%28Hair+Cuttery%29&ie=UTF8&z=13&layer=c&pw=2",'mywindow','scrollbars=yes,width=800,height=600'); return false;}
			
			
		}
		function directionsClear(){
			document.getElementById('routedefault').style.display = 'block';
			document.getElementById('route').style.display = 'none';
			document.getElementById('links').style.display= 'none';
		}
		
		function getQueryVariable(variable) {
			var query = window.location.search.substring(1);
			var vars = query.split("&");
			for (var i=0;i<vars.length;i++) {
				var pair = vars[i].split("=");
				if (pair[0] == variable) {
					return pair[1];
				}
			}
		}

