
function MMToolWindow(title, pxWidth, pxHeight, showCross)
{	

	this.showCross = showCross;
	
	this.title = title;
	this.width = pxWidth;
	this.height = pxHeight;	
	this.position = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0,0));
	
	var current = new Date();
	this.elementId = current.getTime() + "_" + Math.random();

	this.div;
	this.content;
}
MMToolWindow.prototype = new GControl();

/**
 * Sets GControlPosition of the ToolWindow. 
 */
MMToolWindow.prototype.setPosition = function(position){this.position = position;}

/**
 * Returns to the map if the control should be printable. 
 */
MMToolWindow.prototype.printable = function(){
	return false;
}

/**
 * Returns to the map if the control contains selectable text. 
 */
MMToolWindow.prototype.selectable = function(){
	return false;
}

/**
 * Returns to the map the position in the map view at which the control appears by default. 
 * This will be overridden by the second argument to GMap2.addControl(). 
 */
MMToolWindow.prototype.getDefaultPosition = function(){
	return this.position;
}

MMToolWindow.prototype.cancelScrollEvent = function(e)
{
	if (!e) e = window.event;
	if (e.preventDefault) e.preventDefault();
	if (e.stopPropagation) e.stopPropagation();
	e.returnValue = false;
	e.stopped = true;
}

MMToolWindow.prototype.clearContent = function(e)
{

	this.div.removeChild(this.content);
	
	
	
	// reinit
	this.content = document.createElement("div");
	this.content.style.position = "relative";
	
	if(this.title)this.content.style.top = "20px";	
	else this.content.style.top = "17px";
	
	this.content.style.margin = "5px";
	this.content.style.height = this.height +"px";
	this.div.appendChild(this.content);
	this.initializeContent(this.content)
	
}


/**
 * Will be called by the map so the control can initialize itself. The control will 
 * use the method GMap2.getContainer() to get hold of the DOM element that contains 
 * the map, and add itself to it. It returns the added element. 
 */
MMToolWindow.prototype.initialize = function(map){
	
	// Main Div
	this.div = document.createElement("div");
	this.div.setAttribute("id",this.elementId);
	
	this.div.style.height = this.height +"px";
	this.div.style.width = this.width +"px";
	
	this.div.style.position = "relative";
	this.div.style.display = "none";
	
	this.div.style.background = "#FFFFFF";
	this.div.style.border="1px solid #000000";
	
	this.div.style.padding = "5px";
	this.div.style.margin = "0px";
	
	// Add Dockingwindow to the DOM	
	map.getContainer().appendChild(this.div);
	
	// Titel
	if(this.title)
	{
		var title = document.createElement("div");
		title.style.position="absolute";
		title.style.left = "10px";
		title.style.top = "8px";
		title.style.width = (this.width - 30) +"px";
		title.style.height = "12px";
		//title.style.font = "bold 13px arial sans-serif";
		title.style.fontFamily = "arial, sans-serif";
		title.style.fontWeight = "700";
		title.style.fontSize = "15px";
		title.innerHTML = this.title;
		this.div.appendChild(title);
	}
	
	//CloseButton	
	var close = document.createElement("div");
	close.style.position="absolute";
	close.style.right = "10px";
	close.style.top = "10px";
	close.style.width = "12px";
	close.style.height = "12px";	
	
	if(this.showCross)
	{
		close.style.cursor = "pointer";
		close.style.background='url("dateien/dockingWindow/closeCross.gif")';
		close.style.backgroundRepeat = "no-repeat";
	}
	this.div.appendChild(close);
	
	// Add Close Handler
	GEvent.bindDom(close, "click", this, this.hideWindow);

	
	//Content
	this.content = document.createElement("div");
	this.content.style.position = "relative";
	
	if(this.title)this.content.style.top = "20px";	
	else this.content.style.top = "17px";
	
	this.content.style.margin = "5px";
	this.content.style.height = this.height +"px";
	this.div.appendChild(this.content);
	this.initializeContent(this.content)
	
	//Buttons
	var buttons = document.createElement("div");
	this.div.appendChild(buttons);
	buttons.style.position = "absolute";
	buttons.style.bottom = "10px";	
	buttons.style.width="100%";
	buttons.style.textAlign="center";

	this.initializeButtons(buttons)
	
	
	// cancel Scroll Event
	this.div.onmousewheel = this.cancelScrollEvent; // IE
	GEvent.bindDom(this.div, "DOMMouseScroll", this, this.cancelScrollEvent);
	return this.div;
}

MMToolWindow.prototype.showWindow = function(){
	this.div.style.display = "block";
}

MMToolWindow.prototype.hideWindow = function(triggerEvent){	
	if(this.div)this.div.style.display = "none";
	if(triggerEvent !== false) GEvent.trigger(this, "close");
}

MMToolWindow.prototype.maxWindow = function(){
	h=this.div.parentNode.clientHeight-60;
	w=this.div.parentNode.clientWidth-100;
	this.div.style.height = h +"px";
	this.div.style.width = w +"px";
}

/**
 * Overwrite in subclass!
 */
MMToolWindow.prototype.initializeContent = function(div)
{
	return div;
}
MMToolWindow.prototype.initializeButtons = function(div)
{
	return div;
}
