/**
 * @author erick
 */
var serviceRotator = {
	//Array of anchor to rotate
	serviceArr:[
	"<a href='http://www.hotdreamweaver.com/installation-service' ><div class='banner-title'>Install Service</div><div class='usd'>USD 25</div></a>",
	"<a href='http://www.hotdreamweaver.com/full-website-development' ><div class='banner-title'>Full Website Development  from </div><div class='usd'>USD 150</div></a>",
	"<a href='http://www.d4wstats.com' ><div class='banner-title'>Web Stats Software</div><div class='usd'>USD 29.99</div></a>",
	"<a href='http://www.tsplayer.com/skin-design' ><div class='banner-title'>Custom Skin Design</div><div class='usd'>USD 149</div></a>",
	"<a href='http://www.topdreamweaverextensions.com/ie-firefox-cool-bar' ><div class='banner-title'>IE & Firefox Ad Bar</div><div class='usd'>Free</div></a>"
	],
	
	// Time in seconds showing the element
	staticTime:5,
	
	// Time in seconds of the duration to the animation
	fadeTime:1,
	
	start:function(container){
		var $A = YAHOO.util.Anim,
		$D = YAHOO.util.Dom,
		$E = YAHOO.util.Event,
		$U = YAHOO.util,
		hide,
		show,
		index = 0,
		containerE = $D.get(container);
		
		function hideService(){
			hide.animate();
		};
		
		function selectNext(){
			if(index+1 < serviceRotator.serviceArr.length){
				index++;
			}else{
				index = 0;
			}
			return index;
		};
		
		if(containerE){
			hide = new $A(containerE, 
				{ opacity: { to: 0 }}, 
				serviceRotator.fadeTime, 
				$U.Easing.easeOut
				);
		
			show = new $A(containerE, 
				{ opacity: { to: 1 }}, 
				serviceRotator.fadeTime, 
				$U.Easing.easeOut
				);	
			
			hide.onComplete.subscribe(function(){
				var i = selectNext();
				containerE.innerHTML = serviceRotator.serviceArr[i];
				show.animate();
			});
			
			show.onComplete.subscribe(function(){
				setTimeout(hideService, serviceRotator.staticTime*1000);
			});	
			
			setTimeout(function(){hide.animate();}, serviceRotator.staticTime*1000);
			
		}else{
			return;
		}
	}
}

YAHOO.util.Event.addListener(window, 'load', function(){
	// Set the id of the element that contain the elements
	serviceRotator.start('test');
});
