SiblingElementIdCollection = new ForteClass
(
	function(options)
	{
		this.data=
		{
			 elementIdStorageArray	: []
			,currentIndex			: 0
			,lastIndex				: 0
			,isInfinitLoopMode		: 0//when last element reached, rotates back around
			,isLastChangeLooped		: 0//recorded of when a loop occurs
			,isDebugMode			: 0
		}
		jQuery.extend(this.data, options);//same as structAppend() in ColdFusion
		return this
	},'SiblingElementIdCollection'
)

SiblingElementIdCollection.prototype.setElementId = function(id)
{this.data.elementIdStorageArray.push(id)}

SiblingElementIdCollection.prototype.getLength = function()
{return this.data.elementIdStorageArray.length}

SiblingElementIdCollection.prototype.isLastChangeForward=function()
{
	if(this.isLastChangeFowardLooped())
		return true;

	if(this.isLastChangeReverseLooped())
		return false;

	if(this.data.currentIndex > this.data.lastIndex)
		return true;
	
	return false
}

SiblingElementIdCollection.prototype.isCurrentIndex = function(n)
{return (n == this.data.currentIndex)}

SiblingElementIdCollection.prototype.isLength = function(n)
{return (n == this.data.elementIdStorageArray.length)}

SiblingElementIdCollection.prototype.isLastChangeLooped = function()
{return this.data.isLastChangeLooped}

SiblingElementIdCollection.prototype.isLastChangeFowardLooped = function()
{return this.data.isLastChangeLooped == 1}

SiblingElementIdCollection.prototype.isLastChangeReverseLooped = function()
{return this.data.isLastChangeLooped == 2}

SiblingElementIdCollection.prototype.getByIndex = function(n,setAsPosition)//all methods transcend into using this method (for the most part)
{
	this.data.lastIndex = this.data.currentIndex;

	if(setAsPosition==null || setAsPosition)
	{
		this.data.currentIndex = n;

		if(this.data.isInfinitLoopMode)
		{
			if(this.isLength(this.data.currentIndex))
			{
				this.data.currentIndex=0;
				this.data.isLastChangeLooped = 1;
			}else if(this.data.currentIndex < 0)
			{
				this.data.currentIndex=this.data.elementIdStorageArray.length-1;
				this.data.isLastChangeLooped = 2;
			}else
				this.data.isLastChangeLooped = 0;
		}else
			this.data.isLastChangeLooped = 0

		this.log('Position Index Now: '+this.data.currentIndex)
	}

	return this.data.elementIdStorageArray[n]
}

SiblingElementIdCollection.prototype.getCurrentIndex = function()
{return this.data.currentIndex}

SiblingElementIdCollection.prototype.getCurrent = function()
{return this.getByIndex(this.data.currentIndex,false)}

SiblingElementIdCollection.prototype.getNext = function(setAsPosition)//returns the next element id in memory
{return this.getByIndex(this.data.currentIndex+1,setAsPosition)}

SiblingElementIdCollection.prototype.getPrevious = function(setAsPosition)
{return this.getByIndex(this.data.currentIndex-1,setAsPosition)}

SiblingElementIdCollection.prototype.getLast = function(setAsPosition)
{return this.getByIndex(this.data.elementIdStorageArray.length-1,setAsPosition)}

SiblingElementIdCollection.prototype.getFirst = function(setAsPosition)
{return this.getByIndex(0,setAsPosition)}

SiblingElementIdCollection.prototype.getCurrentElement = function()
{return document.getElementById(this.getCurrent())}

SiblingElementIdCollection.prototype.nextElement = function(setAsPosition)//returns the next element id in memory
{return document.getElementById(this.getNext(setAsPosition))}

SiblingElementIdCollection.prototype.previousElement = function(setAsPosition)
{return document.getElementById(this.getPrevious(setAsPosition))}

SiblingElementIdCollection.prototype.getElementByIndex = function(n,setAsPosition)
{return document.getElementById(this.getByIndex(n,setAsPosition))}

