var selec = 0;
var map = null;
var geocoder = null;

/* GoogleMap*/
function initGMap(address, name) {

    if (document.getElementById("map_canvas") == null)
        return;
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 1);
        map.setUIToDefault();
        geocoder = new GClientGeocoder();
    }
    showAddress(address, name);
}

function showAddress(address, name) {
    if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
              if (!point) {
                  alert(address + " not found");
              } else {
                  map.setCenter(point, 15);
                  var marker = new GMarker(point, { draggable: true });
                  map.addOverlay(marker);
                  GEvent.addListener(marker, "dragend", function() {
                      marker.openInfoWindowHtml(marker.getLatLng().toUrlValue(6));
                  });
                  GEvent.addListener(marker, "click", function() {
                      marker.openInfoWindowHtml(name);
                  });
                  GEvent.trigger(marker, "click");
              }
          }
        );
    }
}



/* Menu*/

function xVisibility(e, bShow) {
    if (!(e = xGetElementById(e)))
        return null;
    if (e.style && xDef(e.style.visibility)) {
        if (xDef(bShow)) e.style.display = bShow ? 'inline' : 'none';
        return e.style.visibility;
    }
    return null;
}


function xGetElementById(e) {
    if (typeof (e) != 'string') return e;
    if (document.getElementById) e = document.getElementById(e);
    else if (document.all) e = document.all[e];
    else e = null;
    return e;
}


function xDef() {
    for (var i = 0; i < arguments.length; ++i) {
        if (typeof (arguments[i]) == 'undefined')
            return false;
    }
    return true;
}


function xShow(e) 
	{
	
		return xVisibility(e,1);
	}
	
function xHide(e)
	{
		return xVisibility(e,0);
	}



	function select(num) {

	    
	    if (document.getElementById(selec) != null)
	        document.getElementById(selec).style.display = "none";
	    
//	    if(document.getElementById(num)!=null)
	    document.getElementById(num).style.display = "";
	    selec = num;
//	    
//	    if (selec != 0)
//	        eval("xHide('menu" + selec + "');");

//	    if (selec != num) {
//	        eval("xShow('menu" + num + "');");
//	        selec = num;
//	    }
//	    else {
//	        selec = 0;
//	    }
	}

	function init2(num) {
	    //eval("xShow('menu" + num + "');");
	    if (document.getElementById(num) != null)
	        document.getElementById(num).style.display = "";
	    selec = num;
	
	} 


    function init(num, address, name) 
	{
	    //eval("xShow('menu" + num + "');");
	    if (document.getElementById(num) != null)
	        document.getElementById(num).style.display = "";
	    selec = num;

	    initGMap(address, name);
	}
