/*

	Animated Slide Show
	By Paul Dunning 2010

*/

var theObject;

function animationSkipTo( theObject , theNumber )
{
//	alert("The object: " + theObject);
	objectPos = theObject["objectPos"];
	
	thisItem = theObject[objectPos];
	
	fadeOut( theObject , thisItem , theNumber );
	
	return(theObject);
}

function animationStart( theObject )
{
	theObject["moving"] = true;
	objectPos = theObject["objectPos"];
	thisItem = theObject[objectPos];
	captionPos = theObject["captionPos"];
	slideShowHideTime = theObject["slideDelay"];
	slidePauseTime = theObject[thisItem]["duration"];
	theName = theObject["name"];
	theTitle = theObject["title"];
	theLink = theObject[thisItem]["link"];
	captionHeight = theObject["captionHeight"];
	
	slideItem = document.getElementById(thisItem);
	xMove = theObject[thisItem]["xMove"];
	yMove = theObject[thisItem]["yMove"];
	targetX = theObject[thisItem]["targetX"];
	targetY = theObject[thisItem]["targetY"];
	startScale = theObject[thisItem]["startscale"];
	endScale = theObject[thisItem]["endscale"];
	slideItem.style.left = targetX - xMove + "px";
	slideItem.style.top = targetY - yMove + "px";

	captionText = document.getElementById(theName+'_caption');
	captionText.innerHTML='<p class="' + theTitle + 'caption">' + theObject[thisItem]['caption'] + '</p>';
	bannerItem = document.getElementById( theTitle );
	
	bannerItem.setAttribute('onClick' , "");
	bannerItem.style.cursor="auto";
	
	myCaption = theName+'_caption';
	
	new Effect.Move(myCaption, { x: 0, y: captionPos, mode: 'absolute', duration:0 });
	
	paneDelay = slideShowHideTime - slidePauseTime;
	if (paneDelay<0)
		paneDelay = 0;
	
	new Effect.Parallel(
	[
	
		new Effect.Move(thisItem,
		{
			x: xMove,
			y: yMove,
			mode: 'relative',
			sync:true
		}),
		
		new Effect.Move(myCaption,
		{
			x: 0,
			y: -captionHeight,
			mode: 'relative',
			sync:true
		}),
		
		new Effect.Appear(thisItem ,
		{
			sync:true
		}),
		
		new Effect.Scale(thisItem, endScale ,
		{
			scaleFrom: startScale,
			scaleFromCenter: false,
			scaleContent: true,
			scaleMode: 'contents',
			sync:true
		})

	] ,
	{
		duration:slideShowHideTime ,
		afterFinish:function()
		{
		// loop through the tabs
			for (i=0; i<10; i++)
			{
				myTab = document.getElementById("position"+i);
				//alert(i + "  " + myTab);
				if (myTab)
				{
					if (i==objectPos)
					{
						myTab.addClassName('navActive');
						myTab.removeClassName('navTab');
					}
					else
					{
						myTab.removeClassName('navActive');
						myTab.addClassName('navTab');
					}
				}
			}
				
			if (theLink!="")
			{
				bannerItem.style.cursor="pointer";
				bannerItem.setAttribute('onClick' , 'document.location.href="'+theLink+'"');
			}

			new Effect.Move(myCaption,
			{
				x: 0,
				y: captionHeight,
				mode: 'relative',
				duration:slideShowHideTime,
				delay: paneDelay,
				afterFinish: function()
				{
					bannerItem.style.cursor="auto";
					bannerItem.setAttribute('onClick' , "");
					theObject = fadeOut( theObject , thisItem , false );
				}
			});
		

		}
	});

	return(theObject);
}

function fadeOut( myObject , thisItem , jumpTo )
{
	theDuration = myObject[thisItem]["duration"];
	caption = document.getElementById('caption');
	slideShowHideTime = myObject["slideDelay"];
	objectPos = myObject["objectPos"];
	objectCount = myObject["objectCount"];
	theName = myObject["name"];
	
	new Effect.Fade( thisItem , {
		duration:slideShowHideTime
	});
	
	if (!jumpTo)
	{
		objectPos = objectPos + 1;
		if (objectPos>objectCount)
			objectPos = 0;
	}
	else
	{
		objectPos = jumpTo;
		// need to kill all Scripty effects
	}


	myObject["moving"] = false;
	myObject["objectPos"] = objectPos;
	myObject["objectCount"] = objectCount;
	
	return( myObject );
}



