var objFloaters = {};
var debugCount = 0,debugStep = 10; //if debugging is on and you don't want debug msg on each pixel dragged increase this step no (only show debug msg every X drag events)
var objWinStats = null; //holds stats about mouse pos, scroll pos, window size and gets updated on certain events that any floater can access

function OutputWindowStats(){
	if(objWinStats && typeof(objWinStats)=="object"){
		var str = "CaptureMouse = " + objWinStats.captureMouse + ", MouseX = "+objWinStats.mouseX+", MouseY = " + objWinStats.mouseY + ", ScrollX = "+objWinStats.scrollX+", ScrollY = "+objWinStats.scrollY+", ViewportWidth = "+objWinStats.viewportWidth+", ViewportHeight = "+objWinStats.viewportHeight;
		//ShowDebug(str);
	}else{
		ShowDebug("No window stats object instantiated!");
	}
}
WindowStats = function(e)
{
	ShowDebug("Create new Window Stats object")
	var self = this;
	//set default values
	this.mouseX = 0;
	this.mouseY = 0;
	this.scrollX = 0;
	this.scrollY = 0;
	this.viewportHeight = 0;
	this.viewportWidth = 0;
	this.debugMoves = 10; // must be > 0 to output debug statements every X mouse move events
	this.debugStep = 0;//reset to 0 when it reaches debugMoves
	this.captureMouse = false; //only set to true when a draggable object is initialised
	if(document.captureEvents && Event){ 
		document.captureEvents(Event.MOUSEMOVE);	
	}
	this.onScrollEvent = function(e){self.UpdateScroll(e);};
	this.onResizeEvent = function(e){self.UpdateViewport(e);};
	this.onMouseMoveEvent = function(e){if(self.captureMouse){self.UpdateMouse(e);};};
	//attach internal methods to event handlers to keep scroll, mouse and viewport stats up to date using the addHanlders function
	//that will also add remove listeners on the window.unload event
	addHandlers(window,"scroll",self.onScrollEvent);
	addHandlers(window,"resize",self.onResizeEvent);
	addHandlers(document,"mousemove",self.onMouseMoveEvent)
	//call function that will populate properties now and override default values
	this.UpdateWindowStats();
}

WindowStats.prototype.Destroy = function(e){
	ShowDebug("IN WindowStats.Destroy Remove all events");
	var self = this;
	this.captureMouse=false;
	removeEvent(window,"scroll",self.onScrollEvent);
	removeEvent(window,"resize",self.onResizeEvent);	
	removeEvent(document,"mousemove",self.onMouseMoveEvent)
	this.onScrollEvent = null;
	this.onResizeEvent = null;	
	this.onMouseMoveEvent = null;
	if(document.captureEvents && Event){ 
		document.releaseEvents(Event.MOUSEMOVE);
	}
}

WindowStats.prototype.UpdateWindowStats = function(e){
	ShowDebug("IN WindowStats.UpdateWindowStats")
	this.UpdateMouse(e);
	this.UpdateScroll();
	this.UpdateViewport();
}

WindowStats.prototype.UpdateMouse = function(e){
	if(!e) e = window.event;
	var pos=getMouseXY(e);
	this.mouseX = pos.x;
	this.mouseY = pos.y;
	if(this.debugMoves>0){
		if (this.debugStep==this.debugMoves){
			OutputWindowStats();
			this.debugStep=0;//reset and on the next X will output again
		}else{this.debugStep++;}
	}
}

WindowStats.prototype.UpdateScroll = function(e){
	var scroll = getScrollPosition();
	this.scrollX = scroll.x;
	this.scrollY = scroll.y;
}

WindowStats.prototype.UpdateViewport = function(){
	var viewport = getViewportSize()
	this.viewportHeight = viewport.height;
	this.viewportWidth = viewport.width;
	//ShowDebug("Updated Viewport")
	OutputWindowStats();

}

