
if(detectBrowser.modernBrowser())
{



Event.observe(window,'load',function()
{
     if($('map_check_centers'))
	 {
    $('map_check_centers').checked=true;
	 }
	
	
	  if($('map_check_facilities'))
	  {
	$('map_check_facilities').checked=true;
	  }
	
	if(window['GBrowserIsCompatible'])
	{
		var geocoder;
	
	   function inverseOrder(marker,b) 
	  {
	    return -GOverlay.getZIndex(marker.getPoint().lat());
      }
		
        function identifyAddress1(id,dontClear,options) {
			var location;
			if(parseInt(id) > -1){
				// this is a location id -- retrieve a location object from array
				location = locations.find(function(item){ return item.id==id; });
			} else {
				// not an integer. this might be a location
				if(typeof(id)=='object' && parseInt(id['id']) > -1){
					// it is a location
					location = id;
				} else {
					return false;
				}
			}
			if(dontClear!=true){
				map.clearOverlays();
			}
			
			
			     if($('map_check_centers'))
				 {
			  $('map_check_centers').checked=false;
			     }
				 
				 
			   if($('map_check_facilities'))
			   {
	          $('map_check_facilities').checked=false;
			   }
			
			geocoder.getLatLng(
				location['address'],
				function(point) {
				
				    //alert(point);
					// use optional zoom parameter if its there and is a number. Otherwise, default to zoom level 3
					if(options && typeof(parseInt(options['zoom']))=='number'){
						map.setCenter(points[id-1],options['zoom']);
					} else {
						map.setCenter(new GLatLng(39, -93), 3);
					}
					
					var marker = new GMarker(points[id-1],icon);
					map.addOverlay(marker);	
					var html = (
						'<div id="info_window">' +
							'<div id="image_wrapper">' +
								'<img src="' + location['image'] + '"alt="' + location['altText'] +
								 '"title="' + location['title'] +'" border="0" />' +
							'</div>' +
							'<div id="data_wrapper">' +
								'<p id="info_window_title">' + location['place_name'] + '</p>' +
								'<p id="info_window_description">' + location['address'] + '</p>' +
								'<p class="info_window_link"><b><a href="' + location['website'] +'" target="_blank">View web site</a></b></p>' +
								'<p class="info_window_link"><b><a href="' + location['visitor'] +'" target="_blank">Visitors information</a></b></p>' +
								'<p class="info_window_link info_window_link_last"><b><a href="' + location['driving'] +'" target="_blank">Driving instructions</a></b></p>' +
							'</div>' +
						'</div>'
					);
					GEvent.addListener(marker,"click", function() {
							map.openInfoWindowHtml(points[id-1],html);
					});
					map.openInfoWindowHtml(points[id-1],html);
				}
			);				
		}
		
		
		// loads the map according to the one location selected
		function identifyAddress(id,dontClear,options)


		{
			
			if(dontClear!=true)
			{
				map.clearOverlays();
			}
			
							  
			
            for (i=0;i<points.length;i++)
			{
			
            // use optional zoom parameter if its there and is a number. Otherwise, default to zoom level 3
					if(options && typeof(parseInt(options['zoom']))=='number')
					{
						map.setCenter(points[i],options['zoom']);
					} else
					{
						map.setCenter(new GLatLng(39, -93), 3);
					}
				
					
					
					
					addEventListeners(i);
					
					
					

            }
			
		//End of Identify Adress
		}
	
	
	    function addEventListeners(i)
		{
		
		    		map.setCenter(new GLatLng(39, -93), 3);	
					 html = (
						'<div id="info_window">' +
							'<div id="image_wrapper">' +
								'<img src="' + locations[i]['image'] + '"alt="' + locations[i]['altText'] +
								 '"title="' + locations[i]['title'] +'" border="0" />' +
							'</div>' +
							'<div id="data_wrapper">' +
								'<p id="info_window_title">' + locations[i]['place_name'] + '</p>' +
								'<p id="info_window_description">' + locations[i]['address'] + '</p>' +
								'<p class="info_window_link"><b><a href="' + locations[i]['website'] +'" target="_blank">View web site</a></b></p>' +
								'<p class="info_window_link"><b><a href="' + locations[i]['visitor'] +'" target="_blank">Visitors information</a></b></p>' +
								'<p class="info_window_link info_window_link_last"><b><a href="' + locations[i]['driving'] +'" target="_blank">Driving instructions</a></b></p>' +
							'</div>' +
						'</div>'
					);
	                
					if ( i == 0)
					{
					html0=html;
					
					var marker = new GMarker(points[i],icon);
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(37.414968,-122.051723),html0);
					});
					}
					
					if ( i == 1)
					{
					html1=html;
					var marker = new GMarker(points[i],icon);
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(34.951691,-117.891826),html1);
					});
					}
					
					if ( i == 2)
					{
					html2=html;
					var marker = new GMarker(points[i],icon);
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(41.4198,-81.85290),html2);
					});
					}
					
					if ( i == 3)
					{
					html3=html;
					var marker = new GMarker(points[i],icon);
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(38.997438,-76.853014),html3);
					});
					}
					
					if ( i == 4)
					{
					html4=html;
					var marker = new GMarker(points[i],icon);
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(40.805437,-73.965629),html4);
					});
					}
					
					if ( i == 5)
					{
					html5=html;
					var marker = new GMarker(points[i],icon);
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(39.430687,-80.195721),html5);
					});
					}
					
					if ( i == 6)
					{
					html6=html;
					var marker = new GMarker(points[i],icon);
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(34.20,-118.174623),html6);
					});
					}
					if ( i == 7)
					{
					html7=html;
					var marker = new GMarker(points[i],icon);
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(29.562688,-95.092172),html7);
					});
					}
					
					if ( i == 8)
					{
					html8=html;
					var marker = new GMarker(points[i],icon);
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(28.586,-80.65),html8);
					});
					}
					
					if ( i == 9)
					{
					html9=html;
					var marker = new GMarker(points[i],icon);
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(37.08,-76.36013),html9);
					});
					}
					
					if ( i == 10)
					{
					html10=html;
					var marker = new GMarker(points[i],icon);
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(34.711326,-86.653783),html10);
					});
					}
					
					if ( i == 11)
					{
					html11=html;
					var marker = new GMarker(points[i],icon);
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(38.883012,-77.015982),html11);
					});
					}
					
					if ( i == 12)
					{
					html12=html;
					var marker = new GMarker(points[i],{zIndexProcess:inverseOrder,icon:icon});
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(30.3744020,-89.6181200),html12);
					});
					}
					
					if ( i == 13)
					{
					html13=html;
					var marker = new GMarker(points[i],{zIndexProcess:inverseOrder,icon:icon});
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(30.388507,-89.613906),html13);
					});
					}
					
					if ( i == 14)
					{
					html14=html;
					var marker = new GMarker(points[i],icon);
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(37.939865,-75.47204),html14);
					});
					}
					
					if ( i == 15)
					{
					html15=html;
					var marker = new GMarker(points[i],icon);
					map.addOverlay(marker);	
					GEvent.addListener(marker,"click", function()
					{
					       
							map.openInfoWindowHtml(new GLatLng(32.506512,-106.6118),html15);
					});
					}
					
	}				
	
		// brings all centers on click on link
		function allCenters(ev)
		{
			if(ev.target.nodeName!="INPUT" && ev.target.nodeName!="input")
			{
				$('map_check_centers').checked = !$('map_check_centers').checked;
				
				ev.stop();
     		}
			mapFilteredLocations();
			return false;
		}
	
	
		// brings all facilities on click on link
		function allFacilities(ev)
		{
			if(ev.target.nodeName!="INPUT" && ev.target.nodeName!="input")
			{
				$('map_check_facilities').checked = !$('map_check_facilities').checked;
				ev.stop();
			}
			mapFilteredLocations();
			return false;
		}
	
		Event.observe($$('#map_allcenters a')[0],'click',allCenters);
		Event.observe($$('#map_check_centers')[0],'click',allCenters);
		Event.observe($$('#map_allfacilities a')[0],'click',allFacilities);
		Event.observe($$('#map_check_facilities')[0],'click',allFacilities);
		
		
		
		
	
		function mapFilteredLocations()
		{
			map.clearOverlays();
			if($('map_check_centers').checked)
			{			
				for (var i = 0; i < locations.length;i++)
				{	
					if(locations[i]['type'] == '1')
					{
					addEventListeners(i);
					}	
				}
				
			}
			if($('map_check_facilities').checked)
			{
			for (i = 0; i < locations.length;i++)
				{				
					if(locations[i]['type'] == '2')
					{
						addEventListeners(i);
					}
				}
			}
		}
		
		
		
		if (GBrowserIsCompatible())
		{
		
		    var points = new Array();
            points[0] = new GLatLng(37.414968,-122.051723);
            points[1] = new GLatLng(34.951691,-117.891826);
           	points[2] = new GLatLng(41.4198,-81.85290);
			points[3] = new GLatLng(38.997438,-76.853014);
            points[4] = new GLatLng(40.805437,-73.965629);
            points[5] = new GLatLng(39.430687,-80.195721);
            points[6] = new GLatLng(34.20,-118.174623);
			points[7] = new GLatLng(29.562688,-95.092172);
			points[8] = new GLatLng(28.586,-80.65);
			points[9] = new GLatLng(37.08,-76.36013);
            points[10] =new GLatLng(34.711326,-86.653783);
            points[11] =new GLatLng(38.883012,-77.015982);
			points[12] =new GLatLng(30.3744020,-89.6181200);
			points[13] =new GLatLng(30.388507,-89.613906);
			points[14] =new GLatLng(37.939865,-75.47204);
			points[15]=new GLatLng(32.506512,-106.6118);
            
         	var html,html0,html1,html2,html3,html4,html5,html6,html7,html8,html9,html10,html11,html12,html13,html14,html15;	

		
		    var locationSelector = new Element("select");	
			locations.each(function(location)
			{
			    var opElem = new Element("option",{'value':location['id']});
				opElem.update(location['place_name']);
				locationSelector.appendChild(opElem);
			});
	
			$('locations_selector').appendChild(locationSelector);
			var skinnedDropper = new SkinnedSelect($$('#locations_selector')[0],$$('#locations_selector select')[0],function(){
				identifyAddress1($$('#locations_selector select')[0].value,false,{'zoom':14});
			},'','gray');
			

			var map = new GMap2(document.getElementById("map_canvas"));
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.addControl(new GOverviewMapControl());
			map.enableScrollWheelZoom();
			geocoder = new GClientGeocoder();
			map.setCenter(new GLatLng(39, -93), 3);
			
			// Creates the  customized marker icon
			var icon = new GIcon();
			icon.image = "/templateimages/redesign/modules/locations/blue_marker.png";
			icon.iconSize = new GSize(13, 27);
			icon.iconAnchor = new GPoint(8, 25);
			icon.infoWindowAnchor = new GPoint(5, 1);	
			identifyAddress(true);
				
	
		}
		
		
		
	}
	
});



}