function getCurrentLocation()
{
  if(geo_position_js.init())
  {
    geo_position_js.getCurrentPosition(success_callback,error_callback,{enableHighAccuracy:true});
  }
  else
  {
    alert("Functionality not available");
  }
}

function success_callback(p)
{
  document.forms[0].elements["lat"].value = p.coords.latitude.toFixed(2);
  document.forms[0].elements["lng"].value = p.coords.longitude.toFixed(2);
  document.forms[0].submit();
}

function error_callback(p)
{
  alert('error='+p.message);
}   

function initialize_map()
{
    var myOptions = {
        zoom: 4,
        mapTypeControl: true,
        mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
        navigationControl: true,
        navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
        mapTypeId: google.maps.MapTypeId.ROADMAP      
      }
  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function initialize()
{
  if(geo_position_js.init())
  {
    document.getElementById('current').innerHTML="Receiving...";
    geo_position_js.getCurrentPosition(show_position,function(){document.getElementById('current').innerHTML="Couldn't get location"},{enableHighAccuracy:true});
  }
  else
  {
    document.getElementById('current').innerHTML="Functionality not available";
  }
}

function show_position(p)
{
  document.getElementById('current').innerHTML="latitude="+p.coords.latitude.toFixed(2)+" longitude="+p.coords.longitude.toFixed(2);
  var pos=new google.maps.LatLng(p.coords.latitude,p.coords.longitude);
  map.setCenter(pos);
  map.setZoom(14);

  var infowindow = new google.maps.InfoWindow({
      content: "<strong>yes</strong>"
  });

  var marker = new google.maps.Marker({
      position: pos,
      map: map,
      title:"You are here"
  });

  google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map,marker);
  });
}

function createMarker(point, html) {
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {
	  marker.openInfoWindowHtml(html);
	});
	return marker;
}

function createCenterMarker(point)
{
  var baseIcon = new GIcon();
      baseIcon.iconSize=new GSize(32,32);
      baseIcon.shadowSize=new GSize(56,32);
      baseIcon.iconAnchor=new GPoint(16,32);
      baseIcon.infoWindowAnchor=new GPoint(16,0);
  var pushpin = new GIcon(
      baseIcon, "http://maps.google.com/mapfiles/kml/pal5/icon14.png", 
      null, 
      "http://maps.google.com/mapfiles/kml/pal5/icon14s.png");
  return new GMarker(point, pushpin);
}

function initialize_map2(p)
{
  addMarkers(p);
}

function addMarkers(p)
{
if (GBrowserIsCompatible()) {	
  var map = new GMap2(document.getElementById("map_canvas"));
  map.setUIToDefault();
  
  var markers = [];
  var bounds = new GLatLngBounds();
  var firstpoint = false;
  
  //alert(p.locations.length);
  
  for (var x=0; x < p.locations.length; x++) 
  {
	  var s = p.locations[x];
	  
      //alert(s.name + ': ' + s.latitude + ', ' + s.longitude);
      var point = new GLatLng(s.latitude, s.longitude);
      if (!firstpoint) {
        map.setCenter(point);
        firstpoint = true;
      }
      bounds.extend(point);
      html = "<div class=\"mappopup\">";
      if (s.website)
      {
        html += "<a target=\"cilink\" href=\"" + s.website + "\">" + s.name + "</a><br/>";
      }
      else
      {
        html += s.name + "<br/>";
      }
      html += s.address1 + "<br/>";
      html += s.city + ", " + s.state + " " + s.zip5 + "<br/>";
      html += s.phone;
      if (s.opentable)
      {
        html += "<br/><a target=\"cilink\" href=\"" + s.opentable + "\">" + "Open Table Reservations" + "</a>";
      }
      if (s.facebook)
      {
        html += "<br/><a target=\"cilink\" href=\"" + s.facebook + "\">" + "Facebook Fan Page" + "</a>";
      }
      html += "</div>";
      if (s.name == "searchcenter")
      {
        map.addOverlay(createCenterMarker(point));
      }
      else
      {
        map.addOverlay(createMarker(point, html));
      }
      //markers.push(createMarker(point, s.name + "<br/>" + s.address1 + ""));
  }
  
  var zoomLevel = map.getBoundsZoomLevel(bounds);
  if (p.locations.length <= 3 && zoomLevel > 13)
  {
    zoomLevel = 13;
  }

  map.setZoom(zoomLevel);
  map.setCenter(bounds.getCenter());
  map.checkResize();
  map.savePosition();
}
}