ShowObject = function(e,id,startX,startY,intWidth,intHeight,widthPad,heightPad,prevMov)
{
	ShowDebug("in ShowObject id="+id+",startX="+startX+",startY="+startY+",intWidth="+intWidth+",intHeight="+intHeight+",widthPad="+widthPad+",heightPad="+heightPad+",prevMov="+prevMov);

	var objFloat;
	var origX,origY;

	if(objFloaters[id]){
		//ShowDebug("got stored object with this id = " + id)
		objFloat = objFloaters[id];
	}else{
		//ShowDebug("create new floater object with id = " + id)
		objFloat = new Floater(e,id);
	}	
	
	ShowDebug("do we have an object = " + objFloat + " typeof = " + typeof(objFloat) + " - exists = "+ objFloat.exists);
	if(!objFloat || !objFloat.exists) return;

	if(!isNaN(parseInt(intWidth))){ objFloat.internalWidth = intWidth; }
	if(!isNaN(parseInt(intHeight))){ objFloat.internalHeight = intHeight; }
	if(!isNaN(parseInt(widthPad))){ objFloat.internalWidthPadding = widthPad; }
	if(!isNaN(parseInt(heightPad))){ objFloat.internalHeightPadding = heightPad; }

	//ShowDebug("set objFloat.internalWidth = " + objFloat.internalWidth + " == " + intWidth)
	//ShowDebug("set objFloat.internalHeight = " + objFloat.internalHeight + " == " + intHeight)

	var dimensions = getDimensions(id); //get dimensions of floating div
	//ShowDebug("back from getDimensions width = " + dimensions.width + ", height = " + dimensions.height)
	//might return auto or % for width so in that case check if we have an internalWidth to use + any padding
	var w=parseInt(dimensions.width),h=parseInt(dimensions.height);
	if(isNaN(w) || w==0){
		//ShowDebug(dimensions.width + " isNaN or 0 use internalWidth = " + objFloat.internalWidth + " if > 0")
		if(objFloat.internalWidth>0){
			objFloat.width = parseInt(objFloat.internalWidth) + parseInt(objFloat.internalWidthPadding);
			ShowDebug("used internal width = " +objFloat.width );
		}
	}else{
		objFloat.width = w;
	}
	if(isNaN(h) || h==0){
		//ShowDebug(dimensions.height + " isNaN or 0 use internalHeight = " + objFloat.internalHeight + " if > 0")
		if(objFloat.internalHeight>0){
			objFloat.height = parseInt(objFloat.internalHeight) + parseInt(objFloat.internalHeightPadding);
			//ShowDebug("used internal height = " +objFloat.height );
		}
	}else{
		objFloat.height = h;
	}
	//script may want to prevent div from roaming outside viewport boundaries but if there is no room then we need to override
	objFloat.origPrevMov = prevMov;

	ShowDebug("width = " +objFloat.width + " height = " + objFloat.height)
	//ShowDebug("viewport.width = " + objWinStats.viewportWidth + " viewport.height = " + objWinStats.viewportHeight)
	//ShowDebug("is there no room for dragging without auto corrections happening all the time if so turn off auto-correct")
	
	//if the height of the moveable object + 50px is more than the available height/width then no point trying to keep in viewport boundary as you
	//wont be able to move it anywhere.
	CheckHidden(objFloat);

	//startX = parseInt(startX),startY = parseInt(startY);
	//ShowDebug("After parseInt startX="+startX+",startY="+startY);

	// if starting co-ords not supplied for object then place in middle of the screen.
	if(startX==0||startY==0){								
		//ShowDebug("do a sum to work out where to position div");
		var center = objFloat.CenterObject();
		startX = center.startX;
		startY = center.startY;
		//ShowDebug("startX = " + startX + " startY = " + startY);
		/*
		if(!isNaN(objFloat.width)){	var startX = (objWinStats.viewportWidth/2)-(objFloat.width/2); }else{ startX=200; }
		if(!isNaN(objFloat.height)){ var startY = (objWinStats.viewportHeight/2)-(objFloat.height/2);}else{ startY=200;}
		//ShowDebug("startX = " + objWinStats.viewportWidth + " / 2 = " + (objWinStats.viewportWidth/2) + " - " + objFloat.width + " / 2 = " + (objFloat.width/2) + " = " + startX);
		//ShowDebug("startY = " + objWinStats.viewportHeight + " / 2 = " + (objWinStats.viewportHeight/2) + " - " + objFloat.height + " / 2 = " + (objFloat.height/2) + " = " + startY);
		*/
	}	
	
	//ShowDebug("startX = " + startX + " startY = " + startY)
	//store starting position of element
	objFloat.divStartLeft = startX;
	objFloat.divStartTop = startY;
	//ShowDebug("set objFloat.divStyle.left")
	//ShowDebug("currently = " + objFloat.divStyle.left)
	//ShowDebug("objFloat.px = " + objFloat.px)
	//ShowDebug("I want to set objFloat.divStyle.left to " +  objFloat.divStartLeft + objFloat.px);
	objFloat.divStyle.left = objFloat.divStartLeft + objFloat.px; 
	//ShowDebug("done left now set top to " + objFloat.divStartTop + objFloat.px);
	objFloat.divStyle.top = objFloat.divStartTop + objFloat.px; 
		
	//divStyle.top = "0px";	
	//ShowDebug("show div = "+ objFloat.id + " set left = " + objFloat.divStartLeft + " top = "+ objFloat.divStartTop + " height = " + objFloat.height +" width = " + objFloat.width);

	//ShowDebug("divStyle.left = " + objFloat.divStyle.left + " objFloat.divStyle.top = " + objFloat.divStyle.top + " divStartLeft = " + objFloat.divStartLeft + " divStartTop = " + objFloat.divStartTop);

	if(Browser.dom==3){
		objFloat.divStyle.visibility="show";
		objFloat.divStyle.display="block";
	}else{
		objFloat.divStyle.visibility="visible";
		objFloat.divStyle.display='block';
	}	

}

