/* a cross fade animation using the motion tween library opacity function */

var frames ; 
var frameIndex = 0 ; 
var fadeDuration = 2; 
var pauseBetweenFrames = 3; 

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	// alert ("the number of elements in the class is " + classElements.length) ; 
	return classElements;
}



function initAnimation() {
	//alert("initting animation") ;

	/* THIS FUNCTION IS CALLED ON LOAD */
	/* ADD HOVER EFFECT ON LOAD IN IE6 */
	if (document.all&&document.getElementById) {
	navRoot = document.getElementById("primary-nav");
	for (i=0; i<navRoot.childNodes.length; i++) {
	node = navRoot.childNodes[i];
	if (node.nodeName=="LI") {
	node.onmouseover=function() {
	this.className+=" over";
	  }
	  node.onmouseout=function() {
	  this.className=this.className.replace(" over", "");
	   }
	   }
	  }
	 }
	
	// END HOVER IE6 
	frames = getElementsByClass('fader', null, 'img')  ;
	crossFadeBetweenItems();
}	


function crossFadeBetweenItems() {
	//alert("cross fading animation") ;
		
	var seq = new Sequence() ;	
	//alert("cross fading animation 2") ;
	//stepArray = new Array; 
	// fade in the new item
	var clientName = document.getElementById("clientName");
	var serviceBullet1 = document.getElementById("serviceBullet1");
	var serviceBullet2 = document.getElementById("serviceBullet2");
	var serviceBullet3 = document.getElementById("serviceBullet3");
	var dummy = document.getElementById("dummy");
	
	/* construct a pause to be used */
	var pause = new Tween(dummy.style,'width',Tween.regularEaseIn,10,20,pauseBetweenFrames,'px') ;
	
	//alert("number of frames is "+frames.length) ;
	for (i= 0 ; i < frames.length; i++) {
		var item = frames[ i ] ;
		//alert("frame number is " + i );
		bullets = item.title.split('+'); 
		//alert("bullet count is " + bullets.length );

		var step = new Parallel() ;
		var teletype = new Sequence;
		step.addChild( new OpacityTween(item,Tween.regularEaseOut,0,100,fadeDuration)    ) ;
		teletype.addChild( new TextTween(clientName.firstChild, 'nodeValue', item.alt, Tween.regularEaseIn, 2)  );
		teletype.addChild( new TextTween(serviceBullet1.firstChild, 'nodeValue', bullets[0], Tween.regularEaseIn, 2)  );
		teletype.addChild( new TextTween(serviceBullet2.firstChild, 'nodeValue', bullets[1], Tween.regularEaseIn, 2)  );
		teletype.addChild( new TextTween(serviceBullet3.firstChild, 'nodeValue', bullets[2], Tween.regularEaseIn, 2)  );
		step.addChild(teletype) ;
		seq.addChild(step) ;
		seq.addChild(pause) ;
	}
	seq.start() ;
	
	// use onMotionFinished property to set up repeat
	seq.onMotionFinished = function(){this.start()};
	seq.start();
}





