// InfoWindowクラス
homesInfoWindow = new Object

// 表示HTML
homesInfoWindow.html = "";

homesInfoWindow = function(map) {
	this.map = map;
	this.div = document.createElement("DIV");
	
	this.div.style.position = "absolute";
	this.div.style.visibility = "hidden";
	this.map.infodiv.appendChild(this.div);
	this.div.onclick = function() { // クリックしたときに動かないように。
		MEvent.EventMClickQueue["PmDf"] = 1; // このおまじないをすれば、ちゃんとテキスト選択できる。
	};
	this.div.onmousedown = function(e) {
		MEvent.EventMDownQueue["PmDf"] = 1; // このおまじないをすれば、ちゃんとテキスト選択できる。
	};

	
	
	this.id="closeIcon";
	this.div.style.visibility = "hidden";

	this.nosearch = false;
	
	this.openrpos = null;
	this.opentype = null;

 	if(typeof(EventDispatcher)=="undefined"){return;}
	EventDispatcher.implement(this);
}

homesInfoWindow.prototype.setHTML = function(html) {
	this.div.innerHTML = html;
}

homesInfoWindow.prototype.show = function(rpos, offsetx, offsety, type) {
	var pp = this.map.r2p( rpos , this.map.zid );
	var moveflag = false;
	if (typeof(offsetx) != "number") {
		offsetx = 0;
	}
	if (typeof(offsety) != "number") {
		offsety = 0;
	}
	this.div.style.left = (pp.x + offsetx) + "px";
	this.div.style.top  = (pp.y + offsety) + "px";
	this.div.style.visibility = "visible";
	
	var thisobject = this;

	var bounds = this.map.getBoundsLatLng();
	var move = this.map.getCenterLatLng();
	
	var minppos = this.map.r2p(new MPoint(bounds.minX, bounds.minY), this.map.zid);
	var maxppos = this.map.r2p(new MPoint(bounds.maxX, bounds.maxY), this.map.zid);
	var movepp = this.map.r2p(move, this.map.zid);
	if (rpos.x - bounds.minX < 0) {
		move.x += bounds.minX;
	}
	if (minppos.x > eval(pp.x + offsetx)) {
		movepp.x -= eval(pp.y - minppos.x - offsetx);
		moveflag = true;
	}
	if (maxppos.y > eval(pp.y + offsety)) {
		movepp.y -= eval(pp.y - maxppos.y - offsety);
		moveflag = true;
	}
	if (maxppos.x < eval(pp.x + offsetx + this.div.offsetWidth)) {
		movepp.x += eval(pp.x + offsetx + this.div.offsetWidth - maxppos.x);
		moveflag = true;
	}
	if (minppos.y < eval(pp.y + offsety + this.div.offsetHeight)) {
		movepp.y += eval(pp.y + offsety + this.div.offsetHeight - minppos.y);
		moveflag = true;
	}
	move = this.map.p2r(movepp, this.map.zid);
	if (moveflag) {
		this.map.recenterOrPanToLatLng(move);
		this.nosearch = true;
	}
	this.openrpos = rpos;
	this.opentype = type;
	this.dispatchEvent(new EventObject("open",thisobject));
}

homesInfoWindow.prototype.close = function(thisobject) {
	thisobject.div.style.visibility = "hidden";
	thisobject.openrpos = null;
	thisobject.opentype = null
	thisobject.dispatchEvent(new EventObject("close",thisobject));
}

homesInfoWindow.prototype.getSize = function() {
	var size = new Object();
	size.width = this.div.offsetWidth;
	size.height = this.div.offsetHeight;
	return size;
}