Floater.prototype.CenterObject = function(){
	var self = this;
	//ShowDebug("IN CenterObject")
	var startX=200,startY=200;
	if(!isNaN(self.width)){
		var startX = (objWinStats.viewportWidth/2)-(self.width/2);
		//ShowDebug("startX = " + objWinStats.viewportWidth + " / 2 - " + self.width + " / 2");
		startX+=objWinStats.scrollX;
		//ShowDebug("startX += " + objWinStats.scrollX);
	}	
	if(!isNaN(self.height)){
		var startY = (objWinStats.viewportHeight/2)-(self.height/2);	
		//ShowDebug("startY = " + objWinStats.viewportHeight + " / 2 - " + self.height +  " / 2");
		startY+=objWinStats.scrollY;
		//ShowDebug("startY += " + objWinStats.scrollY);
		
	}
	var center={
		"startX":startX,
		"startY":startY
	}
	return center;
}

CheckHidden = function(obj){
	//ShowDebug("In CheckHidden")
	if(obj && objWinStats && obj.origPrevMov){
		if(obj.width+50 > objWinStats.viewportWidth || obj.height+50 > objWinStats.viewportHeight){
			obj.prevMov = false;
			//ShowDebug("set prevMov = false not enough room")
		}else{
			obj.prevMov = true;
			//ShowDebug("set prevMov = true")
		}
	}else{ obj.prevMov = false;}
	return;
}

HideObject = function(e,id)
{
	//ShowDebug("In HideObject id="+id)
	var objFloat,divStyle;
	if(id){
		objFloat = getFloatObj(id,null);
		if(objFloat){			
			//ShowDebug("got float object")
			divStyle = objFloat.divStyle;
		}else{
			//ShowDebug("no float object so get from id")
			var el = getEl(id);
			divStyle = (el.style) ? el.style : el;
		}
		//ShowDebug("dom = " + Browser.dom)
		if(Browser.dom==3){
			divStyle.visibility="hide";
			divStyle.display="none";
		}else{
			divStyle.visibility="hidden";
			divStyle.display="none";
		}
		//ShowDebug("should now be hidden")
		if(objFloat){
			//ShowDebug("Remove events")
			objFloat.intMotion = false;
			objFloat.RemoveEvents();
			objFloat = null;
		}
		//ShowDebug("Nullify object")
		//nullify object within array of floaters
		if(objFloaters[id]){objFloaters[id] = null;}
	}

	// destroy existing window stats object and remove all event handlers within
	if(objWinStats&&typeof(objWinStats)=="object"){
		//ShowDebug("destroy window object")
		objWinStats.Destroy;
	}
	//ShowDebug("destroy objWinStats reference")
	objWinStats = null;
}


