// JavaScript Document
var fs=new Array();

var map="";

function farmstand(str){

	this.id;
	this.fd;
	this.htmlTab1;
	this.htmlTab2;
	this.infotab;
	this.markerIcon;
	this.opt;
	this.marker;

	this.fd=str.split("\t");
	this.id=this.fd[0];

	this.htmlTab1="<div class=\"gmap-baloon\"><h2>"+this.fd[6]+"</h2>";
	this.htmlTab1+= (this.fd[11]=="") ? "" : "<img src=\"img/"+this.fd[11]+"\" alt=\""+this.fd[6]+"\" />" ;
	this.htmlTab1+= "<table>";
	this.htmlTab1+= (this.fd[5]=="") ? "" : "<tr><th>JA</th><td>"+this.fd[5]+"</td></tr>" ;
	this.htmlTab1+= (this.fd[7]=="") ? "" : "<tr><th>住所</th><td>"+this.fd[8]+"</td></tr>" ;
	this.htmlTab1+= (this.fd[8]=="") ? "" : "<tr><th>TEL</th><td>"+this.fd[9]+"</td></tr>" ;
	this.htmlTab1+= (this.fd[6]=="") ? "" : "<tr><th>品目等</th><td>"+this.fd[7]+"</td></tr>" ;
	this.htmlTab1+="<table></div>";
	this.htmlTab2="";
	this.htmlTab2+= (this.fd[10]=="") ? "" : "<div class=\"gmap-baloon\"><img src=\"img/"+this.fd[10]+"\" alt=\""+this.fd[3]+"\" />" ;
	this.htmlTab2+= (this.htmlTab2=="") ? "" : "</div>";

	this.infotab=new Array();
	this.infotab.push(new GInfoWindowTab("基本情報",this.htmlTab1));
	if(this.htmlTab2!=""){
		this.infotab.push(new GInfoWindowTab("イラスト地図",this.htmlTab2));
	}

	this.markerIcon = new GIcon();
	this.markerIcon.image = "img/store.png";
	switch(this.fd[4]){
		case "西多摩":
			this.markerIcon.image = "img/fs01.png";
			break;
		case "南多摩":
			this.markerIcon.image = "img/fs02.png";
			break;
		case "北多摩":
			this.markerIcon.image = "img/fs03.png";
			break;
		case "区内":
			this.markerIcon.image = "img/fs04.png";
			break;
		case "島しょ":
			this.markerIcon.image = "img/fs05.png";
			break;
		case "その他":
			this.markerIcon.image = "img/fs06.png";
			break;
		default:
			this.markerIcon.image = "img/fs01.png";
			break;
	}
	this.markerIcon.iconSize = new GSize(27, 27);
	this.markerIcon.iconAnchor = new GPoint(14, 27);
	this.markerIcon.infoWindowAnchor = new GPoint(14, 0)

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

	this.marker = new GMarker(new GPoint(this.fd[2],this.fd[1]),this.opt);
	this.marker.infotab = this.infotab;
	this.marker.infohtml = this.fd[6];
	map.addOverlay(this.marker);
	GEvent.addListener(this.marker, 'click', function(){
		this.openInfoWindowTabsHtml(this.infotab);
		$("alt-window").style.display="none";
		Element.update($("alt-window"),""); 
	});
	GEvent.addListener(this.marker, 'mouseover', function(){
		$("alt-window").style.display="block";
		Element.update($("alt-window"),this.infohtml); 
	});
	GEvent.addListener(this.marker, "mouseout", function() {
		$("alt-window").style.display="none";
		Element.update($("alt-window"),""); 
	});
}





window.onload = function(e) {
	if(document.getElementById("gmap")!=null){
		var lat=35.71;
		var lng=139.55;
		map = new GMap2(document.getElementById("gmap"),{size:new GSize(520,600)});
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl());

		var center = new GLatLng(lat, lng);
		map.setCenter(center, 10);
		map.enableScrollWheelZoom();
		for(var i=0;i<fsDL.length;i++){
			fs.push(new farmstand(fsDL[i]));
		}
	}
	$("farmstand-area02").style.display="none";
	$("farmstand-area03").style.display="none";
	$("farmstand-area04").style.display="none";
	$("farmstand-area05").style.display="none";
	$("farmstand-area06").style.display="none";
	Event.observe(window.document, "mousemove", movealt, false);
}


function movealt(e){
	Element.setStyle($("alt-window"),{
		'left':Event.pointerX(e)+20+'px',
		'top':Event.pointerY(e)-20+'px'
	});
}

function listBtnClick(id){
	for(var i=0;i<fs.length;i++){
		if(fs[i].id==id){
			fs[i].marker.openInfoWindowTabsHtml(fs[i].infotab);
			map.setZoom(10);
		}
	}
}
function tabBtnClick(id){
	for(var i=1;i<7;i++){
		if(i==id){
			$("farmstand-area0"+i).style.display="block";
		}else{
			$("farmstand-area0"+i).style.display="none";
		}
	}
	switch(id){
		case 1:
			map.setCenter(new GLatLng(35.760,139.283), 11);
			break;
		case 2:
			map.setCenter(new GLatLng(35.605,139.359), 11);
			break;
		case 3:
			map.setCenter(new GLatLng(35.709,139.467), 11);
			break;
		case 4:
			map.setCenter(new GLatLng(35.703,139.733), 10);
			break;
		case 5:
			map.setCenter(new GLatLng(30.942,140.724), 6);
			break;
		case 6:
			map.setCenter(new GLatLng(35.696,139.375), 11);
			break;
		default:
	}
}