function ckElementSlideMgr() {
	this.aElements = Array();
		
	this.slideSpeed=10;
		
	this.autoSequenceTimer = null;
	this.autoSequenceIndex = -1;
	this.autoSequenceDelay = 9000;
	this.sequenceCount = 0;
	this.maxSequenceCount = -1;
		
	this.startX = 0;
	this.startY = 0;
		
	this.fnAfterSlideIn = null;
	this.fnAfterSlideOut = null;
	
	this.bOverlap = false; //when sequencing, if overlap is false, the existing current will slide out before the new one slides in
	this.transitionDelay = 200; //when sequencing, how many ms to wait between time current slides out and new slides in
	
	this.displayAtZIndex = 30; //current slide will be set to default, outgoing slide will be set one less in case overlapping
	return this;
}
	
ckElementSlideMgr.prototype.setStartPos = function(startX,startY) { 
	this.startX = startX;
	this.startY = startY;
}
ckElementSlideMgr.prototype.setOverlap = function(bOverlap) {
	this.bOverlap = bOverlap;
	if (this.bOverlap) this.transitionDelay = 0;
}
ckElementSlideMgr.prototype.setTransitionDelay = function(ms) {
	this.transitionDelay = ms;
}
ckElementSlideMgr.prototype.setDisplayAtZIndex = function(zIndex) {
	this.displayAtZIndex = zIndex;
}
	
ckElementSlideMgr.prototype.autoSequence = function() {  //optional params: maxSequenceCount
	if (this.aElements.length > 0) {
		this.maxSequenceCount = (arguments.length >=1 ? arguments[0] : -1);
		this.autoSequenceIndex=-1;
		this.sequenceCount=0;
		this.continueAutoSequence();
	}
}
ckElementSlideMgr.prototype.continueAutoSequence = function() {
	this.slideInNext();

	if ((this.maxSequenceCount != -1) && (this.sequenceCount >= this.maxSequenceCount)) this.stopAutoSequence();		
	else this.autoSequenceTimer=setTimeout("oElementSlideMgr.continueAutoSequence()",this.autoSequenceDelay);
		
	this.sequenceCount++;
}
ckElementSlideMgr.prototype.stopAutoSequence = function() {
	clearTimeout(this.autoSequenceTimer);
}
/*------------------------------------------------------------------------------------*/	
ckElementSlideMgr.prototype.slideInNext = function() {
	var nextIndex = this.autoSequenceIndex + 1;
	if (nextIndex > (this.aElements.length-1)) nextIndex=0;
		
	this.slideIn(this.aElements[nextIndex].elementID);
}
ckElementSlideMgr.prototype.slideInPrev = function() {
	var prevIndex = this.autoSequenceIndex - 1;
	if (prevIndex < 0) prevIndex=this.aElements.length-1;
		
	this.slideIn(this.aElements[prevIndex].elementID);
}
/*------------------------------------------------------------------------------------*/
ckElementSlideMgr.prototype.slideInCurrent = function() {
	this.aElements[this.autoSequenceIndex].slideIn(this.startX);
	if (this.fnAfterSlideIn) this.fnAfterSlideIn();
}
ckElementSlideMgr.prototype.slideOutCurrent = function() {
	slideOut(this.autoSequenceIndex);
}
/*------------------------------------------------------------------------------------*/	

/*------------------------------------------------------------------------------------*/
ckElementSlideMgr.prototype.addElements = function(elementIDs) {
	var aIDs = elementIDs.split(",");
	for (var index=0; index < aIDs.length; index++) this.addElement(aIDs[index])
}
	
ckElementSlideMgr.prototype.addElement = function(elementID) {
	var iNewIndex = this.aElements.length
	this.aElements[iNewIndex] = new slideElementObj(iNewIndex,elementID,this.displayAtZIndex);
}
/*------------------------------------------------------------------------------------*/	
ckElementSlideMgr.prototype.callFnAfterSlideIn = function(fnPtr) {
	this.fnAfterSlideIn = fnPtr;
}
ckElementSlideMgr.prototype.callFnAfterSlideOut= function(fnPtr) {
	this.fnAfterSlideOut = fnPtr;
}
/*------------------------------------------------------------------------------------*/
ckElementSlideMgr.prototype.getShowingElementID = function() {
	return this.aElements[this.autoSequenceIndex].elementID; //useful for functions that are called after a slide and need to know what is showing
}
/*------------------------------------------------------------------------------------*/
ckElementSlideMgr.prototype.slideOut = function(index) {
	if (this.aElements[index]) {
		this.aElements[index].slideOut(this.bOverlap);
		if (this.fnAfterSlideOut) this.fnAfterSlideOut();
	}

}

