Balloon=function(w) {
    var structure=null;
    var content=null;
    var position=0; //0=TopLeft, 1=TopRight, 2=BottomLeft, 3=BottomRight
    var arrow=new Array();
    var closeButton=null;
    var width=w;
    
    initialize();
    
    this.content=content;
    this.show=show;
    this.hide=hide;
    
    function show(x, y) {
        position=0;
        var left=true;
        if(x-(structure.offsetWidth-10)<0) {
            position=1;
            left=false;
        }
        if(y-(structure.offsetHeight+15)<0) {
            if(!left) {
                position=3;
            }
            else {
                position=2;
            }
        }   
        structure.style.left=getX(x)+"px";
        structure.style.top=getY(y)+"px";
        for(var i=0;i<4;i++) {
            arrow[i].style.visibility="hidden";
        }
        arrow[position].style.visibility="visible";
        structure.style.visibility="visible";
    }
    
    function hide() {
        arrow[position].style.visibility="hidden";
        structure.style.visibility="hidden";
    }
    
    function getX(x) {
        if(position==0 || position==2) {
            return x-(structure.offsetWidth-10);
        }
        return x-10;
    }
    
    function getY(y) {
        if(position==0 || position==1) {
            return y-(structure.offsetHeight+15);
        }
        return y+15;
    }
    
    function initialize() {
        structure=document.createElement("DIV");
        structure.style.position="absolute";
        structure.style.top="0px";
        structure.style.left="0px";
        structure.style.visibility="hidden";
        structure.style.zIndex="101";
        
        //Arrows
        for(var i=0;i<4;i++) {
            arrow[i]=document.createElement("IMG");
            arrow[i].style.visibility="hidden";
            arrow[i].style.position="absolute";
            arrow[i].style.zIndex="102";
        }
        arrow[0].src="Images/BalloonImages/TopLeftArrow.gif";
        arrow[0].style.right="10px";
        arrow[0].style.bottom="-14px";
        arrow[1].src="Images/BalloonImages/TopRightArrow.gif";
        arrow[1].style.left="10px";
        arrow[1].style.bottom="-14px";
        arrow[2].src="Images/BalloonImages/BottomLeftArrow.gif";
        arrow[2].style.right="10px";
        arrow[2].style.top="-14px";
        arrow[3].src="Images/BalloonImages/BottomRightArrow.gif";
        arrow[3].style.left="10px";
        arrow[3].style.top="-14px";
        
        //Close Button
        closeButton=document.createElement("IMG");
        closeButton.alt="Close";
        closeButton.title="Close";
        closeButton.src="Images/BalloonImages/CloseButton.gif";
        closeButton.style.cssFloat="right";
        closeButton.style.styleFloat="right";
        closeButton.onmouseover=function() {
            this.src="Images/BalloonImages/CloseButtonHover.gif";
        }
        closeButton.onmouseout=function() {
            this.src="Images/BalloonImages/CloseButton.gif";
        }
        closeButton.onclick=function(e) {
            e=e ? e : event;
            e.cancelBubble=true;
            hide();
        }

        var table;
        var tsection;
        var tr;
        var td;
        
        table=document.createElement("TABLE");
        table.cellPadding="0";
        table.cellSpacing="0";
        table.style.width=width+"px";
        
        //Header Section
        tsection=document.createElement("THEAD");
        tr=document.createElement("TR");
        td=document.createElement("TD");
        td.style.backgroundImage="url(Images/BalloonImages/TopLeftCorner.gif)";
        td.style.height="5px";
        td.style.width="5px";
        tr.appendChild(td);
        td=document.createElement("TD");
        td.style.backgroundImage="url(Images/BalloonImages/Top.gif)";
        td.style.height="5px";
        for(var i=0;i<4;i++) {
            td.appendChild(arrow[i]);
        }
        tr.appendChild(td);
        td=document.createElement("TD");
        td.style.backgroundImage="url(Images/BalloonImages/TopRightCorner.gif)";
        td.style.height="5px";
        td.style.width="5px";
        tr.appendChild(td);
        tsection.appendChild(tr);
        table.appendChild(tsection);
        
        //Body Section
        tsection=document.createElement("TBODY");
        tr=document.createElement("TR");
        td=document.createElement("TD");
        td.style.backgroundImage="url(Images/BalloonImages/Left.gif)";
        td.style.width="5px";
        tr.appendChild(td);
        td=document.createElement("TD");
        td.style.backgroundColor="#F8F8F0";
        td.appendChild(closeButton);
        content=document.createElement("DIV");
        content.style.textAlign="left";
        td.appendChild(content);
        tr.appendChild(td);
        td=document.createElement("TD");
        td.style.backgroundImage="url(Images/BalloonImages/Right.gif)";
        td.style.width="5px";
        tr.appendChild(td);
        tsection.appendChild(tr);
        table.appendChild(tsection);
        
        //Footer Section
        tsection=document.createElement("TFOOT");
        tr=document.createElement("TR");
        td=document.createElement("TD");
        td.style.backgroundImage="url(Images/BalloonImages/BottomLeftCorner.gif)";
        td.style.height="5px";
        td.style.width="5px";
        tr.appendChild(td);
        td=document.createElement("TD");
        td.style.backgroundImage="url(Images/BalloonImages/Bottom.gif)";
        td.style.height="5px";
        tr.appendChild(td);
        td=document.createElement("TD");
        td.style.backgroundImage="url(Images/BalloonImages/BottomRightCorner.gif)";
        td.style.height="5px";
        td.style.width="5px";
        tr.appendChild(td);
        tsection.appendChild(tr);
        table.appendChild(tsection);
        
        structure.appendChild(table);
        document.body.appendChild(structure);
    }
}