var setObj = new Object();
setObj.lat = 34.022982;
setObj.lng = 133.78409;
setObj.msg = "有限会社サファリ<br />TEL.0883-76-0745";

var gmap = null;
var adjust_x = 54;
var adjust_y = 160;
setObj.disp = 1;
var customWindowObj = document.getElementById("gmap_window");
var customWindowBodyObj = document.getElementById("custom_disp");

function tf(obj) {
	if(obj.value == obj.defaultValue){
		obj.value = "";
		obj.style.color = "#000000";
	}
}
function tb(obj) {
	if(obj.value == ""){
		obj.value = obj.defaultValue;
		obj.style.color = "#999999";
	}
}

function openCustomWindowBeta(msg,lat,lng){
	var customWindowObj = document.getElementById("gmap_window");
	var customWindowBodyObj = document.getElementById("custom_disp");
	if(setObj.disp){
		adjustPos();
		customWindowObj.style.display = "block";
		customWindowBodyObj.innerHTML = msg;
		setObj.disp = 0;
	}
	else {
		var customWindowObj = document.getElementById("gmap_window");
		customWindowObj.style.display = "none";
		setObj.disp = 1;
	}
}
//
function closeCustomWindow(){
	var customWindowObj = document.getElementById("gmap_window");
	customWindowObj.style.display = "none";
	setObj.disp = 1;
}
function adjustPos(){
	var customWindowObj = document.getElementById("gmap_window");
	var marker_pixls = gmap.fromLatLngToDivPixel(new GLatLng(setObj.lat, setObj.lng));
	customWindowObj.style.top = (marker_pixls.y - adjust_y) + "px";
	customWindowObj.style.left = (marker_pixls.x - adjust_x) + "px";
}
function mapsreload(){
	gmap = new GMap2(document.getElementById("gmap"));
	gmap.setCenter(new GLatLng(setObj.lat,setObj.lng), 18);
	
	var customInfoDIV = document.getElementById("gmap_window");
	function customBox(){}
	customBox.prototype = new GOverlay();
	customBox.prototype.initialize = function(gmap){
		//gmap.getPane(G_MAP_MARKER_PANE).appendChild(customInfoDIV);
		//customInfoDIV.style.zIndex = 300000;
	}
	customBox.prototype.remove = function() {
		gmap.getPane(G_MAP_MARKER_PANE).removeChild(customInfoDIV);
	}
	customBox.prototype.copy = function() {
		return new customBox();
	}
	customBox.prototype.redraw = function(force){}
	customInfoWindow = new customBox();
	gmap.addOverlay(customInfoWindow);
	
	gmap.addControl(new GLargeMapControl());
	gmap.addControl(new GMapTypeControl(true));
	gmap.addControl(new GScaleControl());
	gmap.setMapType(G_HYBRID_MAP);
	var icon = new GIcon();
	icon.image = "images/pin.png";
	icon.iconSize = new GSize(40, 40);
	icon.iconAnchor = new GPoint(20, 30);
	icon.infoWindowAnchor = new GPoint(40, 40);
	var marker = new GMarker(new GLatLng(setObj.lat,setObj.lng), icon);
	gmap.addOverlay(marker);
}
function mapsload() {
	gmap = new GMap2(document.getElementById("gmap"));
	gmap.setCenter(new GLatLng(setObj.lat,setObj.lng), 15);
	var customInfoDIV = document.getElementById("gmap_window");
	function customBox(){}
	customBox.prototype = new GOverlay();
	customBox.prototype.initialize = function(gmap){
		gmap.getPane(G_MAP_MARKER_PANE).appendChild(customInfoDIV);
		customInfoDIV.style.zIndex = 300000;
	}
	customBox.prototype.remove = function() {
		gmap.getPane(G_MAP_MARKER_PANE).removeChild(customInfoDIV);
	}
	customBox.prototype.copy = function() {
		return new customBox();
	}
	customBox.prototype.redraw = function(force){}
	customInfoWindow = new customBox();
	gmap.addOverlay(customInfoWindow);
	
	gmap.addControl(new GLargeMapControl());
	gmap.addControl(new GMapTypeControl(true));
	gmap.addControl(new GScaleControl());
	gmap.setMapType(G_HYBRID_MAP);
	var icon = new GIcon();
	icon.image = "images/pin.png";
	icon.iconSize = new GSize(40, 40);
	icon.iconAnchor = new GPoint(20, 30);
	icon.infoWindowAnchor = new GPoint(40, 40);
	var marker = new GMarker(new GLatLng(setObj.lat,setObj.lng), icon);
	gmap.addOverlay(marker);
	
	GEvent.addListener(marker, "click", function(){openCustomWindowBeta(setObj.msg,setObj.lat, setObj.lng);});
	GEvent.addListener(gmap, "moveend", function() {adjustPos();});
	GEvent.addListener(gmap, "zoomend", function() {adjustPos();});
	openCustomWindowBeta(setObj.msg,setObj.lat, setObj.lng);
}
if (GBrowserIsCompatible()) {
	addEventSet(window,"load",function(){mapsload();});
	//onload = mapsload;
	onunload = GUnload;
}

