// Infowin class for displaying a miniature info window. Does not
// respond to any events - so you should show and remove the
// overlay yourself as necessary.

function Infowin(marker, html) {
	this.latlng_ = new GLatLng(marker.getPoint().lat(), marker.getPoint().lng());
	this.html_ = html;
	this.prototype = new GOverlay();

	// Creates the DIV representing the infowindow
	this.initialize = function(map) {
		var div = $('<div />');
		div.css( {
			position : 'absolute',
			width : 234
		}).appendTo(map.getPane(G_MAP_FLOAT_PANE))

		this.map_ = map;
		this.div_ = div;

		this.update(html);
	};

	this.update = function(html) {
		this.html_ = html;

		this.div_.empty();
		
		var parent = $('<div />').addClass('info-window-shadow').css({
			width: 320,
	    	height: 180,
			padding: '0 0 0 0'
		}).appendTo(this.div_);
		
		parent.html('<div class="closeDiv"><a href="javascript:void(0);" class="close"><img src="scripts/maps/close.gif" alt="close" /></a></div>');
		
		var content = $('<div/>').addClass('gMapContent').css({
			'position' : 'relative',
			'overflow' : 'hidden'
		}).html(html);
		
		// add content to the parent div
		content.appendTo(parent);
		
		$('a.close').click(function(){
			closeOverlay();
		});
		
		this.redraw(true);
	};

	// Remove the main DIV from the map pane
	this.remove = function() {
		this.div_.remove();
	};

	// Copy our data to a new instance
	this.copy = function() {
		return new Infowin(this.latlng_, this.html_);
	};

	// Redraw based on the current projection and zoom level
	this.redraw = function(force) {
		if (!force)
			return;

		var point = this.map_.fromLatLngToDivPixel(this.latlng_);

		// Now position our DIV based on the DIV coordinates of our bounds
		this.div_.css( {
			left : point.x - 160,
			top : point.y - this.div_.height() - 40
		});
		
		
		var G = this.map_.fromDivPixelToLatLng(new GPoint(point.x, point.y - (this.div_.height() / 2) - 20));
		this.map_.panTo(G);
	};
}