

function anchor_open(id){
	var request = GXmlHttp.create();
	var html = '';
	request.open("GET", "shop.php?id=" +id ,true);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			var xmlDoc = request.responseXML;
			var places = xmlDoc.documentElement.getElementsByTagName("place");
			var str ='<table border="0" cellspacing="0" cellpadding="7" width="100%">';
			var latitude = parseFloat(places[0].getAttribute("latitude") );
			var longitude = parseFloat(places[0].getAttribute("longitude") );
			var point    = new GLatLng( latitude,longitude );

			var choka_html = "<div id='balloon' class='clearfix'><div class='choka_col clearfix'><div class='choka_header clearfix'>";
			var html = "<div id='balloon' class='clearfix'><div class='choka_col clearfix'><div class='choka_header clearfix'>";
			if( places[0].getElementsByTagName("photo").length != 0 ) {
				html += "<div class='shop_photo'><img src='";
				html += places[0].getElementsByTagName("photo")[0].firstChild.nodeValue;
				if(places[0].getElementsByTagName("size")[0].firstChild.nodeValue=="w"){
					html += "' width='90'></div>";
				}else{
					html += "' width='60'></div>";
				}
			}

			if( places[0].getElementsByTagName("name").length != 0 ) {
				choka_html += "<div class='shop_name'>";
				html += "<div class='shop_name'>";

				var title = places[0].getElementsByTagName("name")[0].firstChild.nodeValue;

				if( places[0].getElementsByTagName("id").length != 0 ) {
					if(places[0].getElementsByTagName("icon")[0].firstChild.nodeValue == "sea" ||
					   places[0].getElementsByTagName("icon")[0].firstChild.nodeValue == "bass"||
					   places[0].getElementsByTagName("icon")[0].firstChild.nodeValue == "freshwater"){
						var id = places[0].getElementsByTagName("id")[0].firstChild.nodeValue;
						choka_html += "<a href='http://www.fishing-v.jp/choka/shop.php?s=" + id + "' target='_blank'>" + title + "</a>";
						html += "<a href='http://www.fishing-v.jp/choka/shop.php?s=" + id + "' target='_blank'>" + title + "</a>";
					}

					if(places[0].getElementsByTagName("icon")[0].firstChild.nodeValue == "shop"){
						var id = places[0].getElementsByTagName("id")[0].firstChild.nodeValue - 10000000;
						html += "<a href='http://www.fishing-v.jp/data/shop/shop_detail.php?id=" + id + "' target='_blank'>" + title + "</a>";
					}

					if(places[0].getElementsByTagName("icon")[0].firstChild.nodeValue == "kantsuri"){
						var id = places[0].getElementsByTagName("id")[0].firstChild.nodeValue - 20000000;
						html += "<a href='http://www.fishing-v.jp/data/kantsuri/content.php?kantsuri_id=" + id + "' target='_blank'>" + title + "</a>";
					}

				}else{
					choka_html += title;
					html += title;
				}
				choka_html += "</div>";
				html += "</div>";
			}

			if( places[0].getElementsByTagName("address").length != 0 ) {
				html += "<div class='navi'>住所：";
				html += places[0].getElementsByTagName("address")[0].firstChild.nodeValue;
				html += "</div>";
			}

			if( places[0].getElementsByTagName("tel").length != 0 ) {
				html += "<div class='navi'>電話番号：";
				html += places[0].getElementsByTagName("tel")[0].firstChild.nodeValue;
				html += "</div>";
			}

			if( places[0].getElementsByTagName("url").length != 0 ) {
				html += "<div class='navi'>URL：";
				html += "<a href='" + places[0].getElementsByTagName("url")[0].firstChild.nodeValue + "' target='_blank'>";
				html +=  places[0].getElementsByTagName("url")[0].firstChild.nodeValue + "</a>";
				html += "</div>";
			}

			if( places[0].getElementsByTagName("holiday").length != 0 ) {
				html += "<div class='navi'>定休日：";
				html += places[0].getElementsByTagName("holiday")[0].firstChild.nodeValue;
				html += "</div>";
			}

			if( places[0].getElementsByTagName("presentation").length != 0 ) {
				html += "<div class='comment'><br />";
				html += places[0].getElementsByTagName("presentation")[0].firstChild.nodeValue;
				html += "</div>";
			}
			
			choka_html +="</div>";
			html +="</div>";

			if( places[0].getElementsByTagName("date").length != 0 ) {
				choka_html += "<span class='choka_date'>";
				choka_html += places[0].getElementsByTagName("date")[0].firstChild.nodeValue;
				choka_html += "の釣果</span><br>";
			}

			if( places[0].getElementsByTagName("choka").length != 0 ) {
				choka_html += "<table><tr><td><div id='choka_info'><div class='choka_num_head'>　</div><div class='choka_box_head'>釣りもの</div><div class='choka_box_head'>大きさ</div><div class='choka_box_head'>釣果</div></div>";

				choka_html += places[0].getElementsByTagName("choka")[0].firstChild.nodeValue;

				choka_html += "</td></tr></table>";
			}

			if( places[0].getElementsByTagName("comment").length != 0 ) {
				choka_html += "<div class='comment'>";
				choka_html += places[0].getElementsByTagName("comment")[0].firstChild.nodeValue;
				choka_html += "</div>";
			}


			if(places[0].getElementsByTagName("icon")[0].firstChild.nodeValue == "sea" ||
			   places[0].getElementsByTagName("icon")[0].firstChild.nodeValue == "bass"||
			   places[0].getElementsByTagName("icon")[0].firstChild.nodeValue == "freshwater"){
				html += "<div class='comment'><a href='http://www.fishing-v.jp/choka/shop.php?s=" + id + "' target='_blank'>";
			}

			if(places[0].getElementsByTagName("icon")[0].firstChild.nodeValue == "shop"){
				html += "<div class='comment'><a href='http://www.fishing-v.jp/data/shop/shop_detail.php?id=" + id + "' target='_blank'>";
			}

			if(places[0].getElementsByTagName("icon")[0].firstChild.nodeValue == "kantsuri"){
				html += "<div class='comment'><a href='http://www.fishing-v.jp/data/kantsuri/content.php?kantsuri_id=" + id + "' target='_blank'>";
			}

				html += "もっと見る</a></div>";


			if(places[0].getElementsByTagName("choka_cd").length != 0 ){
				choka_html += "<div class='comment'><a href='http://www.fishing-v.jp/choka/choka.php?id=";
				choka_html += places[0].getElementsByTagName("choka_cd")[0].firstChild.nodeValue;
				choka_html += "' target='_blank'>もっと見る</a></div>";
			}


			choka_html += "</div></div>";

			if( places[0].getElementsByTagName("icon").length != 0 ) {
				var icon = places[0].getElementsByTagName("icon")[0].firstChild.nodeValue;
			}

			var id = places[0].getElementsByTagName("id")[0].firstChild.nodeValue;

			if( places[0].getElementsByTagName("choka").length == 0 && places[0].getElementsByTagName("comment").length == 0 ){
				var infoTabs = [
					new GInfoWindowTab("基本情報",html)
				];
			}else{
				var infoTabs = [
					new GInfoWindowTab("基本情報",html),
					new GInfoWindowTab("最新の釣果",choka_html)
				];
			}
			map.setCenter( point, 14 );
			anchors[id].openInfoWindowTabsHtml(infoTabs);
		}

	}
	request.send(null)
}

