GISJS.MapObject = function(a_mapimg,a_mapsel,a_img) {
     this.drag = false ;
  	 this.startX = 0;
 	 this.startY = 0;
  	 this.imgstartX = 0;
 	 this.imgstartY = 0; 	 
  	 this.endX = 0;
 	 this.endY = 0;  
 	 this.opcode ="" ;
 	 this.amapimg = a_mapimg ;
  	 this.mapsel = a_mapsel ;
  	 this.img = a_img ;
  	 //Added
  	 this.xp1 = 0;
 	 this.xp2 = 0;
 	 this.yp1 = 0;
 	 this.yp2 = 0;
 	 //End Added
 	 this.mouseup = function   (e){        	
 	  	    GISJS.Dom.setStyle(this.mapsel,"visibility","hidden" );  	 	  	    
			if ( this.drag && (this.opcode != "PAN" && this.opcode != "MEASURE")) //Added
			{	 this.amapimg.href="#";			     
			     var el = this.mapsel ;
			     var el2 = this.amapimg ;
			     this.startX = GISJS.Dom.getXY(el)[0] - GISJS.Dom.getXY(el2)[0]; 
				 this.startY = GISJS.Dom.getXY(el)[1] - GISJS.Dom.getXY(el2)[1]; 
				 this.endX = this.startX + el.offsetWidth -3 ;//Remove height and border size 
				 this.endY = this.startY + el.offsetHeight -3 ;//Remove height and border size 				 				 
		         this.submitvalues(this.opcode,this.startX,this.endX,this.startY,this.endY);   	          	
		  	}	
		  	//Added		 
		  	else if(this.drag && this.opcode == "MEASURE" ){
		       this.amapimg.href="#";
		       if ( this.xp1 == 0 && this.yp1 == 0 ){
		           //alert("this.xp1 = " + this.xp1 + " this.yp1 =  " + this.yp1);
		           var el = this.mapsel ;
			       var el2 = this.amapimg ;
                   this.startX = GISJS.Dom.getXY(el)[0] - GISJS.Dom.getXY(el2)[0]; 
		           this.startY = GISJS.Dom.getXY(el)[1] - GISJS.Dom.getXY(el2)[1]; 
				   this.xp1 = this.startX; 
				   this.yp1 = this.startY; 
				   GISJS.Event.stopEvent(e);
				   //this.endX = 0;
				   //this.endY = 0;
				   
				   alert("Please select end point......." ); 
				   return true;
				    } 
			   else {
			       var el3 = this.mapsel;
                   var el4 = this.amapimg;
                   this.endX = GISJS.Dom.getXY(el3)[0] - GISJS.Dom.getXY(el4)[0]; 
				   this.endY = GISJS.Dom.getXY(el3)[1] - GISJS.Dom.getXY(el4)[1]; 
				   GISJS.Event.stopEvent(e);
				   this.xp2 = this.endX; 
				   this.yp2 = this.endY; 
                //} 
			    //alert( "endX" + this.xp2 +  "endY" + this.yp2);
                this.submitvalues(this.opcode,this.xp1,this.xp2,this.yp1,this.yp2);
			  }
			}   	//End Added	
		  	else if (this.drag && this.opcode == "PAN") {
		  	     this.amapimg.href="#";
		  	     this.startX =  GISJS.Event.getPageX(e)  - this.startX  ; 
				 this.startY = GISJS.Event.getPageY(e)  - this.startY    ;
				 this.endX = 0;
				 this.endY = 0;
		        // alert("startX" + this.startX + "endX" + this.endX + "startY" + this.startY + "endY" + this.endY);				 
				 this.submitvalues(this.opcode,this.startX,this.endX,this.startY,this.endY);
		  	}
		  	this.drag = false ;
		 
 	  };
	  this.mousedown = function (e){
	        this.drag = true ;
		    this.startX = GISJS.Event.getPageX(e); 
		    this.startY = GISJS.Event.getPageY(e);  
		    this.imgstartX = GISJS.Dom.getX(this.img);
 	        this.imgstartY = GISJS.Dom.getY(this.img);     
		    GISJS.Dom.setXY(this.mapsel, [ this.startX , this.startY]);
			GISJS.Dom.setStyle(this.mapsel,"width", "1px" );
			GISJS.Dom.setStyle(this.mapsel,"height","1px" );
		    if (this.opcode != "PAN" ) GISJS.Dom.setStyle(this.mapsel,"visibility","visible" );  	
		    
		    GISJS.Event.stopEvent(e);	 	
	  };
	  this.mousemove = function (e){	  			
			  if (this.drag && this.opcode != "PAN" && this.opcode != "MEASURE" && this.opcode != "BUFFER") {
				if ( ( GISJS.Event.getPageX(e) - this.startX ) <= -1 ){
					GISJS.Dom.setX(this.mapsel, GISJS.Event.getPageX(e));		
					GISJS.Dom.setStyle(this.mapsel,"width", ( this.startX - GISJS.Event.getPageX(e))+"px" );				 
				}
			 	else if ( ( GISJS.Event.getPageX(e) - this.startX ) == 0 ){}
				else{		
				 	GISJS.Dom.setStyle(this.mapsel,"width", (GISJS.Event.getPageX(e)  - this.startX  )+"px" );
				}
				if ( ( GISJS.Event.getPageY(e) - this.startY ) <= -1 ){
					GISJS.Dom.setY(this.mapsel, GISJS.Event.getPageY(e));						
					GISJS.Dom.setStyle(this.mapsel,"height",(  this.startY - GISJS.Event.getPageY(e)   )+"px" );
				}
			    else if ( ( GISJS.Event.getPageY(e) - this.startY ) == 0 ){}		
			    else{			        			        
					GISJS.Dom.setStyle(this.mapsel,"height",( GISJS.Event.getPageY(e) - this.startY )+"px" );
				}
		       GISJS.Event.stopEvent(e);	 					 
		     }
		     else if (this.drag && this.opcode == "PAN") {               
		           
		          if ( ((GISJS.Event.getPageX(e) - this.startX) > 0) &&  ((GISJS.Event.getPageY(e) - this.startY) > 0))
		           this.img.style.clip ='rect(0px '+  (580 -  (GISJS.Event.getPageX(e) - this.startX))+'px '+(580 -  (GISJS.Event.getPageY(e) - this.startY))+'px 0px)';
		          else if ( ((GISJS.Event.getPageX(e) - this.startX) > 0) &&  ((GISJS.Event.getPageY(e) - this.startY) < 0))
		           this.img.style.clip ='rect('+( this.startY - GISJS.Event.getPageY(e))+'px '+  (580 -  (GISJS.Event.getPageX(e) - this.startX))+'px 580px 0px)';
		          else if ( ((GISJS.Event.getPageX(e) - this.startX) < 0) &&  ((GISJS.Event.getPageY(e) - this.startY) > 0))
                    this.img.style.clip ='rect(0px 580px '+(580 -  (GISJS.Event.getPageY(e) - this.startY))+'px '+ ( this.startX - GISJS.Event.getPageX(e))+'px)';
		          else if ( ((GISJS.Event.getPageX(e) - this.startX) < 0) &&  ((GISJS.Event.getPageY(e) - this.startY) < 0))
		           this.img.style.clip ='rect('+( this.startY - GISJS.Event.getPageY(e))+'px 580px 580px '+ ( this.startX - GISJS.Event.getPageX(e))+'px)';
		           
		           if (Math.abs(GISJS.Event.getPageX(e) - this.startX) > 0 && Math.abs(GISJS.Event.getPageX(e) - this.startX) < 580)GISJS.Dom.setX(this.img,( this.imgstartX  + GISJS.Event.getPageX(e) - this.startX ));
		           if (Math.abs(GISJS.Event.getPageY(e) - this.startY) > 0 && Math.abs(GISJS.Event.getPageY(e) - this.startY) < 580) GISJS.Dom.setY(this.img,( this.imgstartY  + GISJS.Event.getPageY(e) - this.startY ));
		           GISJS.Event.stopEvent(e);	 	 		 
		     }
	  }; 
	    
	  this.submitvalues = function (o,x1,x2,y1,y2){};
	  GISJS.Event.addListener(this.amapimg,"mousedown",this.mousedown,this,true);
	  GISJS.Event.addListener(this.amapimg,"mousemove",this.mousemove,this,true);
	  GISJS.Event.addListener(this.mapsel,"mousemove",this.mousemove,this,true);  
	  GISJS.Event.addListener(document,"mouseup",this.mouseup,this,true);  
  };
  