function Floater(e,id)
{	
	ShowDebug("Floater = " + id);

	this.id = id;
	this.el = getEl(id);	
	if(!this.el) {
		this.exists = false;
		ShowDebug("No object with this id = " + id + " so quit"); 
		return;		
	}else{
		this.exists = true;
	}
	this.divStyle = (this.el.style) ? this.el.style : this.el;
	//ShowDebug("Set divStyle = " + this.divStyle)
	this.posX = 0;
	this.posY = 0;
	this.posLastX = 0;
	this.posLastY = 0;
	this.startPosX = 0;
	this.startPosY = 0;
	this.divStartLeft = 0;
	this.divStartTop = 0;
	this.zIndex = 10000;
	this.mousemove = null;
	this.mouseup = null;
	this.overDiv = false; //used on older NN browsers to mark when cursor should affect the positioning+	
	this.inMotion= false;
	this.origPrevMov = false;
	this.prevMov = true; //will prevent the div from being moved outside the current viewports boundaries
	//If you want to set the width of any internal object within the floater then if a width/height cannot be accessed for floater this will be used
	//with the extra padding adding if set.
	this.internalWidth = 0;
	this.internalHeight = 0;
	this.internalWidthPadding = 0;
	this.internalHeightPadding = 0;

	if(Browser.dom==3){
		this.px = "";
	}else{
		this.px = "px"; // to append to positioning
	}	
	//add this floater object into the array of floating objects
	objFloaters[id]=this;
	ShowFloaters();	

	ShowDebug("do we create a new objWinStats object??")
	// create a new WindowStats object if one doesn't already exist as this will hold info about mousepos,viewport,scrollbars etc
	if(!objWinStats || typeof(objWinStats)!="object"){
		ShowDebug("Yes create new object");
		objWinStats = new WindowStats(e);
	}

}

Floater.prototype.Destroy = function(e){
	//ShowDebug("IN Floater.Destroy")
	// make sure all event handlers have been removed and pointers nullified	
	this.RemoveEvents();
}

Floater.prototype.RemoveEvents = function(e){
	//ShowDebug("In Floater.Destroy")
	var self = this;

	if(document.captureEvents && Event){ 
		document.releaseEvents(Event.MOUSEDOWN | Event.MOUSEUP); 
	}

	//ShowDebug("Remove events");
	
	removeEvent(document,"mousemove",self.onmousemove);
	removeEvent(document,"mouseup",self.onmouseup);	
	this.onmousemove=null;
	this.onmouseup=null;		
	//ShowDebug("All events Removed");
	return;
}


//show all floater objects stored
function ShowFloaters()
{
	//ShowDebug("lets look at all current objects in array")			
	for (var obj in objFloaters){
		ShowDebug("obj = " + obj + " = " + typeof(objFloaters[obj]))
	}
}



var z=1;
function StartDrag(e,id){
	//ShowDebug("IN StartDrag = " +id);

	var objFloat = getFloatObj(id,null);
	if(!objFloat){
		StopEvent(e);
		return;
	}else{
		objFloat.inMotion=true; //only allow drag when true. If events cannot be removed for whatever reason this prevents sticky mouse syndrome
	}
	//make sure we have a valid window stats object
	if(!objWinStats || typeof(objWinStats)!="object"){
		objWinStats = new WindowStats(e);
	}else{ //update mouse stats as we use them for starting positions
		objWinStats.UpdateMouse(e);
	}
	
	//hanlder older event systems
	if(document.captureEvents && Event){ 
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP); 
	}	
	

	
	var el,x,y;	
	if(!id){
		el = GetElementFromEvent(e);
	}
	objWinStats.captureMouse = true; //tell our window stats object to record position of mouse as it moves
	//also get current position of mouse position at present point
	objWinStats.UpdateMouse(e);
	// Save starting positions of cursor and element.
	objFloat.startPosX = objWinStats.mouseX;
	objFloat.startPosY = objWinStats.mouseY;
		
	//ShowDebug("Save Starting pos of cursor = startPosX = " + objFloat.startPosX + " startPosY = " + objFloat.startPosY);
				
	//if the start positions are not valid then we get the current position of the div
	if(isNaN(parseInt(objFloat.divStyle.left))||isNaN(parseInt(objFloat.divStyle.left))){
		//ShowDebug(objFloat.divStyle.left + " isNaN OR " + objFloat.divStyle.left + " isNaN so get current position of div")
		var curPos = findPosition(objFloat.el);
		objFloat.divStartLeft = curPos.x;
		objFloat.divStartTop  = curPos.y;
		//ShowDebug("as one or both NAN then use current pos of element divStartLeft = " +objFloat.divStartLeft  + " divStartTop = " + objFloat.divStartTop);
	}else{
		//ShowDebug(objFloat.divStyle.left + " is OK AND " + objFloat.divStyle.left + " is OK")
		objFloat.divStartLeft = parseInt(objFloat.divStyle.left,10);	
		objFloat.divStartTop = parseInt(objFloat.divStyle.top,10);
	}
	//ShowDebug("Save Starting pos of div = divStartLeft = " +objFloat.divStartLeft  + " divStartTop = " + objFloat.divStartTop);
		
	// Update element's z-index.
	objFloat.divStyle.zIndex = ++objFloat.zIndex;
	//alert("set zIndex = " + objFloat.divStyle.zIndex)
	//ShowDebug("Add event handlers")

	var thisID = objFloat.id;
	//ShowDebug("thisID = "+ thisID)

	// Capture mousemove and mouseup events on the page.
	// This works

	// using cross-browser funcs with anonymouse functions and store references so we can remove them later
	//ShowDebug("Add Events using cross browser functions addEvent")
	//ShowDebug("B4 adding lets check to see we are not adding extra events!!")
	//ShowDebug("objFloat.mousemove = " + objFloat.onmousemove)
	//ShowDebug("objFloat.mouseup = " + objFloat.mouseup)
	//ShowDebug("ARE THEY EMPTY???? IF SO ADD SOME")
	if(objFloat.mousemove===null){
		//ShowDebug("YES IS NULL SO ADD MOUSEMOVE EVENT")
		objFloat.onmousemove = function(e){Drag(e,objFloat.id,objFloat);}
		addHandlers(document,"mousemove",objFloat.onmousemove);
	}
	if(objFloat.mouseup===null){
		//ShowDebug("YES IS NULL SO ADD MOUSEUP EVENT")
		objFloat.onmouseup = function(e){StopDrag(e,thisID,objFloat);}
		addHandlers(document,"mouseup",objFloat.onmouseup);
	}
	//stop event propagation
	StopEvent(e);		
	
	//ShowDebug("RETURN FROM StartDrag")
}

