var map;
$(function(){

	map = new GMap2($("#mapView").get(0));
	map.setCenter(new GLatLng(33.584450264346955, 130.44445037841797), 14);
	map.addControl(new GLargeMapControl(),new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,10)));

	var TL = new GTileLayer(new GCopyrightCollection());
	TL.getTileUrl = function(){ return "./images/backTL.jpg" }
	TL.getOpacity = function(){return 0.1}
	map.addOverlay(new GTileLayerOverlay(TL));
	
	map.addOverlay(new GScreenOverlay(
		'./images/map_shadow.png',
		new GScreenPoint(0, -10),
		new GScreenPoint(0, 0),
		new GScreenSize( 2000,10)
	));

	var icon = new GIcon();
	icon.image = "./images/map_p_icon.png";
	icon.iconSize = new GSize(49,45);
	icon.iconAnchor = new GPoint(20,30);
	
	var point = [
		{
			name : "kuukouminami" , 
			lat : 33.59467460059404, 
			lng : 130.45109421014786 
		},{
			name : "kokunaisen" , 
			lat : 33.58607694434694,
			lng : 130.43947219848633
		},{
			name : "kokusaisen" , 
			lat : 33.58181801664121,
			lng : 130.44322729110718 
		}
	];
		
	maker = new Array;
	$(point).each(function(){

		if(this.name == "kuukouminami"){
			maker[this.name] = new GMarker(new GLatLng(this.lat , this.lng),icon);
			map.addOverlay(maker[this.name]);
			maker[this.name].ja = new GLatLng(this.lat , this.lng);
			maker[this.name].name = this.name;
			GEvent.addListener(maker[this.name], "click", function(){
				show(this.name);
			});
			show(this.name);

		}else if(this.name == "kokunaisen"){
			maker[this.name] = new GMarker(new GLatLng(this.lat , this.lng),icon);
			map.addOverlay(maker[this.name]);
			maker[this.name].ja = new GLatLng(this.lat , this.lng);
			maker[this.name].name = this.name;
			GEvent.addListener(maker[this.name], "click", function(){
				show2(this.name);
			});
			show2(this.name);		

		}else if(this.name == "kokusaisen"){
			maker[this.name] = new GMarker(new GLatLng(this.lat , this.lng),icon);
			map.addOverlay(maker[this.name]);
			maker[this.name].ja = new GLatLng(this.lat , this.lng);
			maker[this.name].name = this.name;
			GEvent.addListener(maker[this.name], "click", function(){
				show3(this.name);
			});
			show3(this.name);		
		}

	});

})

var info_win;
function show(name){
	if(info_win)map.removeOverlay(info_win);
	info_win = new CO(name);
	map.addOverlay(info_win);
}
var info_win2;
function show2(name){
	if(info_win2)map.removeOverlay(info_win2);
	info_win2 = new CO(name);
	map.addOverlay(info_win2);
}
var info_win3;
function show3(name){
	if(info_win3)map.removeOverlay(info_win3);
	info_win3 = new CO(name);
	map.addOverlay(info_win3);
}

function CO(name) {this.name = name };
CO.prototype = new GOverlay();
CO.prototype.initialize = function() {
	map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild($("#"+this.name).get(0));
}
CO.prototype.redraw = function(){
	var point=map.fromLatLngToDivPixel(maker[this.name].ja)
	if(this.name == "kuukouminami"){
	$("#"+this.name).css({
		display:"block",
		left:point.x+ 15 +"px",
		top:point.y-parseInt($("#"+this.name).height())+ 190 + "px"
	})
	}else if(this.name == "kokunaisen"){
	$("#"+this.name).css({
		display:"block",
		left:point.x+ -325 +"px",
		top:point.y-parseInt($("#"+this.name).height()) + -15 + "px"
	})
	}else if(this.name == "kokusaisen"){
			$("#"+this.name).css({
		display:"block",
		left:point.x+ -315 +"px",
		top:point.y-parseInt($("#"+this.name).height())+ 190 + "px"
	})
	}
}
CO.prototype.remove = function() {
	$("#"+this.name).css("display","none");
}

