//timeout variable so it can be cleared when moving between menu divs
var delay = 900;
var twOut; //timer
var topServices = 16;
var leftHiddenMenu = -973;
var leftShowMenu = 0;

function init(){
	if($('servicesmenu')){	
		servicesMenu_mc = $('servicesmenu');
		servicesitem_mc = $('servicesitem');
		servicesitem_mc.onmouseover = moveSquareServices;
		servicesitem_mc.onmouseout = moveSquareServices;
		servicesMenu_mc.onmouseout = moveSquareServices;		
		servicesTweenHoriz = new Tween(servicesMenu_mc.style,'left','',parseInt(servicesMenu_mc.style.left),10,1,'px');
		servicesTweenVert = new Tween(servicesMenu_mc.style,'top','',parseInt(servicesMenu_mc.style.top),10,1,'px');
	}
	//if tabbed browsing, need to be able to click to remove menu
	document.onclick = moveSquareCloseAll;
}
function moveSquareServices(evt){
		var x,y;
		//alert(event.fromElement.id);
		if(!evt) evt = window.event;
		//alert(evt.type);
		if(evt.type=='mouseout')
		{			
			//if moving mouse out of menu give it a sec before closing the flyout
			// the clearTimeout is necessary for moving mouse from one div to the next
			//if the mouseevent is a click, don't timer it
			try{
			clearTimeout(twOut);
			twOut=setTimeout("moveSquareFuncServices(-973,16,'out')",1500);
			}catch(err){}
		}
		else
		{
			try{
			moveSquareFuncServices(leftShowMenu,topServices,'in');
			}catch(err){}			
		}
}
function moveSquareFuncServices(x,y,inOut) {
	var curX = tempX;
	var curY = tempY;
	//get the current loc of the centered main div Image
	//var xPosImage = $('image').offsetLeft;
	var xPosImage = $('container').offsetLeft;	
	var yPosImage = $('image').offsetTop;
//alert(inOut + ' --<>--- ' + curX + ' --<>--- ' + xPosImage);	
	//TEST TO SEE IF MOUSE IS OUTSIDE OF ALL 4 DIRECTIONS ! ! ! !		
	if(inOut=='in' || (((xPosImage > curX) || (curX > xPosImage + 245) || (curY < yPosImage) || (curY > yPosImage + 51) && inOut=='out'))) { 	
		var duration = 0.75; //$('myDuration').value;
		var easingFunc = eval(Tween.strongEaseOut);
		isNaN(duration) ? duration = 1 : null;
		servicesTweenHoriz.func = easingFunc;
		servicesTweenHoriz.continueTo(x,duration);
		servicesTweenVert.func = easingFunc;
		servicesTweenVert.continueTo(y,duration);
	}		
}

function moveSquareCloseAll(evt) {
	if(!evt) evt = window.event;
	if(evt.type=='click') 
	{
		try{
			moveSquareFuncServices(-973,16,'out');
		}catch(err){}
	}
}


// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + 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
  //document.Show.MouseX.value = tempX
  //document.Show.MouseY.value = tempY
  return true
}

