document.observe("dom:loaded", function() {
	
	rotateT1 = {
		current : 1,
		first : 1,
		last : 4,	
		timer : 0,
		moveNext : function() { 
			if(this.current < this.last) { 
				this.current++;
			} else {
				this.current=this.first;
			}
			this.activatePanel(document.getElementById('cnnEatHero'+this.current+'Ctrl'));
		},
		activatePanel : function(a) {
			$$('#cnnEatT1Controls li').each(function(el) {
				el.removeClassName('cnnT1Selected');
			}); 
			$(a).addClassName('cnnT1Selected');
			
			$$('.cnnEatT1Hero').each(function(el) {
				el.removeClassName('cnnEatT1Current');
				el.hide();
				//el.hide();
			});
			
			var hero = $(a).id.split('Ctrl')[0];
			
			$(hero).fade({ duration: 1.0, from: 0, to: 1});
			$(hero).show();
			/*
			$(hero).toggle("appear").show();
			*/
			//$(hero).addClassName('cnnEatT1Current');
						
			var pos = a.id.split('Ctrl')[0];
			pos = pos.split('cnnEatHero')[1];
			this.current=pos;
		},
		
		startAutoplay : function() {
			this.timer = setInterval('rotateT1.moveNext();',5000);
		},
		stopAutoplay : function() {
			clearInterval(this.timer);
		},	
		init : function() {
			
			$$('#cnnEatT1Controls li').each(function(el) {
				el.observe("click",function() {
					rotateT1.stopAutoplay();
					rotateT1.activatePanel(this);
				});
				
				el.observe("mouseover",function() {
					el.addClassName('over');
					
				});
				
				el.observe("mouseout",function() {
					el.removeClassName('over');
				});
			});
								
			
			$$('#cnnEatT1Controls a').each(function(a) {
			
				Event.observe(a, 'click', function(event) {
					var a = Event.findElement(event, 'a');
					if (!(a.parentNode.parentNode.hasClassName('cnnT1Selected'))) {
						event.preventDefault();
					}
				});
			});
			
			rotateT1.startAutoplay();
												  
		}
	}	
	
	if ($('cnnEatT1Controls')) {
		rotateT1.init();
	}
	
});
