﻿geodata.maptips.MapTipWindow = function() {
	this.hoverDivId = "MapTipHoverContainerDiv";
	this.hoverContentId = "MapTipHoverContentCell"
	this.currentItem = null;

	this.createDivs = function() {
 	    var s = '<div onmouseout="return gdMapTipHoverInfoMouseOut(event);" id="' + this.hoverDivId + '" class="GDMapTipBodyStyle">';
		s +=  '      <div class="GDMapTipContentsStyle"  id="' + this.hoverContentId + '" >';
		//	    Content Content Content Content Content  
		s +=  '      </div>';
	    s +=  '</div>';
        this.addDiv("MapTipPanelHolder", s, 0, 0, 1, 1, "visible", "background-color: transparent; position: absolute;")
	}
	
	this.setPosition = function (maptipItem) {
        var mp = geodata.maptips.currentMapTipsLayer.map;
        var mapx = (mp.position ? mp.position.x : mp._pos.x); // 1.2 / 1.3 version of JSAPI
        var mapy = (mp.position ? mp.position.y : mp._pos.y); // 1.2 / 1.3 version of JSAPI
        if(maptipItem.selected)
        {
            // Selected maptip may have been cached on client, so screen coordinates produced serverside are not necessarily correct.
            var s = mp.toScreen(new esri.geometry.Point(maptipItem.X, maptipItem.Y, null));
            maptipItem.screenX = s.x;
            maptipItem.screenY = s.y;
        }
		var x = mapx + maptipItem.screenX;
		var y = mapy + maptipItem.screenY;
        var right = mapx + mp.width - 5;
        var bottom = mapy + mp.height - 5;
        if(x + maptipItem.contentWidth > right)
            x = right - maptipItem.contentWidth;
        if(y + maptipItem.contentHeight > bottom)
            y = bottom - maptipItem.contentHeight;
        dojo.style(this.hoverDivId, "left", x + "px");
        dojo.style(this.hoverDivId, "top", y + "px");
	}
	
	this.show = function(item) {
		this.currentItem = item;
		if (this.currentItem != null) {
    		dojo.byId(this.hoverContentId).innerHTML = item.htmlContent;
	        this.setPosition(this.currentItem);
	        dojo.style(this.hoverDivId, "visibility", "visible");
	        geodata.maptips.hoverVisible = true;
    		if(item.contentByCategory && item.contentByCategory.length > 0)
    		    mapHoverFunctions.multiCatMouseOver(0, item.index);
		}
	}
	
	this.hide = function() {
	    var item = this.currentItem;
	    this.currentItem = null;
        dojo.style(this.hoverDivId, "visibility", "hidden");
		geodata.maptips.hoverVisible = false;
		return item;
	}

    this.addDiv = function(id, content, left, top, width, height, visible, style) {
        var oDiv = document.createElement("div");
        oDiv.id = id;
        if (left!=null) oDiv.style.left = left + "px";
        if (top!=null) oDiv.style.top = top + "px";
        if (width!=null) oDiv.style.width = width + "px";
        if (height!=null) oDiv.style.height = height + "px";
        if (style!=null) oDiv.style.cssText += "; " + style;
        if (oDiv.style.position==null) oDiv.style.position = "absolute";	
        oDiv.innerHTML = content;
        document.body.appendChild(oDiv);
        if (visible!=null) oDiv.style.visibility = visible;	
    }
	
}
// MapTipWindow
