var tabOpen = '';
var tabWaiting = '';
var tabInMotion = '';
var sayTabOpen = function(openElement){
	tabOpen = openElement;
	document.getElementById(openElement.id+'Sub').style.visibility = 'visible';
	tabInMotion = '';
}
var sayTabClosed = function(closedElement){
	tabOpen = '';
	tabInMotion = '';
	if (tabWaiting != ''){
		makeItMove(tabWaiting);
	}
}
function goAway(){

}

var makeItMove = function(theElement, isCall){
	if (tabInMotion == true){
		goway();
	} else {
		if (isCall == true){
			theElement = document.getElementById(theElement);
		}
		var moveLeft=function(theElement){
			var elementIsOpen = function(){
				sayTabOpen(theElement);
			}
			var theDistance = theElement.offsetWidth-172;
			var moveItLeft  = new YAHOO.util.Motion(theElement, {points: { by: [-theDistance, 0] }}, .5, YAHOO.util.Easing.easeBoth);
			moveItLeft.onComplete.subscribe(elementIsOpen); 
			tabInMotion = theElement;
			moveItLeft.animate();
		}
		
		var moveRight=function(theElement){
			var elementIsClosed = function(){
				sayTabClosed(theElement);
			}
			var theDistance = theElement.offsetWidth-172;
			moveItRight  = new YAHOO.util.Motion(theElement, {points: { by: [theDistance, 0] }}, .5, YAHOO.util.Easing.easeBoth);
			moveItRight.onComplete.subscribe(elementIsClosed); 
			tabInMotion = theElement;
			document.getElementById(theElement.id+'Sub').style.visibility = 'hidden';
			moveItRight.animate();
		}
		if (tabOpen != '' && tabOpen != theElement && tabInMotion ==''){
			tabWaiting = theElement;
			moveRight(tabOpen);
		} else if (tabOpen == '' && tabInMotion ==''){
			moveLeft(theElement);
		}
	}
}
/*//////////////////////*/

var makeItJump = function(theElement){
			theElement = document.getElementById(theElement);
		var jumpLeft=function(theElement){
			var elementIsOpen = function(){
				sayTabOpen(theElement);
			}
			var theDistance = theElement.offsetWidth-172;
			theStart = theElement.offsetLeft;
			theElement.style.left = eval(theStart - theDistance)+'px';
			elementIsOpen(); 
		}
        jumpLeft(theElement);
}
/////////////////////////////
function colorMe(element, color){
	if (element.id != tabOpen.id){
		document.getElementById(element.id+'Text').style.color = color;
	}
}
function setSubNav(subNavElement){
	//subNavTarget = document.getElementById(subNavElement+'Sub');
	//subNavTarget.class += 'Active';
	//document.getElementById(subNavTarget).class += 'Active';
	
}
//////////////////////////////////////////////////////////////////////////
function theScrolling(nullVar){
	this.getYPos=function(theElement){
			theYApparent = YAHOO.util.Dom.getY(theElement);
			
				theYActual = eval(theYApparent - zeroModifier);
			
			//alert(theYActual);
			return theYActual;
		}
		
		var scrollMoving = false;
	
	 this.sayMoveFalse=function(){
		scrollMoving = false;
	}
	
	
	this.getXPos=function(theElement){
			theXApparent = YAHOO.util.Dom.getX(theElement);
			
				theXActual = eval(theXApparent - zeroModifier);
			
	 //alert(zeroModifier);
			//alert(theYActual);
			return theXActual;
		}
		
		var scrollMoving = false;
	
	 this.sayMoveFalse=function(){
		scrollMoving = false;
	}
	
	
	 this.moveUp=function(theElement){
	  moveItUp  = new YAHOO.util.Motion(theElement, {points: { by: [0, -moveDistance] }}, .5, YAHOO.util.Easing.easeOut);
		 theYPos = this.getYPos(theElement);
		 //alert('this time: '+theYPos);
		 //alert(theCopyHeight);
		 //alert();
		 if (eval(theCopyHeight+theYPos) > copyContainerHeight && scrollMoving == false){
			scrollMoving = true;
	moveItUp.onComplete.subscribe(this.sayMoveFalse);
			moveItUp.animate();
			}
	}
	 this.moveDown=function(theElement){
		  moveItDown = new YAHOO.util.Motion(theElement, {points: { by: [0, moveDistance] }}, .5, YAHOO.util.Easing.easeOut);
		 theYPos = this.getYPos(theElement); 
		 if (theYPos < 0 && scrollMoving == false){
			 scrollMoving = true;
	moveItDown.onComplete.subscribe(this.sayMoveFalse);
			moveItDown.animate();
			}
	}
	 this.moveLeft=function(theElement){
	  moveItUp  = new YAHOO.util.Motion(theElement, {points: { by: [-moveDistance, 0] }}, .5, YAHOO.util.Easing.easeOut);
		 theXPos = this.getXPos(theElement);
		 if (eval(theCopyHeight+theXPos) > copyContainerHeight && scrollMoving == false){
			scrollMoving = true;
	moveItUp.onComplete.subscribe(this.sayMoveFalse);
			moveItUp.animate();
			}
	}
	 this.moveRight=function(theElement){
		  moveItDown = new YAHOO.util.Motion(theElement, {points: { by: [moveDistance, 0] }}, .5, YAHOO.util.Easing.easeOut);
		 theXPos = this.getXPos(theElement);
		 if (theXPos < 0 && scrollMoving == false){
			 scrollMoving = true;
	moveItDown.onComplete.subscribe(this.sayMoveFalse);
			moveItDown.animate();
			}
	}
	
	 this.doScrollButtons=function(whichCopy, whichContainer, whichMoveDistance, whichPage){
		theCopy = document.getElementById(whichCopy);
		theCopyHeight = theCopy.offsetHeight;
		copyContainer = document.getElementById(whichContainer);
		copyContainerHeight = copyContainer.offsetHeight;
		//alert(whichContainer);
		zeroModifier = YAHOO.util.Dom.getY(whichContainer);
			moveDistance = whichMoveDistance;
		//alert(theCopy);
			if (theCopyHeight > copyContainerHeight){
				document.getElementById(whichPage+"UpButton").style.visibility = 'visible';
				document.getElementById(whichPage+"DownButton").style.visibility = 'visible';
		}
	}
	 this.doHorizScroll=function(whichCopy, whichContainer, whichMoveDistance, whichPage){
		theCopy = document.getElementById(whichCopy);
		theCopyHeight = theCopy.offsetWidth;
		//alert(theCopyHeight);
		copyContainer = document.getElementById(whichContainer);
		copyContainerHeight = copyContainer.offsetWidth;
		//alert(whichContainer);
		zeroModifier = YAHOO.util.Dom.getX(whichContainer);
			moveDistance = whichMoveDistance;
		//alert(theCopy);
			if (theCopyHeight > copyContainerHeight){
				document.getElementById(whichPage+"LeftButton").style.visibility = 'visible';
				document.getElementById(whichPage+"RightButton").style.visibility = 'visible';
		}
	}
}