//this script will move the bubble on the homepage
browserVersion = parseInt(navigator.appVersion);
var tempX = 0;
var tempY = 0;

var IE = document.all?true:false;
var flag = false;
var velocity = .2;
var numLines = 1;
var horizArray = new Array();
var ComeOut;

if(!window.event && window.captureEvents) {
  // set up event capturing for mouse events (add or subtract as desired)
  window.captureEvents(Event.MOUSEMOVE|Event.CLICK|Event.MOUSEOFF);
  // set window event handlers (add or subtract as desired)
  window.onmouseover = WM_getCursorHandler;
  window.onmouseout = WM_getCursorHandler;
  window.onclick = WM_getCursorHandler;
  window.ondblclick = WM_getCursorHandler;
  window.onMouseMove = WM_getCursorHandler;
  // create an object to store the event properties 
  window.event = new Object;
}


function WM_getCursorHandler(e) {
  // set event properties to global vars (add or subtract as desired)
  window.event.clientX = e.pageX;
  window.event.clientY = e.pageY;
  window.event.x = e.layerX;
  window.event.y = e.layerY;
  window.event.screenX = e.screenX;
  window.event.screenY = e.screenY;
  // route the event back to the intended function
  if ( routeEvent(e) == false ) {
    return false;
  } else {
    return true;
  }
}

function init(){ // initialize a bunch of stuff
	if(browserVersion >= 4){
		// make an array of sliders
		var myVelocity = velocity
		for (var i = 0; i <= (numLines-1); i++){
			eval("slider_" + i + '= new makeSliders("sliderdiv",myVelocity)');
			horizArray[i] = "slider_" + i;
			myVelocity = myVelocity * .75;
			// fix the positioning
			
			if(netpoop){
				eval('document.sliderdiv.y -= 15');
			}
			
				
			if(macie5){
				eval('document.all.sliderdiv.style.pixelTop -= 0');
			}
			
			if(macie4){
				eval('document.all.sliderdiv.style.pixelTop += 7');	
			}
					//preload the slider images
			
			if(netpoop){
				eval('document.sliderdiv.document.images.slider' + i + '.src = "images/home-slider.gif"');
			} else {
				document.images['slider' + i].src = 'images/home-slider.gif';
			}
		}
		
		nodeWidth = 1;
		var nodeXPos = 0;
		
		for (var i = 0; i <= (horizArray.length - 1); i++){
			functionCall = horizArray[i] + '.moveMe()';
			setInterval(functionCall, 25);
		}
	}
}

function makeSliders(layerName,velocity){//get the layer properties
	if(netpoop){
	
		this.currentPos = eval('document.' + layerName + '.pageX');
	} else {
		this.currentPos = eval('document.all.'+ layerName +'.style.pixelLeft');
	} 
	this.layerName = layerName;
	this.velocity = velocity;
	this.origin = this.currentPos;
	this.destination = this.currentPos;
	this.length = 3;
	this.moveMe = mMoveMe;
	return this;
}

function mMoveMe(){
	if(browserVersion >= 4){

		//Now, figure out the new position;
		newPosition = Math.ceil(this.velocity * (this.destination - eval(this.currentPos)));
		if ((this.destination != this.currentPos) && (this.destination != 0)){
			this.currentPos = this.currentPos + newPosition;
			realName = this.layerName;
			
			nodePos = this.currentPos + newPosition;

			if(netpoop){
			eval('document.'+ this.layerName +'.pageX ='+ nodePos);
			}
			
			else{
			eval('document.all.'+ this.layerName +'.style.left ='+ nodePos);
			}
			
			
			
			// if the new position is less than one, set the new position to the destination
			if (Math.abs(newPosition) < 1){
				this.currentPos = this.destination;
			}
			
			// see if it is netscape, in which case, figure out the position differntly.
			if(netpoop){
				eval('document.'+ realName +'.pageX ='+ this.currentPos);
			} else {
				eval('document.all.'+ realName +'.style.left ='+ this.currentPos);
			}
		}
	}
	return true;
}


function getRealX(el) {
    xPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}

function getMouseXY(e) { // get the cursor coordinates
	if (IE) { // grab the x-y pos.s if browser is IE
		//alert(event)
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else {  // grab the x-y pos.s if browser is NS
		tempX = window.event.clientX;
		tempY = window.event.clientY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  

	return true;
}

//this will change the destination of the pointer to a new place.
function doIt(newButton){
	// we only have to do something if this is a 4 or greater browser
	if(browserVersion >= 4){
		// figure out if this is a vertical or horizontal move, and set the 
		// destination of the appropriate objects.
		if(netpoop){
			buttonX = eval('document.' + newButton.name + '.x');
		} else {
			buttonX = eval('document.' + newButton.name + '.offsetLeft');
		} 


			for (var i = 0; i <= (horizArray.length - 1); i++){

			
			//this will make sure the bubble is centered over the text
				if(newButton.name == 'about'){
	
					eval(horizArray[i] + '.destination = buttonX + 1');
				}
				
				if(newButton.name == 'capabilities'){
			
					eval(horizArray[i] + '.destination = buttonX + 8');
				}
				
				if(newButton.name == 'ourwork'){//this one looks ok, so i dont add or sutract anything
	
					eval(horizArray[i] + '.destination = buttonX');
				}
				
				if(newButton.name == 'press'){
					eval(horizArray[i] + '.destination = buttonX - 12');
				}
				
				if(newButton.name == 'funstuff'){
					eval(horizArray[i] + '.destination = buttonX - 1');
				}
				
				if(newButton.name == 'login'){
					eval(horizArray[i] + '.destination = buttonX + 5');
				}
				
				if(newButton.name == 'contact'){
					eval(horizArray[i] + '.destination = buttonX - 5');
				}
				

		}
	}
}
//this function (should) will detect if the mouse if over a slider.  If it is, then it will ignore //rolloffs
function onSlider(){
	//initialize the onslider variable
	var onSlider = false;
	// go through the list of horizontal sliders
		for (var i = 0; i <= (horizArray.length - 1); i++){
				eval('testLayer = ' + horizArray[i] + '.layerName');
				getMouseXY(document);
				mouseX = tempX;
				mouseY = tempY;
				if(netpoop){
					eval('testLayer_left = document.'+ testLayer +'.pageX');
					eval('testLayer_top = document.'+ testLayer +'.pageY');
					eval('testLayer_right = testLayer_left + document.'+ testLayer +'.clip.width');					
					eval('testLayer_bottom = testLayer_top + document.'+ testLayer +'.clip.height -3');
				} else {
					eval('testLayer_left = document.all.'+ testLayer +'.style.left');
					eval('testLayer_top = document.all.'+ testLayer +'.style.top');
					eval('testLayer_right = testLayer_left + document.all.'+ testLayer +'.style.width');
					eval('testLayer_bottom = testLayer_top + document.all.'+ testLayer +'.style.height');
				}

				// see if the mouse is inside the slider
				if (mouseY >= testLayer_top && mouseY <= testLayer_bottom && mouseX >= testLayer_left && mouseX <= testLayer_right){
					onSlider = true;
					break;
				}
			}
	//return the answer
	return onSlider
}
function GoBack(){
	if(browserVersion >= 4 && (!onSlider())){
		for (var i = 0; i <= (horizArray.length - 1); i++){
			eval(horizArray[i] + '.destination =  ' + horizArray[i] + '.origin');
		}
	}
}

