function MapSizeController (map, sizes) {
	this.map   = map;
	this.sizes = sizes;
	sizes.zoomMax != null && this.map.setMaxZoom(sizes.zoomMax);
	sizes.zoomMin != null && this.map.setMinZoom(sizes.zoomMin);
	//this.map.
	for (var i in {Update:1, MoveEnd:1}) {
		YMaps.Events.observe(map, map.Events[i], this.checkBounds, this);
	}

	sizes.visible && this.drawBounds();
}
MapSizeController.prototype = {
	drawBounds: function() {
		var s = this.sizes, bounds = new YMaps.Polygon([
			new YMaps.GeoPoint(s.left , s.top),
			new YMaps.GeoPoint(s.right, s.top),
			new YMaps.GeoPoint(s.right, s.bottom),
			new YMaps.GeoPoint(s.left , s.bottom)
		]);

		var style = new YMaps.Style("default#greenPoint");
		style.polygonStyle = new YMaps.PolygonStyle();
		style.polygonStyle.fill = false;
		style.polygonStyle.outline = true;
		style.polygonStyle.strokeWidth = 4;
		style.polygonStyle.strokeColor = "cc006688";
		bounds.setStyle(style);

		this.map.addOverlay(bounds);
		return this;
	},
	checkBounds: function() {
		var bounds = this.map.getBounds(), s = this.sizes,
			widthHalf  = (bounds.getRight() - bounds.getLeft()) / 2,
			heightHalf = (bounds.getTop() - bounds.getBottom()) / 2,
			tmp, newX, newY, center = bounds.getCenter();
		if (s.left   != null && bounds.getLeft()   < s.left  ) newX = s.left + widthHalf;
		if (s.right  != null && bounds.getRight()  > s.right ) {
			tmp = s.right  - widthHalf;
			newX = (newX == null) ? tmp : ((tmp + newX) / 2);
		}
		if (s.top    != null && bounds.getTop()    > s.top   ) newY = s.top  - heightHalf;
		if (s.bottom != null && bounds.getBottom() < s.bottom) {
			tmp = s.bottom + heightHalf;
			newY = (newY == null) ? tmp : ((tmp + newY) / 2);
		}
		if (
			(newX != null && !newX.equals(center.getX(), 5))
				||
			(newY != null && !newY.equals(center.getY(), 5))
		) {
			this.map.panTo(new YMaps.GeoPoint(
				newX == null ? center.getX() : newX,
				newY == null ? center.getY() : newY
			));
		}
		return this;
	}
};


