// JScript File
//  LT infowindow

function InfoWindowHT(map, pt, html, offset, addr){
   
	this.map = map;
	
	this.position = new Point(0, 0);
	
	this.offset = 0;
	this.offsetx = 0;
	this.offsety = 0;
	
	var sz = measureHTML2(html);
	if (sz.width < 200) sz.width = 200;
	sz.width += 10; sz.height += 10;
	this.createImageDiv(sz.width + 15, sz.height + 30);
    
	this.arrowDiv = document.createElement('div');
	var clas = document.createAttribute('class');
	clas.nodeValue = 'arrow';
	this.arrowDiv.setAttributeNode(clas);
	this.topDiv = document.createElement('div');
	clas = document.createAttribute('class');
	clas.nodeValue = 'bubbleTop';
	this.topDiv.setAttributeNode(clas);

	this.htmlDiv = document.createElement('div');
	clas = document.createAttribute('class');
	clas.nodeValue = 'bubbleContainer';
	this.htmlDiv.setAttributeNode(clas);
//	this.htmlDiv = ElementCreator.createChildDiv(this.Needle.width + 10, this.Needle.height+10, sz.width, sz.height, null, "Arial", '12px');

	this.bottomDiv = document.createElement('div');
	clas = document.createAttribute('class');
	clas.nodeValue = 'bubbleBottom';
	this.bottomDiv.setAttributeNode(clas);
	
	this.image.appendChild(this.arrowDiv);
	this.image.appendChild(this.topDiv);
	this.image.appendChild(this.htmlDiv);
	this.image.appendChild(this.bottomDiv);
	
	this.div = document.createElement("div");
	
	this.div.style.position = "absolute";
	this.div.style.top = "0px";
	this.div.style.left = "0px";
	this.div.style.zIndex = 1000;
	this.div.owner = this;;
	this.div.setPosition = function(pt){
		this.owner.setPosition(pt);
	}
	this.div.appendChild(this.image);	
	this.div.onmousedown = this.onMouseDown;
	
	this.setInfo(pt, html, offset, addr);
	this.innerSize = measureHTML2(html);
	this.LT = new Size(parseInt(this.image.childNodes[0].style.left) + parseInt(this.image.childNodes[0].style.width), parseInt(this.image.childNodes[1].style.top));
	this.arrowL = 0;
	this.routerPos = new Size(this.Needle.width + 10, this.IWinSize.height - 25);
	this.color = null;
}

InfoWindowHT.prototype.createImageDiv = function(width, height){
	this.image = document.createElement('DIV');
	clas = document.createAttribute('class');
	clas.nodeValue = 'bubbleOuter';
	this.image.setAttributeNode(clas);
	
	this.image.style.cssText = 'position:absolute;';
	this.image.owner = this;
	this.image.setPosition = function(pt){
		this.owner.setImagePosition(pt);
	}
	var w1 = 25;
	var h1 = 20;
	this.Needle = new Size(w1, h1);
//	this.image.appendChild(ElementCreator.createImage(0, 0, redirected_path('map/images/InfoWinTransparent/needleTL.png'), w1, h1, 0, true,true));
//	this.image.appendChild(ElementCreator.createImage(w1, 0, redirected_path('map/images/InfoWinTransparent/header_gray.png'), width, h1, 0, true,true));
//	this.image.appendChild(ElementCreator.createImage(w1, h1, redirected_path('map/images/InfoWinTransparent/background_white.png'), width, height, 0,true,true));
	
	var infoWindowSize = new Size(0,0);
	infoWindowSize.width = w1 + width;
	infoWindowSize.height = h1 + height;	
	this.IWinSize = infoWindowSize;
	
}


InfoWindowHT.prototype.setImagePosition = function(){
	if (this.offset < 0){
		this.top += this.offset;
	}
	this.image.style.top = this.offset + 'px';
}


InfoWindowHT.prototype.setPosition = function(pt){
	var x = pt.x;
	var y = pt.y;
	this.left = x + 2;
	this.top = y - 2;
	this.right = x + 446;//IWinSize.width + 5;
	this.bottom = y + this.IWinSize.height + 5;
	if (this.offset < 0){
		this.top += this.offset;
	}
	this.div.style.left = x - 8 + 'px';
	this.div.style.top = y - 16 + 'px';
	this.setImagePosition();
}

InfoWindowHT.prototype.appendChild = function(obj){
	this.image.appendChild(obj);
}

InfoWindowHT.prototype.removeChild = function(obj){
	this.image.removeChild(obj);
}

//Fixed height in firefox
function measureHTML2(BU){var Aq=document.createElement("DIV");Aq.style.cssText="position:absolute; left:-3000px; display:block;";Aq.innerHTML=BU;document.body.appendChild(Aq);if(Aq.childNodes[0]!=null&&Aq.childNodes[0].nodeName=="DIV"){var Db=new Size(Aq.childNodes[0].offsetWidth,Aq.childNodes[0].offsetHeight);document.body.removeChild(Aq);return Db;}var Db=new Size(Aq.offsetWidth,Aq.offsetHeight);document.body.removeChild(Aq);return Db;}

InfoWindowHT.prototype.setInfo = function(wp, html, offset, addr){
	this.position = wp;
	this.addr = addr;
	var htmlSize = measureHTML2(html);
    this.htmlDiv.innerHTML = html;
	if (offset != null){
		this.offset = -offset;
		this.offsetx = 0; 
		this.offsety = this.offset; 
	}
}

InfoWindowHT.prototype.onMouseDown=function(b){
	if(b){
		b.cancelDrag=true
	}
	cancelBubbling(b)
}

InfoWindowHT.prototype.isClicked = function(){
	return false;
}

