var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)

var tempX = 0
var tempY = 0
var dx = 0;
var dy = 0;
var activeEl = false;
var MOVE = false;
var MOVE_H = false;
var MOVE_V = false;

//function getMouseXY(e){
//}

function getMouseXY(e){  
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX;
    tempY = event.clientY;
		if(document.body)
		{
			tempX += document.body.scrollLeft;
			tempY += document.body.scrollTop;
		}
		//+ document.body.scrollLeft;
		//+ document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY  
  if( activeEl && MOVE ){     
    if( ( tempY - dy ) > 0 || activeEl.move_all ) activeEl.style.top = ( tempY - dy ) + 'px'; else activeEl.style.top = '0px'; 
    if( ( tempX - dx ) > 0 || activeEl.move_all ) activeEl.style.left = ( tempX - dx ) + 'px'; else activeEl.style.left = '0px';
    if( ( tempY - dy ) > ( activeEl.parentNode.offsetHeight - activeEl.offsetHeight ) && ! activeEl.move_all ) activeEl.style.top = activeEl.parentNode.offsetHeight - activeEl.offsetHeight + 'px';
    if( ( tempX - dx ) > ( activeEl.parentNode.offsetWidth - activeEl.offsetWidth ) && ! activeEl.move_all ) activeEl.style.left = activeEl.parentNode.offsetWidth - activeEl.offsetWidth + 'px';
    activeEl.cX = activeEl.offsetLeft / activeEl.parentNode.offsetWidth;
    activeEl.cY = activeEl.offsetTop / activeEl.parentNode.offsetHeight; 
    if( activeEl.onMove ) activeEl.onMove();  
  }
  if( activeEl && MOVE_H ){    
    activeEl.style.left = ( tempX - dx ) + 'px';   
    activeEl.cX = activeEl.offsetLeft / activeEl.parentNode.offsetWidth;     
    if( activeEl.onMove ) activeEl.onMove();  
  }
  if( activeEl && MOVE_V ){    
    activeEl.style.top = ( tempY - dy ) + 'px';           
    activeEl.cY = activeEl.offsetTop / activeEl.parentNode.offsetHeight;     
    if( activeEl.onMove ) activeEl.onMove();  
  }
  return true;
}

function px_to_int( v ){
  return Number( v.substr( 0, v.length - 2 ) );
}
function obj_move( e ){
  if( ! e ) e = this;
  MOVE = true;  
  dx = tempX - e.offsetLeft;  
  dy = tempY - e.offsetTop;
  activeEl = e;  		
}
function obj_move_h( e ){
  if( ! e ) e = this;
  MOVE_H = true;   
  dx = tempX - e.offsetLeft;  
  dy = tempY - e.offsetTop;
  activeEl = e;
}
function obj_move_v( e ){
  if( ! e ) e = this;
  MOVE_V = true;   
  dx = tempX - e.offsetLeft;  
  dy = tempY - e.offsetTop;
  activeEl = e;
}

document.onmousemove = getMouseXY;
