mouseLocation =
{
	//values to hold x,y cordinates
	xLoc : 0,
	yLoc : 0,
	IE : null,
	xPlace : 0,
	yPlace : 0,
	width : 0,
	height : 0,
	widthOffset : 0,
	heightOffset : 0,
	
	
	isIE : function()
	{
		mouseLocation.IE = document.all?true:false;
		return mouseLocation.IE;
	},
	
	init : function()
	{
		if(this.IE != null)return;
		// Detect if the browser is IE or not.
		// If it is not IE, we assume that the browser is NS.
		mouseLocation.IE = document.all?true:false
		
		// If NS -- that is, !IE -- then set up for mouse capture
		if (!mouseLocation.IE) document.captureEvents(Event.MOUSEMOVE)
		
		// Set-up to use setMouseXY function onMouseMove
		document.onmousemove = mouseLocation.setMouseXY;
		return this;
	},
	setMouseXY : function(e)
	{
		if (mouseLocation.IE) { // grab the x-y pos.s if browser is IE
	    mouseLocation.xLoc = event.clientX + document.body.scrollLeft
	    mouseLocation.yLoc = event.clientY + document.body.scrollTop
	  } else {  // grab the x-y pos.s if browser is NS
	    mouseLocation.xLoc = e.pageX
	    mouseLocation.yLoc = e.pageY
	  }  
	  // catch possible negative values in NS4
	  if (mouseLocation.xLoc < 0){mouseLocation.xLoc = 0}
	  if (mouseLocation.yLoc < 0){mouseLocation.yLoc = 0} 
	  
	  
	  //var div = document.getElementById("tooltipMessage");
	  //mouseLocation.setToolTipPositionModal(div);
  	  
  	  
	  return true
	},
	getXLocation : function()
	{
		return mouseLocation.xLoc;
	},
	getYLocation : function()
	{
		return mouseLocation.yLoc;
	},
	setScreenDimentions : function()
	{
		if(mouseLocation.IE == null)
			this.isIE();
		if(mouseLocation.IE)
		{
			
			//define reference to the body object in IE
			var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;

			mouseLocation.height = document.documentElement.clientHeight;
			mouseLocation.width = document.documentElement.clientWidth;
			if(mouseLocation.height == 0)
			{
				mouseLocation.height = document.body.clientHeight;
				mouseLocation.width = document.body.clientWidth;
			}
			
			mouseLocation.heightOffset =  iebody.scrollTop;
			mouseLocation.widthOffset =  iebody.scrollLeft;
		}
		else
		{
			mouseLocation.height = window.innerHeight;
			mouseLocation.width = window.innerWidth;
			mouseLocation.heightOffset = pageYOffset;
			mouseLocation.widthOffset = pageXOffset;
			
		}
	},
	//this.setToolTipPositionGeneric(obj,mouseLocation.height,mouseLocation.width,mouseLocation.yLoc,mouseLocation.xLoc,mouseLocation.heightOffset,mouseLocation.widthOffset);
	setToolTipPositionGeneric : function (obj,height,width,yLoc,xLoc,heightOffset,widthOffset,isModal){
		
		//var message = "<br> width="+mouseLocation.width+" height="+mouseLocation.height+
		//"<br>Corrected: width="+width+" height="+height+
		//"<br>widthOffset="+mouseLocation.widthOffset+" heightOffset="+mouseLocation.heightOffset+
		//"<br>"+mouseLocation.xLoc+","+mouseLocation.yLoc+"<br>Corrected Location:"+xLoc+","+yLoc;
		//message +="<br> Style: top="+obj.style.top+" bottom="+obj.style.bottom;
		//message +="<br> left="+obj.style.left+" right="+obj.style.right;
		//obj.innerHTML=message; 
		
		
		
		obj.style.top="";
		obj.style.left="";
		obj.style.right="";
		obj.style.bottom="";
		
		
		var isTop = false;
		var isLeft = false;
		var widthOrig = width;
		var heightOrig = height;
		height = height/2;
		width = width/2;
		
		if(!mouseLocation.IE && !isModal)
		{
			height = height+ heightOffset;
			width = width+widthOffset;
		}
		
		if(isModal){
			if(mouseLocation.IE){
				isTop = heightOrig/2 > yLoc;
				yLoc = yLoc-heightOffset;
			}else{
				yLoc = yLoc-heightOffset;
				isTop = height > yLoc;
			}
			isLeft = widthOrig/2 > xLoc;
		}else{
			isTop = height > yLoc;
			isLeft = width > xLoc;
		}
		
		
		var styleRight = (widthOrig-xLoc)+"px";
		var styleBottom = mouseLocation.IE? heightOrig - heightOffset-yLoc+5 :  (heightOrig-yLoc)+5;
		styleBottom +="px";
		var styleTop = mouseLocation.IE? yLoc+heightOffset+5 : yLoc+5;
		styleTop+="px";
		var styleLeft = xLoc+"px";
		
		
		if(isTop)
		{
			obj.style.top=styleTop;
		}
		else
		{
			obj.style.bottom=styleBottom;
		}
		if(isLeft)
		{
			obj.style.left=styleLeft;
		}
		else
		{
			obj.style.right=styleRight;
		}
	},
	setToolTipPosition : function(obj)
	{
		this.setScreenDimentions();
		this.setToolTipPositionGeneric(obj,mouseLocation.height,mouseLocation.width,mouseLocation.yLoc,mouseLocation.xLoc,mouseLocation.heightOffset,mouseLocation.widthOffset,false);
	},
	setToolTipPositionModal : function (obj){
		this.setScreenDimentions();
		var height = mouseLocation.height*.5;
		var width = mouseLocation.width*.5;
		var modal = components.modals.active;
		if(modal==null){
			alert("mouseLocation setToolTipPostionModal : Modal is null");
			return;
		}
		
		var marginTop = parseInt(modal.dialog.style.marginTop);
		var marginLeft = parseInt(modal.dialog.style.marginLeft);
		
		height += marginTop;
		width += marginLeft;
		var yLoc = mouseLocation.yLoc-height;
		var xLoc = mouseLocation.xLoc-width
		//alert("yLoc = "+yLoc+" xLoc= "+xLoc+" height= "+height+" width= "+width);
		//width offset 0 since I don't believe modals scroll.
		var specialWidth = parseInt(modal.content.style.width)
		width = parseInt(modal.dialog.offsetWidth);
		if(!isNaN(specialWidth)){
			width = specialWidth;
		}
		height = -2*marginTop;
		this.setToolTipPositionGeneric(obj,height,width,yLoc,xLoc,mouseLocation.heightOffset,mouseLocation.widthOffset,true);
	},
	displayCenterOfScreen: function(obj,width,height)
	{
		this.setScreenDimentions();
		var w = this.width/2;
		var h = this.height/2;
		width = width/2;
		height = height/2;
		
		width = w-width;
		height = h-height;
		
		obj.style.top=height+"px";
		obj.style.left=width+"px";
	}
}
