﻿function createCtx(){
    var o=document.createElement('DIV');
    
    o.On_Click=null;
    
    o.GetCvsSize=null;
    
    o.className='ctx';
    o.style.cssText='position:absolute;display:none;';
    
    addEvent(o,'mousedown',function(evt){if(evt.preventDefault)evt.preventDefault();evt.cancelBubble=true;return false;},false);
    addEvent(o,'contextmenu',function(evt){if(evt.preventDefault)evt.preventDefault();evt.cancelBubble=true;return false;},false);
    
    o.innerHTML='<a href="javascript:map_ctx_tool(\'search_around\');"><img src="images/toolbar/zbian.gif"/> 周 边 查 询</a>'+
                '<div class="hr"></div>'+
                '<a href="javascript:map_ctx_tool(\'z1\');"><img src="images/toolbar/max.gif"/> 地图放至最大</a>'+
                '<a href="javascript:map_ctx_tool(\'zi\');"><img src="images/toolbar/z1.gif"/> 地图放大一倍</a>'+
                '<a href="javascript:map_ctx_tool(\'zo\');"><img src="images/toolbar/z2.gif"/> 地图缩小一倍</a>'+
                '<a href="javascript:map_ctx_tool(\'z8\');"><img src="images/toolbar/min.gif"/> 地图缩至最小</a>'+
                '<div class="hr"></div>'+
                '<a href="javascript:map_ctx_tool(\'bus_start\');"><img src="images/toolbar/start.gif"/> 设置公交起点</a>'+
                '<a href="javascript:map_ctx_tool(\'bus_end\');"><img src="images/toolbar/end.gif"/> 设置公交终点</a>'+
                '<div class="hr"></div>'+
                '<a href="javascript:map_ctx_tool(\'a_clear\');"><img src="images/toolbar/clear.gif"/> 清 除 所 有</a>';
    
    o.show=function(pos){
        this.style.display='';
        var cvssize=this.GetCvsSize();
        var x=pos.x,y=pos.y;
        if(x+this.offsetWidth>cvssize.w)x-=this.offsetWidth;
        if(y+this.offsetHeight>cvssize.h)y-=this.offsetHeight;
        this._x=pos.x;
        this._y=pos.y;
        this.style.left=x+'px';
        this.style.top=y+'px';
    };
    
    o.getpos=function(){
        return new Point(this._x,this._y);
    };
    
    o.hide=function(){
        this.style.display='none';
    };
    
    window.map_ctx_tool=function(b){
        if(this.On_Click)this.On_Click(this,{b:b,pos:this.getpos()});
    }.bind(o);
    
    return o;
};

