var setObj = new Object();
setObj.lat = 43.058639;
setObj.lng = 141.342601;
setObj.msg = "〒060-0042<br />札幌市中央区大通西10丁目4番16号<br />ダンロップSKビル 7階<br />TEL / 011-219-0591";

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 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), 16);
	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()) {
	onloadObjects.push('mapsload()');
	//onload = mapsload;
	onunload = GUnload;
}