function ShowDebugStep(msg){
	if(debugCount==debugStep){
		ShowDebug(msg); //only show every X messages		
	}
}

var poo=1;


function AdjustFloat(e,id,objFloat)
{
	//ShowDebug("IN AdjustFloat " + id)
	if(typeof(objFloat)!="object"){
		if(objFloaters[id]){
			var objFloat = objFloaters[id];
		}else{
			//ShowDebugStep("no stored float object with this id = " + id);
			return;
		}
	}

}

function getFloatObj(id,objFloat){
	//if we havent got a reference to a drag object then get one from the stored objects
	if(!objFloat||typeof(objFloat)!="object"){
		if(objFloaters[id]){ return objFloaters[id];}
	}else{return objFloat;}
}

function Drag(e,id,objFloat) {
	//ShowDebugStep("IN Drag id="+id)
	if (!e) {e = window.event;}	
	objFloat = getFloatObj(id,objFloat); //make sure we have a float object
		
	if(objFloat){
		if(!objFloat.inMotion){
			//ShowDebug("In Motion = False return with no drag")
			StopEvent(e);
			return;
		}

		// Get cursor position with respect to the page.
		
		var x = objWinStats.mouseX;
		var y = objWinStats.mouseY;
	//	//ShowDebugStep("Got latest mouse position x = "+ x + " y = "+ y + " startPosX = " + objFloat.startPosX + " startPosY = " + objFloat.startPosY)
		
		//ShowDebugStep("check for x==0 && y==0 x is "+ x + " y is " + y + " objWinStats.scrollX = " + objWinStats.scrollX + " objWinStats.scrollY = " + objWinStats.scrollY)
					
		//prevent div from jumping when mouse co-ords cannot be calculated and therefore set to 0,0 for whatever reason
		if(x==0&&y==0){
			//ShowDebugStep("Set to corner 0,0 so check if valid")
			//if last co-ords were nowhere near this then something has fucked up so try to preven the jump
			if(this.posLastX>=5){
				//ShowDebugStep("posLastX was " + this.posLastX +" so set x to that")
				x = posLastX;
			}
			if(this.posLastY>=5){
				//ShowDebugStep("posLastY was " + this.posLastY +" so set y to that")
				y = posLastY;
			}
		}
			

		// Move object but if this.prevMov = true we don't want to allow the div to be moved off screen (over viewports limits)
		var newLeft = parseInt(objFloat.divStartLeft + x - objFloat.startPosX);
		var newTop	= parseInt(objFloat.divStartTop + y - objFloat.startPosY);
		//ShowDebug("newLeft = " + newLeft + " newTop + " + newTop +" check if prevMov is on = " + objFloat.prevMov);
		// also if prevMov has been set prevent div from going over viewports boundaries
		if(objFloat.prevMov){			
			//ShowDebugStep("check new co-ords are not outside allowed boundaries new left =" + newLeft + " newTop = " + newTop);
			
			if(newLeft<objWinStats.scrollX){
				//ShowDebug("newLeft < " + objWinStats.scrollX + " (objWinStats.scrollX) = " + newLeft + " so set == " + objWinStats.scrollX);
				//newLeft = 0; //set to left boundary
				newLeft = objWinStats.scrollX;
			}else{
				//ShowDebug("check for right boundary")
				//check for right boundary
				var elWidth = parseInt(objFloat.width);
				if(!isNaN(elWidth)){
					//ShowDebug("elWidth = " + elWidth + " if not NaN then check")
					if(newLeft+elWidth > objWinStats.viewportWidth+objWinStats.scrollX){
						//ShowDebug("right position = " + newLeft + " + " + elWidth + " (" + (newLeft+elWidth) + ") > " + objWinStats.viewportWidth + " + " + +objWinStats.scrollX + " so reset");
						newLeft = (objWinStats.viewportWidth+objWinStats.scrollX)-elWidth;
					}
				}
			}
			if(newTop<objWinStats.scrollY){
				//ShowDebug("newTop < " + objWinStats.scrollY + " (objWinStats.scrollY) = " + newTop + " so set == " + objWinStats.scrollY)
				//newTop = 0; //set to top boundary
				newTop = objWinStats.scrollY;
			}else{
				//check for bottom boundary
				//ShowDebug("check for bottom boundary")
				var elHeight = parseInt(objFloat.height);
				//ShowDebug("elHeight = " + elHeight + " if not NaN then check")
				if(!isNaN(elHeight)){
					if(newTop+elHeight > objWinStats.viewportHeight+objWinStats.scrollY){
						//ShowDebug("bottom position = " + newTop + " + " + elHeight + " (" + (newTop+elHeight) + ") > " + objWinStats.viewportHeight + " + " + objWinStats.scrollY + " so reset");
						newTop = (objWinStats.viewportHeight+objWinStats.scrollY)-elHeight;
					}
				}
			}	
			//ShowDebugStep("so after any re-calculations newLeft = "+ newLeft + " newTop + " + newTop);
		}
	
	
		// Move draggable div element by the same amount the cursor has moved.
		objFloat.divStyle.left	= newLeft + objFloat.px;
		objFloat.divStyle.top	= newTop + objFloat.px;

		ShowDebugStep("just set divStyle.left = " + objFloat.divStyle.left + " divStyle.top = " + objFloat.divStyle.top);
		ShowDebugStep("look at objFloat.width = " + objFloat.width + " height = " + objFloat.height);

		/*	store the current position so in case we get a fuck up on the next move we revert back to something that works
			if we have suddenly jumped from a valid co-ord say 100,34 to 0,0 it means the cursor has gone off screen so we can't get a value
			therefore we want to revert back to the values before hand to prevent the div from jumping to 0,0	*/
		// if x or y is now 0 then only set if it hasn't jumped due to fuckup
		if(x==0){
			if(this.posLastX<=5){
				this.posLastX = x; //ok to set as its not jumped by a huge margin and cursor was already in the proximity of 0
			}
		}else{
			this.posLastX = x; //ok to set
		}
		if(y==0){
			if(this.posLastY<=5){
				this.posLastY = y; //same as above
			}
		}else{
			this.posLastY = y; //ok to set as we are not on 0 so not a fuckup
		}	
	
		StopEvent(e);	
	}
	if(debugCount==debugStep){
		debugCount = 0; //reset
	}else{
		debugCount++; //inc so we only show debug msgs every X steps on drag
	}
}

function StopDrag(e,id,objFloat) {
	if(!e) { e = window.event;}
	//ShowDebug("STOP DRAG REMOVE EVENTS FOR ID = "  + id)
	objFloat = getFloatObj(id,objFloat); //make sure we have a float object
	if(!objFloat){return;}

	objFloat.inMotion=false;
	objFloat.RemoveEvents();
}

