Yevent	= YAHOO.util.Event;
Ydom	= YAHOO.util.Dom;
Yanim	= YAHOO.util.Anim;

SCM_frontpage = function(){

	return{
		init: function(){
			Yevent.onContentReady('image_container', this.rotate_images);
		},

		rotate_images: function(){
			var container	= Ydom.get('banner');
			var counter		= 2;
			setInterval(function(){
				SCM_frontpage.fade_out(container, counter);

				if(counter == 6){counter = 0;}
				counter++;
			}, 5000);
		},

		fade_in: function(el){
			var image_in = new Yanim(el, {opacity: {to: 1.0}});
			image_in.animate();
		},

		fade_out: function(el, image){
			var image_out = new Yanim(el, {opacity: { to: 0 }});
			image_out.onComplete.subscribe(function(){
				Ydom.setStyle(el, 'backgroundImage', 'url(\'/css/frontend/images/carousel/' + image + '.jpg\')');
				SCM_frontpage.fade_in(el);
			})
			image_out.animate();
		}
	}

}();

SCM_frontpage.init();