heroSlideshow = {
	current : 1,
	first : 1,
	last : 3,	
	timer : 0,
	moveNext : function() { 
		if(this.current < this.last) { 
			this.current++;
		} else {
			this.current=this.first;
		}
		this.activatePanel(document.getElementById('hero'+this.current+'Ctrl'));
	},
	activatePanel : function(a) {
		$('#controls a').removeClass('current'); 
        $(a).addClass('current');
        
        $('.heroImg').removeClass('current');
        $('.heroImg').hide();
        var hero = "#"+a.id.split('Ctrl')[0];
        $(hero).fadeIn("slow");
        $(hero).addClass('current');
		
		var pos = a.id.split('Ctrl')[0];
		var pos = pos.split('hero')[1];
		this.current=pos;
	},
	toggleAutoplay : function() {
		if ($('#controls .autoPlay').hasClass('play'))  {		
			$('#controls .autoPlay').removeClass('play');
			heroSlideshow.startAutoplay();
		}
		else {
			heroSlideshow.stopAutoplay();
		}
	},
	startAutoplay : function() {
		this.timer = setInterval('heroSlideshow.moveNext();',5000);
	},
	stopAutoplay : function() {
		clearInterval(this.timer);
		$('#controls .autoPlay').addClass('play');
	},	
	init : function() {
		$('#controls a').bind("click",function(e) {
			heroSlideshow.stopAutoplay();
			heroSlideshow.activatePanel(this);
	        e.preventDefault();
		});
		
		$('#controls .autoPlay').bind("click",function(e) {
			heroSlideshow.toggleAutoplay();
		});
		
		heroSlideshow.startAutoplay();
											  
	}
}


$(function() {
	heroSlideshow.init();
});

