
function registerMouseSign( selector ,option ){

    // 初始化数据
	$(selector).start_x = 0
	$(selector).start_y = 0
	$(selector).slug =  0;
	$(selector).valid = false
	$(selector).down = false
	$(selector).each(function(){
		this.option = eval("("+option+")");
	});
    document.oncontextmenu = function(){
        //window.event.returnValue=false;
        if( document.current_sign ){
            document.current_sign = null;
            return false;
        }else{
            return true;
        }
    };

    // 全局事件函数，当鼠标在非注册区域释放时，取消当前区域的状态标志
	$(document).mouseup(function(event){
		if(document.current_sign){
			if(document.current_sign.slug){
				document.current_sign.slug.hide();
			}
			document.current_sign.down = false;
		}
	});

    $(document).ready(function(){

    	$(selector).mousedown(function(event){
    		if(!event) event=window.event;

            if( event.button != 2){
                return true;
            }
			this.start_x = event.clientX;
			this.start_y = event.clientY;
			this.down = true;
            this.action = '';
            this.valid=false;
			document.current_sign = this
			
		});

		$(selector).mouseup(function(event){
			if(!event) event=window.event;
            if( event.button != 2){
                return true;
            }
            /* 从一个区域按下鼠标后滑动到另一个区域 */
            /* 
			if( document.current_sign && document.current_sign != this ){
				document.current_sign.down = false;
				if( document.current_sign.slug ){
					document.current_sign.slug.hide();
				}
				//document.current_sign = 0;
				return ;
			}
            */ 
            //document.current_sign = 0

			this.down = false;
			end_x = event.clientX;
			end_y = event.clientY;
			if( this.slug ){
				//this.slug.hide();
                this.slug.remove();
                this.slug = null;
			}
            //document.oncontextmenu= null;
			if(this.valid){
                event.returnValue = false;
                if( this.action ){
                    if( !this.option ){
                        return;
                    }
                    if( this.action == 'top' && this.option.top){
                        this.option.top();
                    }else if( this.action == 'left' && this.option.left ){
                        this.option.left();
                    }else if( this.action == 'right' && this.option.right ){
                        this.option.right(this);
                    }else if( this.action == 'bottom' && this.option.bottom){
                        this.option.bottom();
                    }
                }
			}else{
            }
		});

		$(selector).mousemove(function(event){
            /*
			if(!event) event=window.event;
            if( event.button != 2){
                return true;
            }
            */ 
            x_move = event.clientX - this.start_x;
            y_move = event.clientY - this.start_y;

			if( this.down ){

				if( Math.abs(x_move)<15 || Math.abs(y_move)<15 ){
					this.valid = true;
					if(this.slug ){
					}else{
						this.slug = $("<div class='m_sign' style='position:absolute;'><img src='' /></div>")
						this.slug.css('padding','1em');
                        this.slug.prependTo(this);
						//this.slug.prependTo('body');
                        p = this
                        //this.slug.mouseup(function(event){
                         //       p.onmouseup(event);
                          //  });
						//this.slug.hide();
					}
				}else{
					this.valid = false;
				}

				if(this.valid){
					if( Math.abs(x_move) > 30 || Math.abs(y_move) > 30 ){

                        /*if( $.browser.msie && $.browser.version == '6.0'){
                            //alert( event.pageX + '  ' + event.pageY +'\n' + event.clientX + ' ' + event.clientY);
                            this.slug.css('left',( event.clientX - 100 -250 + 'px'));
                            this.slug.css('top',( event.clientY - 100 + 'px'));
                        }else{
                        */
						    this.slug.css('top',(this.start_y +  event.pageY - event.clientY -15 - 100 +'px'));
                            this.slug.css('left',(this.start_x + event.pageX - event.clientX  -15 - 100 +'px'));
                        /*
                         * }
                         */
						//this.slug.css('opacity',0.2);
						//this.slug.hover(function(){
						//	$(this).css('opacity',1.0);
						//})
					}

					if( Math.abs(x_move) > 30 || Math.abs(y_move) > 30 ){
						if( x_move > 30 ){
							this.img = '/static/sign_right.gif';
                            this.action = 'right';
						}else if( x_move < -30 ){
							this.img = '/static/sign_left.gif';
                            this.action = 'left';
						}else if( y_move < 30 ){
							this.img = '/static/sign_top.gif';
                            this.action = 'top';
						}else{
							this.img = '/static/sign_bottom.gif';
                            this.action = 'bottom';
						}
                        this.slug.find('img').attr('src',this.img);
					}
				}/* if valid */
			}/* if down */

		});/* mouseover */

	});/* document.ready() */
};/* registerMouseSign */