SiblingElementIdCollection.prototype.getFirstElement = function(setAsPosition)
{return this.getElementByIndex(0,setAsPosition)}

SiblingElementIdCollection.prototype.getLastElement = function(setAsPosition)
{return this.getElementByIndex(this.data.elementIdStorageArray.length-1,setAsPosition)}

SiblingElementIdCollection.prototype.getLastUsedElement = function(setAsPosition)//back to last used
{return this.getElementByIndex(this.data.lastIndex,setAsPosition)}








SiblingElementFadeAnimator = new ForteClass
(
	function(SiblingElementIdCollection,options)
	{
		this.data=
		{
			 transitionSpeed	: 400
			,transitionType		: 'fade'
		}

		this.SiblingElementIdCollection = SiblingElementIdCollection;
		this.parentElement				= jQuery(SiblingElementIdCollection.getFirstElement(false).parentNode);
	
		jQuery.extend(this.data, options);//same as structAppend() in ColdFusion
	
		var local = {nodeCount:this.SiblingElementIdCollection.getLength()}
	
		for(local.elmIndex=0; local.elmIndex < local.nodeCount; ++local.elmIndex)
		{
			local.div = jQuery(document.createElement('div'));
			local.div.append(this.SiblingElementIdCollection.getElementByIndex(local.elmIndex,false));
			local.div.attr('id','fadeContainer').css('position','absolute').css('z-index',local.nodeCount-local.elmIndex);
			this.parentElement.append(local.div);
		}
	},'SiblingElementFadeAnimator'
)

SiblingElementFadeAnimator.prototype.animate = function(transitionSpeed)
{
	var local = {}

	if(transitionSpeed==null)
		transitionSpeed = this.data.transitionSpeed;

	local.DivCurrentElement = this.SiblingElementIdCollection.getLastUsedElement(false).parentNode;
	local.divCurrent = jQuery(local.DivCurrentElement);
	local.DivTargetElement = this.SiblingElementIdCollection.getCurrentElement().parentNode;
	local.divTarget = jQuery(local.DivTargetElement);
	local.nodeCount = this.SiblingElementIdCollection.getLength();
	local.divCurrent.css('z-index',local.nodeCount+2)
	local.divTarget.css('z-index',local.nodeCount+1).show();

	if(this.data.transitionType == 'fadeSlide')
		local.divCurrent.hide(transitionSpeed,function(){local.divTarget.show()});
	else
		local.divCurrent.fadeOut(transitionSpeed,function(){local.divTarget.show()});
}








SiblingElementSlideAnimator = new ForteClass
(
	function(SiblingElementIdCollection,options)
	{
		this.data=
		{
			 imageWidth			: 0
			,transitionSpeed	: 400
		}

		this.SiblingElementIdCollection = SiblingElementIdCollection;
		this.parentElement				= jQuery(SiblingElementIdCollection.getFirstElement(false).parentNode);

		jQuery.extend(this.data, options);//same as structAppend() in ColdFusion
	
		var local = {};
	
		local.CMover = document.createElement('DIV')
		local.jCMover = jQuery(local.CMover).addClass('ForteCarouselContainerMover').css('left',0);
		local.jCMover.css('position','absolute').css('top','0px')
		this.parentElement.append(local.CMover);
	
		for(local.nodeIndex=0; local.nodeIndex < this.SiblingElementIdCollection.getLength(); ++local.nodeIndex)
			local.jCMover.append(this.SiblingElementIdCollection.getElementByIndex(local.nodeIndex,false))
	
		/* ensure no wrapping occurs */
			local.totalWidth = this.data.imageWidth * this.SiblingElementIdCollection.getLength()//get width of all slides combined
			local.jCMover.css('width',local.totalWidth);
		/* end */
	},'SiblingElementSlideAnimator'
)

