addLoadEvent(initialize);
function initialize() {
	if (window.aCenters === undefined || window.aCenters < 1){
		return;
	}
	else if (aCenters[0][9] != 'USA'){
		showListView()
	}
	else{
		if (GBrowserIsCompatible()) {
	
			function createMarker(point,html) {
		        	var marker = new GMarker(point);
			        GEvent.addListener(marker, "click", function() {
					marker.openInfoWindowHtml(html);
				        });
			         return marker;
		       }


           		var map = new GMap2(document.getElementById("map"));
           		map.setCenter(new GLatLng(37.4419, -122.1419), 0);
	   		map.addControl(new GSmallMapControl());
	   		map.addControl(new GMapTypeControl());
	  
			if (sSearchType == 'state'){
				var thisState = aCenters[0][7];
				var bounds = new GLatLngBounds(new GLatLng(states[thisState]['latS'], states[thisState]['lngW']), new GLatLng(states[thisState]['latN'], states[thisState]['lngE']));
			}
			else{
   	   			var bounds = new GLatLngBounds();

			}


			for (var loc in aCenters){
				//create point
      				var point = new GLatLng(aCenters[loc][0], aCenters[loc][1]);
				//create the popup
				var html = aCenters[loc][2]+'<br />';
				
				if (aCenters[loc][3] != 'n/a' && aCenters[loc][3] != ''){
					html += aCenters[loc][3]+'<br />';	
				}
				if (aCenters[loc][4] != 'n/a' && aCenters[loc][4] != ''){
					html += aCenters[loc][4]+'<br />';	
				}
				if (aCenters[loc][5] != 'n/a' && aCenters[loc][5] != ''){
					html += aCenters[loc][5]+'<br />';	
				}
				
				html += aCenters[loc][6]+', '+aCenters[loc][7]+' '+aCenters[loc][8]+' '+aCenters[loc][9]+'<br /> ';

				if (aCenters[loc][10] != 'n/a' && aCenters[loc][10] != ''){
					html += aCenters[loc][10]+'<br />';	
				}
				
				if (aCenters[loc][11] != 'n/a' && aCenters[loc][10] !=''){
					html += '<a class="ckLocGoal" href="'+aCenters[loc][11]+'" onclick="logGmapGoal(this)" rel="'+aCenters[loc][2]+'" target="new">Visit Our Website</a>';
				}

      				var marker = createMarker(point, html)
      				map.addOverlay(marker);

				if (sSearchType != 'state'){
					bounds.extend(point);
				}
			}

				//set zoom level according to bounds
				map.setZoom(map.getBoundsZoomLevel(bounds));
				//set center according to bounds
				map.setCenter(bounds.getCenter());
		}

	}
}

function showListView() {
	document.getElementById("cyberknifelocations").style.display = "block";
	//document.getElementById("locationmap").style.visibility = "hidden";
	document.getElementById("locationmap").style.display = "none";
}
function showMapView() {
	document.getElementById("cyberknifelocations").style.display = "none";
	//document.getElementById("locationmap").style.visibility = "visible";
	document.getElementById("locationmap").style.display = "";

}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

