﻿function InfoBox()     // InfoBox Class定义
{
    //this.boxHTML = "";
	this.infoHTML ="";
	this.objBox = null;
	this.id = "";
	this.contentId = "";
	this.onComplete = null;
	this.boxWidth = 0;
    this.boxHeight = 0;
	if(typeof InfoBox.initialized == "undefined")
	{
	    InfoBox.imgCornerWidth = 12;
        InfoBox.imgCornerHeight = 15;
        InfoBox.imgArrowWidth = 86;
        InfoBox.imgArrowHeight = 59;
        InfoBox.imgShadowWidth = 9;
        InfoBox.imgLeftTopCornerURL = "images/infoBox/leftTopCorner.gif";
        InfoBox.imgTopBorderURL = "images/infoBox/topBorder.gif";
        InfoBox.imgRightTopCornerURL = "images/infoBox/rightTopCorner.png";
        InfoBox.imgLeftBorderURL = "images/infoBox/leftBorder.gif";
        InfoBox.imgCenterURL = "images/infoBox/center.gif";
        InfoBox.imgRightBorderURL = "images/infoBox/rightBorder.png";
        InfoBox.imgLeftBottomURL = "images/infoBox/leftBottomCorner.png";
        InfoBox.imgBottomBorderURL = "images/infoBox/bottomBorder.png";
        InfoBox.imgRightBottomURL = "images/infoBox/rightBottomCorner.png";
        InfoBox.imgPointorURL = "images/infoBox/pointor.png";
        InfoBox.imgCloseURL = "images/infoBox/infoBoxClose.gif";
        
		InfoBox.prototype.init = function(id,width,height,contentHtml,onComplete)
		{
		
		
		    if(arguments.length<1)
		    {
		        id="myInfoBox";
                width = 231;
                height = 149;
                contentHtml ="";
                
		    }
		    this.id ="myInfoBox_" + id;
		    this.contentId = id+"Content";
		    this.boxWidth = InfoBox.imgCornerWidth + width;
		    this.boxHeight = InfoBox.imgCornerHeight + height + InfoBox.imgArrowHeight -InfoBox.imgShadowWidth -2;
		    this.onComplete = onComplete; 
		    this.objBox = document.createElement("div");
		
		    var sbBoxHTML = new StringBuffer("<div id='i"+id+"' style='padding-top:5px;position:relative;width:"+(this.boxWidth)+"px;height:"+(height+InfoBox.imgCornerHeight+InfoBox.imgArrowHeight)+"px;z-index:1005;'>");// box
            sbBoxHTML.append("<div id='toppart' style='position:absolute;left:0px;top:0px;width:"+(this.boxWidth)+"px;height:"+(height+InfoBox.imgCornerHeight)+"px;z-index:2;'>");   // top part container 
            // top part，line1
            sbBoxHTML.append("<div style='position:absolute;left:0px;top:0px;width:"+InfoBox.imgCornerWidth+"px;height:"+InfoBox.imgCornerHeight+"px;background-image:url("+InfoBox.imgLeftTopCornerURL+");background-repeat:no-repeat;'></div>"); // leftTop
            sbBoxHTML.append("<div style='position:absolute;left:"+InfoBox.imgCornerWidth+"px;top:0px;width:"+(width-InfoBox.imgCornerWidth)+"px;height:"+InfoBox.imgCornerHeight+"px;background-image:url("+InfoBox.imgTopBorderURL+");background-repeat:repeat-x;'></div>"); // topCenter
            sbBoxHTML.append("<div style=\"position:absolute;right:0px;top:0px;width:"+InfoBox.imgCornerWidth+"px;height:"+InfoBox.imgCornerHeight+"px;background-repeat:no-repeat;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+InfoBox.imgRightTopCornerURL+"',sizingMethod='scale');\"></div>"); // rightTop
            // middle part， line2
            sbBoxHTML.append("<div style='position:absolute;top:"+InfoBox.imgCornerHeight+"px;left:0px;width:"+InfoBox.imgCornerWidth+"px;height:"+(height-InfoBox.imgCornerHeight-5)+"px;background:url("+InfoBox.imgLeftBorderURL+");background-repeat:repeat-y;'></div>");// leftBorder
            sbBoxHTML.append("<div style='position:absolute;left:"+InfoBox.imgCornerWidth+"px;top:"+InfoBox.imgCornerHeight+"px;width:"+(width-InfoBox.imgCornerWidth)+"px;height:"+(height-InfoBox.imgCornerHeight)+"px;background-image:url("+InfoBox.imgCenterURL+");background-repeat:repeat;'></div>");// center
            sbBoxHTML.append("<div style=\"position:absolute;top:"+InfoBox.imgCornerHeight+"px;right:0px;width:"+InfoBox.imgCornerWidth+"px;height:"+(height-InfoBox.imgCornerHeight)+"px;background-repeat:repeat-y;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+InfoBox.imgRightBorderURL+"',sizingMethod='scale');\"></div>"); // rightBorder
            // bottom part，line3
            sbBoxHTML.append("<div style=\"position:absolute;left:0px;bottom:0px;width:"+InfoBox.imgCornerWidth+"px;height:"+InfoBox.imgCornerHeight+"px;background-repeat:no-repeat;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+InfoBox.imgLeftBottomURL+"',sizingMethod='scale');\"></div>"); // leftbottom
            sbBoxHTML.append("<div style=\"position:absolute;left:"+InfoBox.imgCornerWidth+"px;bottom:0px;width:"+(width-InfoBox.imgCornerWidth)+"px;height:"+InfoBox.imgCornerHeight+"px;background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+InfoBox.imgBottomBorderURL+"',sizingMethod='scale');\"></div>");// bottomBorder
            sbBoxHTML.append("<div style=\"position:absolute;right:0px;bottom:0px;width:"+InfoBox.imgCornerWidth+"px;height:"+InfoBox.imgCornerHeight+"px;background-repeat:no-repeat;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+InfoBox.imgRightBottomURL+"',sizingMethod='scale');\"></div></div>");
            // close
            sbBoxHTML.append("<a href='javascript:void(0)' style='position:absolute;top:5px;right:13px;width:12px;height:12px;z-index:10;background:none url("+InfoBox.imgCloseURL+") no-repeat;'onclick=\"var pn=document.getElementById('"+this.id+"');pn.parentNode.removeChild(pn);\"></a>"); // close  InfoBox.prototype.close();
             // main Content
		    if(arguments.length>0)
            {
                sbBoxHTML.append("<div id='"+this.contentId+"' style='position:relative;left:"+(parseInt(InfoBox.imgCornerWidth/2))+"px;top:"+(parseInt(InfoBox.imgCornerHeight/2 - 4))+"px;width:"+(width-InfoBox.imgShadowWidth)+"px;height:"+(height-InfoBox.imgShadowWidth)+"px;z-index:4'>" + contentHtml +"</div>");
            }
            else
            {
                sbBoxHTML.append("<div id='"+this.contentId+"' style='position:relative;left:"+(parseInt(InfoBox.imgCornerWidth/2))+"px;top:"+(parseInt(InfoBox.imgCornerHeight/2 - 4))+"px;width:"+(width-InfoBox.imgShadowWidth)+"px;height:"+(height-InfoBox.imgShadowWidth)+"px;z-index:4'></div>");
            }
            // arrow
            sbBoxHTML.append("<div id='bottomArrow' style=\"position:absolute;left:"+parseInt((this.boxWidth)/2)+"px;top:"+(height+InfoBox.imgCornerHeight-InfoBox.imgShadowWidth-2 -4)+"px;width:"+InfoBox.imgArrowWidth+"px;height:"+InfoBox.imgArrowHeight+"px;background-repeat:no-repeat;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+InfoBox.imgPointorURL+"', sizingMethod='scale');z-index:3;\"></div>");
            sbBoxHTML.append("</div>");
            
            
            this.objBox.innerHTML = sbBoxHTML.toString();
           // this.boxHTML = this.objBox.innerHTML;
            this.infoHTML = contentHtml;
          
		};
		InfoBox.prototype.close = function()
		{
		   if(this.id)
		   {
		    
		      var bbooxx = document.getElementById(this.id);
		      
		      if(!bbooxx) return;
		      bbooxx.style.display = "none";
		      bbooxx.parentNode.removeChild(bbooxx);
		      if(this.onComplete)
		      {
		         this.onComplete ();
		      }
		   }
		}
		InfoBox.prototype.addToMap = function(oMap,id,smx,smy,onComplete)
        {
            oMap.AddMark("myInfoBox_"+id,smx,smy,this.boxWidth,2*this.boxHeight,this.objBox.innerHTML,"",10000,"");

            var ci = document.getElementById("myInfoBox_"+id);
            //document.getElementById("myInfoBox_"+id).style.zIndex = "2000";
            ci.onmouseover = function()
            {   
               //oMap.PanTo();
            }
            ci.onmouseout = function()
            {
               //eval("oMap."+mapOperation+"()");
            }
        }
        InfoBox.prototype.append = function(tagName,iHtml)
		{
		    if(arguments.length<1) return;
		    var ibox = this.objBox.firstChild;
            for (var ci=ibox.firstChild;ci!=null;ci=ci.nextSibling)
            {
                if(ci.id==this.contentId)
                {
                    if(arguments.length==1 && typeof arguments[0]=="object")
                    {
                        ci.appendChild(arguments[0]);
                    }
                    else
                    {
                        var child = document.createElement(tagName);
		                child.innerHTML = iHtml;
		                ci.appendChild(child);
		            }
		            break;
                }
            }
		}
		InfoBox.initialized = true;
	}
}

// StringBuffer Class 
function StringBuffer()
{
    if(arguments.length>0)
    {
        this._strings = new Array(arguments[0].toString());
    }
    else
    {
        this._strings = new Array;
    }
    if(typeof StringBuffer.initialized == "undefined")
	{
	    StringBuffer.prototype.append = function(str)
        {
            this._strings.push(str);
        }
        StringBuffer.prototype.toString = function() 
        {
            return this._strings.join("");
        }
        StringBuffer.initialized = true;
	}
}

