/* Class TreeData, Class CyTree     */
/* for kunitachi index 2007/02/24   */
/* tamura                           */



/* 機能ごとに、カスタマイズ */
function ToiletData(){

	this.ReadAndParseXML = function(){
		var vURL = 'toilet.xml';
		new Ajax.Request(vURL, { method: 'get', onComplete: this.parseData});
	}
	this.parseData = function(httpObj){
		var xotree = new XML.ObjTree();
		xotree.force_array = [ "item" ];
		var tree;

		try {
			tree = xotree.parseXML( httpObj.responseText ); 
		} catch(e){
			alert('error');
		}
//alert(tree.doc.items.item.length);
		for(var i=0; i<tree.doc.items.item.length; i++){
			var vTree = tree.doc.items.item[i];
			var itemid = vTree["-spotid"];
			Toilet[itemid] = new CyToilet();
			Toilet[itemid].setData(vTree);
			Toilet[itemid].addMarker();
		}
	}
}

function CyToilet(){

	this.marker = null;
	this.setData = function(vTree){
		try {
			this.itemid = vTree["-spotid"];
			this.lat = vTree["-lat"];
			this.lng = vTree["-lng"];
			this.label = vTree.label;
		} catch(e){
		}
	}

	this.showData = function(){
		var obj;
		if ( this.itemid ){
			obj = this;
		} else {
			obj = this.parent;
		}

		$("hanami").style.display = 'none';
		$("data").style.display = 'block';
		$("data").innerHTML = $(obj.itemid).innerHTML;
	}

	this.addMarker = function(){

		var ticon = new GIcon();
		ticon.image = 'icons/toilet.png';
		ticon.shadow = 'icons/shadow.png';
		ticon.iconSize = new GSize(20,20);
		ticon.shadowSize = new GSize(1,1);
		ticon.iconAnchor = new GPoint(10,10);
		ticon.infoWindowAnchor = new GPoint(10,10);

		var title = this.label;
		this.marker = new GMarker(new GLatLng(this.lat,this.lng), { icon:ticon, title:title });
		this.marker.itemid = this.itemid;
		this.marker.parent = this;

		GEvent.addListener(this.marker, "click", this.showData);

		map.addOverlay(this.marker);
	}
}


