
function InfoWindow(loc, minSz, maxSz) {

	this.minSize = minSz;
	this.maxSize = maxSz;

	this.windowElem = infoWindow;
	this.windowFrame = infoWindowBg;
	this.windowBar = infoWindowBar;
	this.textElem = infoText;
	//this.imageWindow = new ImageWindow();
	this.imageWindow = new ImageWindow("imgWindow");
	this.imageWindow2 = new ImageWindow("imgWindow2");
	this.arrowElem = infoArrow;
	this.arrowTextElem = infoArrowText;
	this.arrow = new InfoArrow();

	this.windowElem.style.width = minSz.width + "px";
	this.windowElem.style.height = minSz.height + "px";
	this.windowElem.style.top = loc.y + "px";
	this.windowElem.style.left = loc.x + "px";

	// 移動
	this.moveObj = new Move(this.windowElem);

	// ズーム
	this.zoomDir;
	this.delta = {x:14, y:14};
	this.interval = 20;
	this.intervalId;

	// ドラッグ
	var self = this;
	this.windowBar.onmousedown = function() { self.dragStart(); }
	this.mp = {x:0,y:0};
	this.cp = {x:0,y:0};

	this.actionHandler = null;
}

InfoWindow.prototype.setActionHandler = function(handler) {
	this.actionHandler = handler;
	this.moveObj.setActionHandler(handler);
	this.arrow.setActionHandler(handler);
}

InfoWindow.prototype.fireActionEvent = function() {
	if (this.actionHandler) {
		this.actionHandler();
	}
}

InfoWindow.prototype.show = function() {

	this.imageWindow.setLocation({x:8,y:63});
	this.imageWindow.setSize({width:56,height:67});
	this.windowElem.style.visibility = "visible";
	this.windowFrame.style.visibility = "visible";
}

InfoWindow.prototype.hide = function() {

	this.hideText();
	this.hideImage();
	this.hideArrow();
	this.windowElem.style.visibility = "hidden";
	this.windowFrame.style.visibility = "hidden";
}

InfoWindow.prototype.setSize = function(sz) {

	this.windowElem.style.width = sz.width + "px";
	this.windowElem.style.height = sz.height + "px";
	this.windowFrame.style.width = sz.width + "px";
	this.windowFrame.style.height = sz.height + "px";
	this.windowBar.style.width = sz.width + "px";
}

InfoWindow.prototype.setLocation = function(loc) {

	this.windowElem.style.top = loc.y + "px";
	this.windowElem.style.left = loc.x + "px";
}

InfoWindow.prototype.move = function(loc) {

	this.moveObj.to(loc.x, lox.y);
}

InfoWindow.prototype.moveTo = function(offset) {

	var x = parseInt(this.windowElem.style.left);
	var y = parseInt(this.windowElem.style.top);
	this.moveObj.to(x + offset.x, y + offset.y);
}

InfoWindow.prototype.shrink = function(dir) {

	this.hideText();
	this.hideImage();
	this.hideArrow();
	var self = this;
	this.intervalId = setInterval(function() { self.doShrink(self.zoomDir); }, this.interval);
}

InfoWindow.prototype.doShrink = function(dir) {

	if (HDOMElement.getWidth(this.windowElem) == this.minSize.width) {
		clearInterval(this.intervalId);
		this.fireActionEvent();
		return;
	}

	this.windowElem.style.visibility = "hidden";
	switch (dir) {
		case Zoom.TOP_LEFT:
			HDOMElement.addTop(this.windowElem, this.delta.y);
			HDOMElement.addLeft(this.windowElem, this.delta.x);
			break;
		case Zoom.TOP_RIGHT:
			HDOMElement.addTop(this.windowElem, this.delta.y);
			break;
		case Zoom.BOTTOM_LEFT:
			HDOMElement.addLeft(this.windowElem, this.delta.x);
			break;
		case Zoom.BOTTOM_RIGHT:
			break;
	}

	HDOMElement.subWidth(this.windowElem, this.delta.x);
	HDOMElement.subHeight(this.windowElem, this.delta.y);
	HDOMElement.subWidth(this.windowFrame, this.delta.x);
	HDOMElement.subHeight(this.windowFrame, this.delta.y);
	HDOMElement.subWidth(this.windowBar, this.delta.x);
	this.windowElem.style.visibility = "visible";
}