function mapPrefNavi(latlng){
	latlng = latlng.split(',');
	var point = new GLatLng(latlng[0],latlng[1]);
	tmpPosition = point;
	map.setCenter(point, 9);
	showMarker();

}


function addMarker(point, icon, idx) {
	var myicon = getIcon(icon);
	var options = {icon: myicon};
	var marker = new GMarker(point,options);

	if( idx != "" ) {
		GEvent.addListener(marker, "click", function() {
		tmpPosition = point;
		anchor_open(idx);
		});
	}
return marker;

}

function showMarker(){
var latlag = map.getCenter();
var lati = latlag.y;
var long = latlag.x;
map.clearOverlays();
var request2 = GXmlHttp.create();
request2.open("GET", "anchor.php?lat=" + lati + "&lon=" + long , true);
request2.onreadystatechange = function() {
if (request2.readyState == 4) {
	var xmlDoc = request2.responseXML;
	var places = xmlDoc.documentElement.getElementsByTagName("place");
	var str ='<table border="0" cellspacing="0" cellpadding="7" width="100%">';
	for( var i=0; i < places.length ; i++ ) {
		var latitude = parseFloat(places[i].getAttribute("latitude") );
		var longitude = parseFloat(places[i].getAttribute("longitude") );
		var point    = new GLatLng( latitude,longitude );
		if( places[i].getElementsByTagName("id").length != 0 )var id = places[i].getElementsByTagName("id")[0].firstChild.nodeValue;
		if( places[i].getElementsByTagName("icon").length != 0 )var icon = places[i].getElementsByTagName("icon")[0].firstChild.nodeValue;

		anchors[id] =  addMarker( point, icon, id );
		map.addOverlay(anchors[id]);


		if (places[i]) {
			var idx = places[i].getElementsByTagName("id")[0].firstChild.nodeValue;
			if(i%2!=1){
				str = str + '<tr align="left" valign="top" bgcolor="#eeeeee"><td>';
			}else{
				str = str + '<tr align="left" valign="top" bgcolor="#ffffff"><td>';
			}

			
			if(icon == "sea"){

				if( places[i].getElementsByTagName("pref").length != 0 ) {
					str += "<div class='list'><a href='http://www.fishing-v.jp/choka/sea.php?p=";
					str += places[i].getElementsByTagName("pref_cd")[0].firstChild.nodeValue;
					str += "'>";
					str += places[i].getElementsByTagName("pref")[0].firstChild.nodeValue;
					str += "</a>｜<a href='http://www.fishing-v.jp/choka/sea.php?a=";
					str += places[i].getElementsByTagName("area_cd")[0].firstChild.nodeValue;
					str += "'>";
					str += places[i].getElementsByTagName("area")[0].firstChild.nodeValue;
					str += "</a>｜<a href='http://www.fishing-v.jp/choka/sea.php?point=";
					str += places[i].getElementsByTagName("point_cd")[0].firstChild.nodeValue;
					str += "'>";
					str += places[i].getElementsByTagName("point")[0].firstChild.nodeValue;
					str += "</a></div>";
				}

				str = str + "<div class='shop_name_sea'><a href='#' onClick='anchor_open( " + idx + " );return false;'>";


			}


			if(icon == "bass"){

				if( places[i].getElementsByTagName("pref").length != 0 ) {
					str += "<div class='list'><a href='http://www.fishing-v.jp/choka/bass.php?p=";
					str += places[i].getElementsByTagName("pref_cd")[0].firstChild.nodeValue;
					str += "'>";
					str += places[i].getElementsByTagName("pref")[0].firstChild.nodeValue;
					str += "</a>｜<a href='http://www.fishing-v.jp/choka/bass.php?point=";
					str += places[i].getElementsByTagName("point_cd")[0].firstChild.nodeValue;
					str += "'>";
					str += places[i].getElementsByTagName("point")[0].firstChild.nodeValue;
					str += "</a></div>";
				}
				str = str + "<div class='shop_name_bass'><a href='#' onClick='anchor_open( " + idx + " );return false;'>";
			}

			if(icon == "freshwater"){


				if( places[i].getElementsByTagName("pref").length != 0 ) {
					str += "<div class='list'><a href='http://www.fishing-v.jp/choka/freshwater.php?p=";
					str += places[i].getElementsByTagName("pref_cd")[0].firstChild.nodeValue;
					str += "'>";
					str += places[i].getElementsByTagName("pref")[0].firstChild.nodeValue;
					str += "</a>｜<a href='http://www.fishing-v.jp/choka/freshwater.php?point=";
					str += places[i].getElementsByTagName("point_cd")[0].firstChild.nodeValue;
					str += "'>";
					str += places[i].getElementsByTagName("point")[0].firstChild.nodeValue;
					str += "</a></div>";
				}
				str = str + "<div class='shop_name_fresh'><a href='#' onClick='anchor_open( " + idx + " );return false;'>";					}

			if(icon == "shop"){

				if( places[i].getElementsByTagName("pref").length != 0 ) {
					str += "<div class='list'><a href='http://www.fishing-v.jp/data/shop/list.php?to_dou_fu_ken_s=";
					str += places[i].getElementsByTagName("pref_cd")[0].firstChild.nodeValue;
					str += "&submit=1'>";
					str += places[i].getElementsByTagName("pref")[0].firstChild.nodeValue;
					str += "</a></div>";
				}

				str = str + "<div class='shop_name_shop'><a href='#' onClick='anchor_open( " + idx + " );return false;'>";
			}

			if(icon == "kantsuri"){
				if( places[i].getElementsByTagName("pref").length != 0 ) {
					str += "<div class='list'><a href='http://www.fishing-v.jp/data/kantsuri/list.php?to_dou_fu_ken=";
					str += places[i].getElementsByTagName("pref_cd")[0].firstChild.nodeValue;
					str += "'>";
					str += places[i].getElementsByTagName("pref")[0].firstChild.nodeValue;
					str += "</a></div>";
				}

				str = str + "<div class='shop_name_kantsuri'><a href='#' onClick='anchor_open( " + idx + " );return false;'>";
			}
			
			if( places[i].getElementsByTagName("name").length != 0 ) {
			str = str + places[i].getElementsByTagName("name")[0].firstChild.nodeValue;}
			str = str + '</a></div><span class="navi">';
			if( places[i].getElementsByTagName("address").length != 0 ) {
				str += places[i].getElementsByTagName("address")[0].firstChild.nodeValue;
			}
			if( places[i].getElementsByTagName("tel").length != 0 ) {
				str +='<br />' + places[i].getElementsByTagName("tel")[0].firstChild.nodeValue;
			}
			str += '</span></td><td>';
			if( places[i].getElementsByTagName("photo").length != 0 ) {
				str += "<img src='";
				str += places[i].getElementsByTagName("photo")[0].firstChild.nodeValue;
				if(places[i].getElementsByTagName("size")[0].firstChild.nodeValue=="w"){
					str += "' width='50'>";
				}else{
					str += "' width='45'>";
				}
			}
			str += '</td></tr>';
		}

	}
	if(places.length!=0){
		str = str + '</table>';
	}else{
		str = "<table border='0' cellspacing='0' cellpadding='7' width='100%'><tr><td><div class='navi'>登録されている情報はありませんでした。地図をドラッグやダブルクリックして動かしてみてください。</div></td></tr></table>";
	}

	document.getElementById("recent").innerHTML = str;


}
}
request2.send(null);
}

