function google_map(ido, keido, mode){
	this.mode = mode;
	this.ido = ido;
	this.keido = keido;
	this.markers = new Array();
	this.all_tabs = new Array();
	this.div = document.getElementById("map");

	this.map=new GMap2(this.div);
	this.geocoder = new GClientGeocoder();
	if (!this.ido && !this.keido){
		this.ido = 33.5525090;
		this.keido = 130.4364570;
		//alert("緯度経度データがありません");
	}
	this.init_point = new GLatLng(this.ido, this.keido);
	this.map.setCenter(this.init_point);
	this.map.setZoom(16);
	this.map.addControl(new GSmallMapControl());
	//this.map.addControl(new GLargeMapControl());
	if (document.getElementById("map_mode")) {
		if (document.getElementById("map_mode").innerHTML == 'search') {
			this.map.addControl(new GMapTypeControl());
		}
		//else alert(document.getElementById("map_mode").innerHTML);
	}
	//賃貸物件に使うアイコン
	this.icon = new GIcon();
	this.icon.image = "http://www.j-toushi.com/image/google_pin.png";
	this.icon.shadow = "http://www.j-toushi.com/image/google_pin_sh.png";
	this.icon.iconSize = new GSize(25, 34);
	this.icon.shadowSize = new GSize(45, 34);
	this.icon.iconAnchor = new GPoint(15, 36);
	this.icon.infoWindowAnchor = new GPoint(15, 0);
	//一時的にピンのアイコンをデフォルトに戻す
	//this.icon = G_DEFAULT_ICON;

	//不動産に使うアイコン
	this.icon2 = new GIcon();
	this.icon2.image = "http://www.j-toushi.com/image/google_pin.png";
	this.icon2.shadow = "http://www.j-toushi.com/image/google_pin_sh.png";
	this.icon2.iconSize = new GSize(25, 34);
	this.icon2.shadowSize = new GSize(45, 34);
	this.icon2.iconAnchor = new GPoint(15, 36);
	this.icon2.infoWindowAnchor = new GPoint(15, 0);
	//一時的にピンのアイコンをデフォルトに戻す
	//this.icon2 = G_DEFAULT_ICON;
	
	

	//売買物件に使うアイコン
	this.icon3 = new GIcon();
	this.icon3.image = "http://www.j-toushi.com/image/google_pin.png";
	this.icon3.shadow = "/images/pin_shade_bukken.png";
	this.icon3.iconSize = new GSize(25, 34);
	this.icon3.shadowSize = new GSize(45, 34);
	this.icon3.iconAnchor = new GPoint(15, 36);
	this.icon3.infoWindowAnchor = new GPoint(15, 0);
	//一時的にピンのアイコンをデフォルトに戻す
	//this.icon3 = G_DEFAULT_ICON;

	//マップを目的地までずらす関数
	this.center_map = function(center) {
		this.map.panTo(center);
		//alert("ok "+center.toString());
		if (this.mode == "edit") {
			this.markers[this.markers.length-1].setPoint(center);
		}
	};

	//登録時の「ズレ過ぎ」の計算に使用されるマップの中心を更新。
	this.set_hardcenter = function(center) {
		this.ido=center.lat();
		this.keido=center.lng();
	};

	this.autozoom = function() {
		//alert("welcome to autozoom");
		//bounds = new GBounds(this.markers);
		var bounds = new GLatLngBounds();
		for (var i = 0; i < this.markers.length; i+=1) {
			bounds.extend(this.markers[i].getPoint());
		}
		var sw = bounds.getSouthWest();
		var ne = bounds.getNorthEast();
		var y2 = ne.lat();
		var x2 = ne.lng();
		var y1 = sw.lat();
		var x1 = sw.lng();
		var percent = 20;
		x1 -= (x2 - x1)*percent/100;
		x2 += (x2 - x1)*percent/100;
		y1 -= (y2 - y1)*percent/100;
		y2 += (y2 - y1)*percent/100;
		bounds.extend(new GLatLng(y1,x1));
		bounds.extend(new GLatLng(y2,x2));
		bounds.extend(new GLatLng(y1,x2));
		bounds.extend(new GLatLng(y2,x1));
		//alert(sw.lat()+','+sw.lng()+' / '+ne.lat()+','+ne.lng()+' /// '+y1+','+x1+' / '+y2+','+x2);
		var zoom = this.map.getBoundsZoomLevel(bounds);
		var bounds_center = bounds.getCenter();
		//検索結果無し no results
		if (this.markers.length<1){
			//alert(this.markers.length);
			zoom = 11;
			bounds_center = new GLatLng(33.606578,130.417972);
		}
		//alert(zoom+" "+bounds.getCenter().toString());
		this.center_map(bounds_center);
		//this.add_marker(bounds_center);
		this.map.setZoom(zoom);
	};

	this.get_results_data = function() {
		if (document.getElementById("map_mode")) {
			this.map_mode=document.getElementById("map_mode").innerHTML;
		}
		if (document.getElementById("map_search")) {
			this.map_search=document.getElementById("map_search").innerHTML;
		}
		if (document.getElementById("map_ido")) {
			this.map_ido=document.getElementById("map_ido").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_ido.pop(); }
		}
		if (document.getElementById("map_keido")) {
			this.map_keido=document.getElementById("map_keido").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_keido.pop(); }
		}
		if (document.getElementById("map_name")) {
			this.map_name=document.getElementById("map_name").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_name.pop(); }
		}
		if (document.getElementById("map_jusho")) {
			this.map_jusho=document.getElementById("map_jusho").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_jusho.pop(); }
		}
		if (document.getElementById("map_madori")) {
			this.map_madori=document.getElementById("map_madori").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_madori.pop(); }
		}
		if (document.getElementById("map_chinryo")) {
			this.map_chinryo=document.getElementById("map_chinryo").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_chinryo.pop(); }
		}
		if (document.getElementById("map_kakaku")) {
			this.map_kakaku=document.getElementById("map_kakaku").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_kakaku.pop(); }
		}
		if (document.getElementById("map_id")) {
			this.map_id=document.getElementById("map_id").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_id.pop(); }
		}
		if (document.getElementById("map_chintaibaibai")) {
			this.map_chintaibaibai=document.getElementById("map_chintaibaibai").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_chintaibaibai.pop(); }
		}
		if (document.getElementById("map_fudosan_id")) {
			this.map_fudosan_id=document.getElementById("map_fudosan_id").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_fudosan_id.pop(); }
		}
		if (document.getElementById("map_fudosan_user")) {
			this.map_fudosan_user=document.getElementById("map_fudosan_user").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_fudosan_user.pop(); }
		}
		if (document.getElementById("map_fudosan_name")) {
			this.map_fudosan_name=document.getElementById("map_fudosan_name").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_fudosan_name.pop(); }
		}
		if (document.getElementById("map_fudosan_jusho")) {
			this.map_fudosan_jusho=document.getElementById("map_fudosan_jusho").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_fudosan_jusho.pop(); }
		}
		if (document.getElementById("map_fudosan_phone")) {
			this.map_fudosan_phone=document.getElementById("map_fudosan_phone").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_fudosan_phone.pop(); }
		}
		if (document.getElementById("map_fudosan_mail")) {
			this.map_fudosan_mail=document.getElementById("map_fudosan_mail").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_fudosan_mail.pop(); }
		}
		if (document.getElementById("map_pictures")) {
			this.map_pictures=document.getElementById("map_pictures").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_pictures.pop(); }
		}
		if (document.getElementById("map_logos")) {
			this.map_logos=document.getElementById("map_logos").innerHTML.split("|");
			if (this.map_mode == "search") { this.map_logos.pop(); }
		}
	};

	this.attach_click = function(pointer) {
		this.idokeido_listener = GEvent.addListener(this.map, "click", function(click_overlay, click_point) {
			if ( click_overlay !== null ) { return; }
			map1.center_map(click_point);
			var field_ido = document.getElementById("ido");
			if(field_ido) {
				field_ido.value = click_point.lat();
			}
			var field_keido = document.getElementById("keido");
			if(field_keido) {
				field_keido.value = click_point.lng();
			}
			if(map1.markers[map1.markers.length-1]) {
				var point_backup = new GLatLng(map1.ido,map1.keido);
				if (click_point.distanceFrom(point_backup)>1000) {
					//document.getElementById("idokeido_msg").innerHTML = "計算した緯度経度から１キロも外れるが、いいですか？";
					//alert(document.getElementById("idokeido_msg"));
					my_form.idokeido_msg.id.innerHTML = "計算した緯度経度から１キロも外れるが、いいですか？";
				} else { document.getElementById("idokeido_msg").innerHTML = ""; }
			}
		});
	};

	this.add_marker = function(point) {
		if (this.map_search == 'mixed') {
			if (this.markers.length === 0) {
				this.add_marker_fudosan(point);
			} else if (this.map_chintaibaibai[this.markers.length] == '売買') {
				this.add_marker_sale(point);
			} else {
				this.add_marker_rental(point);
			}
		}else if (this.map_search == 'fudosan') {
			this.add_marker_fudosan(point);
		}else if (this.map_mode == 'kakunin') {
			if (this.map_search == '賃貸') {
				this.add_marker_rental(point);
			}else if (this.map_search == '売買') {
				this.add_marker_sale(point);
			}else if (this.map_search == 'user') {
				this.add_marker_fudosan(point);
			}
		}else if (this.map_mode == 'home') {
			this.add_marker_fudosan(point);
		} else if (this.map_chintaibaibai) {
			//alert(this.map_id[this.markers.length]);
			if (this.map_chintaibaibai[this.markers.length] == '売買') {
				this.add_marker_sale(point);
			} else {
				this.add_marker_rental(point);
			}
		}else if (this.map_mode == 'edit') {
			if (this.map_search == 'user') {
				this.add_marker_fudosan(point);
			} else {
				this.add_marker_rental(point);
			}
		} else {
			this.add_marker_rental(point);
		}
	};

	this.add_marker_rental = function(point) {
		this.markers.push(new GMarker(point, this.icon));
		this.map.addOverlay(this.markers[this.markers.length-1]);
	};

	this.add_marker_sale = function(point) {
		this.markers.push(new GMarker(point, this.icon3));
		this.map.addOverlay(this.markers[this.markers.length-1]);
	};

	this.add_marker_fudosan = function(point) {
		this.markers.push(new GMarker(point, this.icon2));
		this.map.addOverlay(this.markers[this.markers.length-1]);
	};

	this.change_marker = function(rentalsale) {
		var latlng = this.markers[this.markers.length-1].getPoint();
		/*var old_rentalsale;
		if(this.markers[this.markers.length-1].getIcon().image.indexOf('rental')) {
			old_rentalsale = 'rental';
		} else {//if(this.markers[this.markers.length-1].getIcon().image.indexOf('sale')) {
			old_rentalsale = 'sale';
		}
		if(rentalsale != old_rentalsale){*/
			//alert("old_rentalsale="+old_rentalsale+" rentalsale="+rentalsale+" len="+this.markers.length)
			GEvent.removeListener(this.idokeido_listener);
			this.map.removeOverlay(this.markers[this.markers.length-1]);
			if(rentalsale=='sale') {
				this.add_marker_sale(latlng);
			} else {
				this.add_marker_rental(latlng);
			}
		//}
		if (this.map_mode == "edit") {
			map1.attach_click(map1.markers[this.markers.length-1], 0);
			var marker = map1.markers[this.markers.length-1];
		}
	};

	this.tabbed_info = function() {
		if (this.map_jusho.length != this.markers.length) {
			alert ("インフォウィンドーのデータは正しく読み込む事が出来ませんでした");
			return 1;
		}
		this.tabs = new Array();
		var i = 0;
		var logo_size;
		var bukken_info = "";
		var fudosan_info = "";
		if (this.map_search == 'fudosan') {
			for (i = 0; i < this.map_jusho.length; i+=1) {
				if (this.map_logos[i]) {
					logo_size = resize_image(pictures_url + this.map_logos[i], 80, 60);
				}
				fudosan_info  = "<div class=\"balloon\">";
				if (this.map_logos[i]) {
					fudosan_info += "<div class=\"balloon_img\"><img src=\"" + pictures_url + this.map_logos[i] + "\" alt=\"" + this.map_fudosan_name[i] + "ロゴ\" width=\"" + logo_size[0] + "\" height=\"" + logo_size[1] + "\" /></div>";
				}
				fudosan_info += "<div class=\"balloon_right\">";
				fudosan_info += "<h2>" + this.map_fudosan_name[i] + "</h2>";
				fudosan_info += "<h3>" + this.map_jusho[i] + "</h3>";
				fudosan_info += "<p class=\"balloon_tel\">TEL " + this.map_fudosan_phone[i] + "</p>";
				fudosan_info += "<p class=\"balloon_detail\"><a href=\"" + users_url + env_url + this.map_fudosan_user[i] + "\"><strong>会社の詳細</strong></a></p>";
				fudosan_info += "<p class=\"balloon_contact\"><a href=\"" + home_url + env_url + "contact/fudosan/" + this.map_id[i] + "\"><strong>お問合せ</strong></a></p>";
				fudosan_info += "<br class=\"close\" /></div><br class=\"close\" /></div>";
				this.tabs.push(fudosan_info);
				this.add_window(i);
			}
		} else if (this.map_search == 'mixed') {
			for (i = 0; i < 1; i+=1) {
				if (this.map_logos[i]) {
					logo_size = resize_image(pictures_url + this.map_logos[i], 80, 60);
				}
				fudosan_info  = "<div class=\"balloon\">";
				if (this.map_logos[i]) {
					fudosan_info += "<div class=\"balloon_img\"><img src=\"" + pictures_url + this.map_logos[i] + "\" alt=\"" + this.map_fudosan_name[i] + "ロゴ\" width=\"" + logo_size[0] + "\" height=\"" + logo_size[1] + "\" /></div>";
				}
				fudosan_info += "<div class=\"balloon_right\">";
				fudosan_info += "<h2>" + this.map_fudosan_name[i] + "</h2>";
				fudosan_info += "<h3>" + this.map_jusho[i] + "</h3>";
				fudosan_info += "<p class=\"balloon_tel\">TEL " + this.map_fudosan_phone[i] + "</p>";
				fudosan_info += "<p class=\"balloon_detail\"><a href=\"" + users_url + env_url + this.map_fudosan_user[i] + "\"><strong>会社の詳細</strong></a></p>";
				fudosan_info += "<p class=\"balloon_contact\"><a href=\"" + home_url + env_url + "contact/fudosan/" + this.map_id[i] + "\"><strong>お問合せ</strong></a></p>";
				fudosan_info += "<br class=\"close\" /></div><br class=\"close\" /></div>";
				this.tabs.push(fudosan_info);
				this.add_window(i);
			}
			for (i = 1; i < this.map_jusho.length; i+=1) {
				if (this.map_logos[i]) {
					logo_size = resize_image(pictures_url + this.map_logos[i], 80, 60);
				}
				bukken_info  = "<div class=\"balloon\">";
				if (this.map_pictures[i]) {
					bukken_info += "<div class=\"balloon_img\"><img src=\"" + thumbs_url + this.map_pictures[i] + "\" alt=\"" + this.map_name[i] + "\" width=\"80\" height=\"60\" /></div>";
				}
				bukken_info += "<div class=\"balloon_right\">";
				bukken_info += "<h2>" + this.map_name[i] + "</h2>";
				bukken_info += "<h3>" + this.map_jusho[i] + "</h3>";
				if (this.map_chintaibaibai[i]=="賃貸") {
					bukken_info += "<p class=\"balloon_tel\">間取り：" + this.map_madori[i] + "｜賃料：￥" + this.map_chinryo[i] + "</p>";
					bukken_info += "<p class=\"balloon_bukken_detail\"><a href=\"" + rental_url + env_url + this.map_id[i] + "\"><strong>物件の詳細</strong></a></p>";
				} else if (this.map_chintaibaibai[i]=="売買") {
					bukken_info += "<p class=\"balloon_tel\">間取り：" + this.map_madori[i] + "｜価格：" + this.map_kakaku[i] + "</p>";
					bukken_info += "<p class=\"balloon_bukken_detail\"><a href=\"" + sale_url + env_url + this.map_id[i] + "\"><strong>物件の詳細</strong></a></p>";
				}
				bukken_info += "<p class=\"balloon_contact\"><a href=\"" + home_url + env_url + "contact/bukken/" + this.map_id[i] + "\"><strong>お問合せ</strong></a></p>";
				bukken_info += "<br class=\"close\" /></div><br class=\"close\" /></div>";
				fudosan_info  = "<div class=\"balloon\">";
				if (this.map_logos[i]) {
					fudosan_info += "<div class=\"balloon_img\"><img src=\"" + pictures_url + this.map_logos[i] + "\" alt=\"" + this.map_fudosan_name[i] + "ロゴ\" width=\"" + logo_size[0] + "\" height=\"" + logo_size[1] + "\" /></div>";
				}
				fudosan_info += "<div class=\"balloon_right\">";
				fudosan_info += "<h2>" + this.map_fudosan_name[i] + "</h2>";
				fudosan_info += "<h3>" + this.map_jusho[i] + "</h3>";
				fudosan_info += "<p class=\"balloon_tel\">TEL " + this.map_fudosan_phone[i] + "</p>";
				fudosan_info += "<p class=\"balloon_detail\"><a href=\"" + users_url + env_url + this.map_fudosan_user[i] + "\"><strong>会社の詳細</strong></a></p>";
				fudosan_info += "<p class=\"balloon_contact\"><a href=\"" + home_url + env_url + "contact/fudosan/" + this.map_fudosan_id[i] + "\"><strong>お問合せ</strong></a></p>";
				fudosan_info += "<br class=\"close\" /></div><br class=\"close\" /></div>";
				this.tabs.push(new info_tabs("物件",	bukken_info, "不動産", fudosan_info ));
				this.add_tabs(i);
			}
		} else {
			for (i = 0; i < this.map_jusho.length; i+=1) {
				if (this.map_logos[i]) {
					logo_size = resize_image(pictures_url + this.map_logos[i], 80, 60);
				}
				bukken_info  = "<div class=\"balloon\">";
				if (this.map_pictures[i]) {
					bukken_info += "<div class=\"balloon_img\"><img src=\"" + thumbs_url + this.map_pictures[i] + "\" alt=\"" + this.map_name[i] + "\" width=\"80\" height=\"60\" /></div>";
				}
				bukken_info += "<div class=\"balloon_right\">";
				bukken_info += "<h2>" + this.map_name[i] + "</h2>";
				bukken_info += "<h3>" + this.map_jusho[i] + "</h3>";
				if (this.map_chintaibaibai[i]=="賃貸") {
					bukken_info += "<p class=\"balloon_tel\">間取り：" + this.map_madori[i] + "｜賃料：￥" + this.map_chinryo[i] + "</p>";
					bukken_info += "<p class=\"balloon_bukken_detail\"><a href=\"" + rental_url + env_url + this.map_id[i] + "\"><strong>物件の詳細</strong></a></p>";
				} else if (this.map_chintaibaibai[i]=="売買") {
					bukken_info += "<p class=\"balloon_tel\">間取り：" + this.map_madori[i] + "｜価格：" + this.map_kakaku[i] + "</p>";
					bukken_info += "<p class=\"balloon_bukken_detail\"><a href=\"" + sale_url + env_url + this.map_id[i] + "\"><strong>物件の詳細</strong></a></p>";
				}
				bukken_info += "<p class=\"balloon_contact\"><a href=\"" + home_url + env_url + "contact/bukken/" + this.map_id[i] + "\"><strong>お問合せ</strong></a></p>";
				bukken_info += "<br class=\"close\" /></div><br class=\"close\" /></div>";
				fudosan_info  = "<div class=\"balloon\">";
				if (this.map_logos[i]) {
					fudosan_info += "<div class=\"balloon_img\"><img src=\"" + pictures_url + this.map_logos[i] + "\" alt=\"" + this.map_fudosan_name[i] + "ロゴ\" width=\"" + logo_size[0] + "\" height=\"" + logo_size[1] + "\" /></div>";
				}
				fudosan_info += "<div class=\"balloon_right\">";
				fudosan_info += "<h2>" + this.map_fudosan_name[i] + "</h2>";
				fudosan_info += "<h3>" + this.map_fudosan_jusho[i] + "</h3>";
				fudosan_info += "<p class=\"balloon_tel\">TEL " + this.map_fudosan_phone[i] + "</p>";
				fudosan_info += "<p class=\"balloon_detail\"><a href=\"" + users_url + env_url + this.map_fudosan_user[i] + "\"><strong>会社の詳細</strong></a></p>";
				fudosan_info += "<p class=\"balloon_contact\"><a href=\"" + home_url + env_url + "contact/fudosan/" + this.map_fudosan_id[i] + "\"><strong>お問合せ</strong></a></p>";
				fudosan_info += "<br class=\"close\" /></div><br class=\"close\" /></div>";
				this.tabs.push(new info_tabs("物件",	bukken_info, "不動産", fudosan_info ));
				this.add_tabs(i);
			}
		}
	};

	this.add_tabs = function(index) {
		GEvent.addListener(this.markers[index], "click", function() {
			this.openInfoWindowTabsHtml(map1.tabs[index].tabs);
			for (i=0; i<results.length; i=i+1) {
				if (i != index){
					//results[i].className = 'results';
					results[i].className = 'clickable_list_item';
				}
			}
			//return this.className = 'results_selected';
			results[index].className = 'clickable_list_item_selected';
			return results[index].className;
		});
	};

	this.add_window = function(index) {
		GEvent.addListener(this.markers[index], "click", function() {
			this.openInfoWindowHtml(map1.tabs[index]);
			for (i=0; i<results.length; i=i+1) {
				if (i != index) {
					//results[i].className = 'results';
					results[i].className = 'clickable_list_item';
				}
			}
			//return this.className = 'results_selected';
			results[index].className = 'clickable_list_item_selected';
			return results[index].className;
		});
	};

	this.attach_click_to_result = function(element, counter) {
		element.style.cursor = 'pointer';
		//element.onmouseover = function(){ return this.className = 'results_over'; };
		//element.onmouseout = function(){ return this.className = 'results'; };
		element.onclick = function(counter){ 
			for (i=0; i<results.length; i=i+1) {
				if (i != counter) {
					//results[i].className = 'results';
					results[i].className = 'clickable_list_item';
				}
			}
			//return this.className = 'results_selected';
			this.className = 'clickable_list_item_selected';
			return this.className;
		};
		//element.className = 'results_selected';
		GEvent.addDomListener(element, "click", function() {
			//map1.center_map(map1.markers[counter].getPoint());
			if (map1.map_search == 'fudosan') {
				map1.markers[counter].openInfoWindowHtml(map1.tabs[counter]);
			} else if (map1.map_search == 'mixed') {
				if (counter === 0) {
					map1.markers[counter].openInfoWindowHtml(map1.tabs[counter]);
				} else {
					map1.markers[counter].openInfoWindowTabsHtml(map1.tabs[counter].tabs);
				}
			} else {
				map1.markers[counter].openInfoWindowTabsHtml(map1.tabs[counter].tabs);
			}
		});
	};

	return true;
}

function info_tabs(label1, body1, label2, body2){
	this.label1 = label1;
	this.label2 = label2;
	this.body1 = body1;
	this.body2 = body2;
	this.tab1 = new GInfoWindowTab(this.label1,this.body1);
	this.tab2 = new GInfoWindowTab(this.label2,this.body2);
	this.tabs = [ this.tab1, this.tab2 ];

	return true;
}