InfoWindow.prototype.spread = function(dir) {

	this.zoomDir = dir;
	var self = this;
	this.intervalId = setInterval(function() { self.doSpread(dir); }, this.interval);
}

InfoWindow.prototype.doSpread = function(dir) {

	if (HDOMElement.getWidth(this.windowElem) == this.maxSize.width) {
		clearInterval(this.intervalId);
		this.fireActionEvent();
		return;
	}

	this.windowElem.style.visibility = "hidden";
	switch (dir) {
		case Zoom.TOP_LEFT:
			HDOMElement.subTop(this.windowElem, this.delta.y);
			HDOMElement.subLeft(this.windowElem, this.delta.x);
			break;
		case Zoom.TOP_RIGHT:
			HDOMElement.subTop(this.windowElem, this.delta.y);
			break;
		case Zoom.BOTTOM_LEFT:
			HDOMElement.subLeft(this.windowElem, this.delta.x);
			break;
		case Zoom.BOTTOM_RIGHT:
			break;
	}

	HDOMElement.addWidth(this.windowElem, this.delta.x);
	HDOMElement.addHeight(this.windowElem, this.delta.y);
	HDOMElement.addWidth(this.windowFrame, this.delta.x);
	HDOMElement.addHeight(this.windowFrame, this.delta.y);
	HDOMElement.addWidth(this.windowBar, this.delta.x);
	this.windowElem.style.visibility = "visible";
}

InfoWindow.prototype.showText = function(html) {

	this.textElem.style.width = this.windowElem.style.width;
	this.textElem.style.height = this.windowElem.style.height;
	this.textElem.innerHTML = html;
	this.textElem.style.visibility = "visible";
}

InfoWindow.prototype.hideText = function() {

	this.textElem.style.visibility = "hidden";
}

InfoWindow.prototype.showImage = function(src) {
	this.imageWindow.show(src);
}

InfoWindow.prototype.hideImage = function() {
	this.imageWindow.hide();
	this.imageWindow2.hide();
}

InfoWindow.prototype.showArrow = function() {

	this.arrowElem.style.visibility = "visible";
	this.arrowTextElem.style.visibility = "visible";
}

InfoWindow.prototype.hideArrow = function() {
	this.arrowElem.style.visibility = "hidden";
	this.arrowTextElem.style.visibility = "hidden";
}

InfoWindow.prototype.setArrowAngle = function(angle) {
	this.arrow.setAngle(angle);
}

InfoWindow.prototype.rotateArrow = function(angle) {
	this.arrow.rotate(angle);
}

InfoWindow.prototype.setArrowLink = function(func, nextScene) {

	this.arrowElem.onclick = function() { func(nextScene); }
	this.arrowElem.style.cursor = "pointer";
}

InfoWindow.prototype.clearArrowLink = function(func, nextScene) {

	this.arrowElem.onclick = "";
	this.arrowElem.style.cursor = "";
}

InfoWindow.prototype.dragStart = function() {

	this.mp.x = parseInt(this.windowElem.style.left, 10);
	this.mp.y = parseInt(this.windowElem.style.top, 10);

	this.cp.x = event.clientX;
	this.cp.y = event.clientY;

	var self = this;
	this.windowBar.onmousemove = function() { self.doDrag(); }
	this.windowBar.onmouseup = function() { self.dragEnd(); }

	this.windowBar.setCapture();
}

InfoWindow.prototype.doDrag = function() {

	var top = this.mp.y - (this.cp.y - event.clientY);
	var left = this.mp.x - (this.cp.x - event.clientX);

/*
	status = " mp:(" + this.mp.x + "," + this.mp.y + ")"
		+ " client:(" + event.clientX + "," + event.clientY + ")"
		+ " (" + left + "," + top + ")";
*/
	status = "(" + left + "," + top + ")";

	this.windowElem.style.top = top;
	this.windowElem.style.left = left;
}

InfoWindow.prototype.dragEnd = function() {

	this.windowBar.onmousemove = "";
	this.windowBar.onmouseup = "";
	this.windowBar.releaseCapture();
}