function getIcon(icon) {
	if(icon == "sea"){
		var myicon = new GIcon();
		myicon.image = "img/fune_icon.png";
		myicon.shadow = "img/shadow_icon.png";
		myicon.iconSize = new GSize(17,23);
		myicon.shadowSize = new GSize(32,23);
		myicon.iconAnchor = new GPoint(9,23);
		myicon.infoWindowAnchor = new GPoint(10,10);
		myicon.transparent = "img/fune_icon.png";
	}

	if(icon == "bass"){
		var myicon = new GIcon();
		myicon.image = "img/bass_icon.png";
		myicon.shadow = "img/shadow_icon.png";
		myicon.iconSize = new GSize(17,23);
		myicon.shadowSize = new GSize(32,23);
		myicon.iconAnchor = new GPoint(9,23);
		myicon.infoWindowAnchor = new GPoint(10,10);
		myicon.transparent = "img/bass_icon.png";
	}

	if(icon == "freshwater"){
		var myicon = new GIcon();
		myicon.image = "img/fresh_icon.png";
		myicon.shadow = "img/shadow_icon.png";
		myicon.iconSize = new GSize(17,23);
		myicon.shadowSize = new GSize(32,23);
		myicon.iconAnchor = new GPoint(9,23);
		myicon.infoWindowAnchor = new GPoint(10,10);
		myicon.transparent = "img/fresh_icon.png";
	}

	if(icon == "shop"){
		var myicon = new GIcon();
		myicon.image = "img/shop_icon.png";
		myicon.shadow = "img/shadow_icon.png";
		myicon.iconSize = new GSize(17,23);
		myicon.shadowSize = new GSize(32,23);
		myicon.iconAnchor = new GPoint(9,23);
		myicon.infoWindowAnchor = new GPoint(10,10);
		myicon.transparent = "img/shop_icon.png";
	}

	if(icon == "kantsuri"){
		var myicon = new GIcon();
		myicon.image = "img/kanri_icon.png";
		myicon.shadow = "img/shadow_icon.png";
		myicon.iconSize = new GSize(17,23);
		myicon.shadowSize = new GSize(32,23);
		myicon.iconAnchor = new GPoint(9,23);
		myicon.infoWindowAnchor = new GPoint(10,10);
		myicon.transparent = "img/kanri_icon.png";
	}

	return myicon;
}
