var map="";

var markers=new Array();

$(document).ready(function(){
	$.ajax({
		url:"map/store.xml",
		type:"GET",
		error: function(){
			alert("xmlファイルの読み込みに失敗しました");
		},
		dataType:"xml",
		success:function(xml){
			parseXml(xml);
		}
	});

	map = new GMap2(document.getElementById("gmap"),{size:new GSize(630,480)});
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.addControl(new GOverviewMapControl());
	var center = new GLatLng(lat,lng);
	map.setCenter(center, zoom);
	map.enableScrollWheelZoom();

	$("#gmap").mousemove(function(e){
		$("#altwnd").css("top",e.pageY-$("#gmap").offset().top+10+'px');
		$("#altwnd").css("left",e.pageX-$("#gmap").offset().left+10+'px');
	});
});


function parseXml(xml)
{
	$(xml).find("store").each(function(){
//		if($(this).attr("area")==area){
			markers.push(new icons($(this)))
//		}
	});
}


function icons(xml){

	this.name=xml.children("name").text();
	this.address=xml.children("address").text();
	this.tel=xml.children("tel").text();
	this.lat=xml.children("lat").text();
	this.lng=xml.children("lng").text();
	this.htmlbody;
	this.markerIcon;
	this.opt;
	this.marker;

	this.htmlbody="<div class=\"gmap-baloon\"><strong>"+this.name+"</strong>";
	this.htmlbody+="<table>";
	this.htmlbody+="<tr><th>住所</th><td>"+this.address+"</td></tr>" ;
	this.htmlbody+="<tr><th>TEL</th><td>"+this.tel+"</td></tr>" ;
	this.htmlbody+="</div>";

	this.markerIcon=new GIcon();
	this.markerIcon.image="map/store.png";
	this.markerIcon.iconSize=new GSize(25,40);
	this.markerIcon.iconAnchor=new GPoint(12, 40);
	this.markerIcon.infoWindowAnchor=new GPoint(12, 0)

	this.opt={icon:this.markerIcon};

	this.marker=new GMarker(new GPoint(this.lng,this.lat),this.opt);
	this.marker.infohtml=this.htmlbody;
	this.marker.name=this.name;
	map.addOverlay(this.marker);

	GEvent.addListener(this.marker, 'click', function(){
		this.openInfoWindowHtml(this.infohtml);
		$("#altwnd").css("display","none");
		$("#altwnd").html(""); 
	});
	GEvent.addListener(this.marker, 'mouseover', function(){
		$("#altwnd").css("display","block");
		$("#altwnd").html(this.name); 
	});
	GEvent.addListener(this.marker, "mouseout", function() {
		$("#altwnd").css("display","none");
		$("#altwnd").html(""); 
	});
}