ckElementSlideMgr.prototype.slideIn = function(elementID) {
	var slideOutIndex = this.autoSequenceIndex; //save what is currently showing so we can start slide in before sliding out. This prevents any gaps from appearing between sliding elements which is particularly noticeable when the elements have different backgrounds //this.slideOutCurrent(); 

	//find what we want from elementID passed in
	var oNextElement = null;
	var oElement;
	for (var index=0; index < this.aElements.length; index++) {	
		oElement=this.aElements[index];
		if (oElement.itemIndex != slideOutIndex) oElement.noDisplay(); //only important when overlapping
		if (this.aElements[index].elementID==elementID) oNextElement=oElement;
	}
	
	//slide out current
	if (this.transitionDelay > 0) this.slideOut(slideOutIndex); //with a delay, slide out old one immediately
		
	if (oNextElement) {
		this.autoSequenceIndex = oNextElement.itemIndex;
		
		if(this.transitionDelay==0) this.slideInCurrent();
		else setTimeout("oElementSlideMgr.slideInCurrent()",this.transitionDelay);

	}
		
	if (this.transitionDelay==0) setTimeout("oElementSlideMgr.slideOut(" + slideOutIndex + ")",50); //without a delay, slide out old one just slightly after new one starts
}
	
	
	
	
	
	
	
	
function slideElementObj(itemIndex,elementID,displayAtZIndex) {
	this.itemIndex = itemIndex;
	this.elementID = elementID; //don't do document.getElementById in this init so we can build the JS structure outside of onLoadActions. Get elements before each call
	this.varName = "oElementSlideMgr.aElements[" + this.itemIndex + "]";
	this.displayAtZIndex = displayAtZIndex;
	
	this.oEl = null
		
	this.leftX = 0;
	this.width = 0;
	this.halfPost = 0;
		
	this.bSlideIn = false;
		
	this.timer = null;

	return this;
}
slideElementObj.prototype.reInit = function() {
	if (this.oEl = document.getElementById(this.elementID)) {
		this.oEl.style.display="";
		this.oEl.style.zIndex = (this.bSlideIn ? this.displayAtZIndex : this.displayAtZIndex-1);
					
		var startX = (arguments.length==1 ? arguments[0] : this.oEl.style.left);
		this.oEl.style.left = startX;
			
		this.leftX = this.oEl.offsetLeft;
		this.width = this.oEl.offsetWidth; //clientWidth;
		this.halfPos = this.width / 2;
	}
}
slideElementObj.prototype.noDisplay = function() {
	if (this.oEl = document.getElementById(this.elementID)) {
		this.oEl.style.display="none";
	}
}	

slideElementObj.prototype.timedMove = function() {
	if (this.oEl) {
		this.leftX -= 15;
		this.oEl.style.left = this.leftX;
			
		if (this.bSlideIn) {
			if (this.leftX <=0) this.stopTimer();
			else this.timer=setTimeout(this.varName + ".timedMove()",5);
		} else {
			if (this.leftX < -(this.width)) this.stopTimer();
			else this.timer=setTimeout(this.varName + ".timedMove()",5);
		}
	}
}
	
slideElementObj.prototype.slideOut = function(bOverlap) {
	this.bSlideIn=false;
	this.reInit();
		
	if (!bOverlap) this.timedMove();
}
slideElementObj.prototype.slideIn = function(startX) {
	if (this.bSlideIn) return; //already showing
	
	this.bSlideIn=true;
		
	this.reInit(startX);
		
	this.timedMove();
}
	
	
slideElementObj.prototype.stopTimer = function() { 
	clearTimeout(this.timer);
	if (this.oEl) {
		if (this.bSlideIn) {
			this.oEl.style.left=0; //in case went past
			this.leftX = 0;
		} else this.oEl.style.display="none";
	}
}
	