SiblingElementSlideAnimator.prototype.animate = function(transitionSpeed)
{
	var local = {cMoverArray:jQuery('div.ForteCarouselContainerMover',this.parentElement)};

	if(transitionSpeed==null)
		transitionSpeed = this.data.transitionSpeed;

	local.CMover = local.cMoverArray[0]
	local.jCMover = local.cMoverArray;

	if(this.SiblingElementIdCollection.isLastChangeFowardLooped())//? requested index greater than number of items?
	{
		local.jCMover.css('left',0)
		/* append all but the last element */
			for(local.nodeIndex=0; local.nodeIndex < this.SiblingElementIdCollection.getLength()-1; ++local.nodeIndex)
				local.jCMover.append( this.SiblingElementIdCollection.getElementByIndex(local.nodeIndex,false));
		/* end */

		local.amount = -this.data.imageWidth;
	}else if(this.SiblingElementIdCollection.isLastChangeReverseLooped())
	{
		/* prepend all but the first element */
			local.objArray = jQuery('li',local.CMover)
			for(local.nodeIndex=local.objArray.length; local.nodeIndex > 0; --local.nodeIndex)
				local.jCMover.prepend(local.objArray[local.nodeIndex]);
		/* end */
		local.leftAmount = this.data.imageWidth * (this.SiblingElementIdCollection.getLength()-1);
		local.jCMover.css('left', -local.leftAmount)
		local.amount = this.data.imageWidth;
	}else
	{
		if(this.SiblingElementIdCollection.isLastChangeForward())
			local.amount = -this.data.imageWidth * (this.SiblingElementIdCollection.data.currentIndex-this.SiblingElementIdCollection.data.lastIndex);
		else
			local.amount = this.data.imageWidth * (this.SiblingElementIdCollection.data.lastIndex-this.SiblingElementIdCollection.data.currentIndex);
	}

	local.amount = local.amount + parseInt(local.CMover.style.left);

	/*
		//great easing plugging
		<script type="text/javascript" language="Javascript" src="http://buildinternet.com/live/smoothmenu/js/jquery.easing.1.3.js"></script>
		//local.jCMover.animate({left:local.amount}, {queue:false, duration:this.data.transitionSpeed, easing:'easeOutQuint', complete:this.getMethodCallback(this.containSlideComplete)}, 'linear')
	*/

	if(transitionSpeed==0)//?are we just performing a warm-up of a once thru to ensure the browser has everything loaded?
	{
		jQuery('div.ForteCarouselContainerMover',this.parentElement).css('left',local.amount)
		this.containSlideComplete();
	}else
		local.jCMover.animate({left:local.amount}, transitionSpeed, 'linear', this.getMethodCallback(this.containSlideComplete))
}

SiblingElementSlideAnimator.prototype.containSlideComplete = function()
{
	var local = {}

	if(this.SiblingElementIdCollection.isLastChangeFowardLooped())//?did we just shift nodes around to create an infinite loop?
	{
		local.jCMover = jQuery('div.ForteCarouselContainerMover',this.parentElement)
		local.jCMover.append(this.SiblingElementIdCollection.getLastElement(false));//The third element is pretending to be the first, put him back at the end
		local.jCMover.css('left',0);
		this.log('Slide Container Div Left Style: '+0);
	}else if(this.SiblingElementIdCollection.isLastChangeReverseLooped())//?did we just shift nodes around to create an infinite loop?
	{
		local.jCMover = jQuery('div.ForteCarouselContainerMover',this.parentElement)
		/* The first node is pretending to be the last node, lets put it back where it needs to be */
			local.nodes = this.SiblingElementIdCollection.getFirstElement(false);
			local.jCMover.prepend(local.nodes);
			local.leftAmount = this.data.imageWidth * (this.SiblingElementIdCollection.getLength()-1)
			local.jCMover.css('left', -local.leftAmount);
		/* end */
		this.log('Slide Container Div Left Style: '+(-local.leftAmount));
	}
}
