
//	ビル情報処理クラス
var BuildSet = Class.create(GMap, {
	//	地図にビル情報を追加
	addAll : function(data) {
		if(typeof(data)=='undefined')
			throw Error('No building data is specified.');
	//	this.setMarkerImage("/img/build.gif",16, 22);
	//	this.setMarkerImage("/img/build_b.gif",16, 22);
	//	this.switchIcon(0);
		for(var i in data) {
			var info = data[i];
			if(typeof(info)!='object')
				continue;
			if((info.Latitude==0) || (info.Longitude==0))
				continue;
			var text = this.getMarkerText(info);
		
			//	マーカー画像を変更
			if(parseInt(info.EventHall)==1)
				this.switchIcon(1);
			else
				this.switchIcon(0);
			var mrk = this.addMarkerData(info, info.Latitude, info.Longitude, info.BuildingName, text);
		}
	},
	//	マーカーに設定するテキストを生成
	getMarkerText: function(info) {
		var url = '/building/detail/'+info.KuURL+'/'+info.BuildingURL+'/';
		var text = '<div class="baloon">';
		if(info.BuildingName)
			text += '<div class="baloon_build_name"><a href="'+url+'" target="_blank">'+info.BuildingName+'</a></div><br />';
		if(info.CatchCopy)
		{
			var copy = info.CatchCopy.replace('◆','<br \>\r\n');

			text += '<div class="baloon_copy">'+copy+'</div><br />';
		}
		text += '<div class="baloon_link"><a href="'+url+'" title="'+info.BuildingName+'" target="_blank">詳しくはこちら</a></div><br />';
		text += '</div>';
		return text;
	},
	//	地図のマーカーをフィルタ(条件はand)
	filterData : function(params,option) {
		if(typeof(this.markers)=='undefined')
			throw Error('No building data is specified.');
		if(typeof(params)=='undefined')
			throw Error('parameter params should not be omitted.');
		for(var build in this.markers){
			var builddata = this.markers[build];
			if(typeof(builddata.marker)!='object')
				continue;
			var show = false;
			for(var key in  params)	{
				var cond = parseInt(params[key]);
				if(cond=='undefined')
					throw Error('Filter value is not Numerical.');
				if(cond!=1)
					continue;
				//	一つでも条件に合わなかったら非表示にする
				if((parseInt(builddata[key]) & cond) != 1)
				{
					show = false;
					break;
				}
				show = true;
			}
			if(show)
				builddata.marker.show();
			else
				builddata.marker.hide();
		}
	},
	//	地図上のマーカーを全て表示
	showAll : function() {
		for(var build in this.markers){
			var builddata = this.markers[build];
			if(typeof(builddata.marker)!='object')
				continue;
			builddata.marker.show();
		}
	}
});

