var banner_loop = false;
var banner_next = 0;

swapHerospace(Math.floor(Math.random()*$("#rotating_hero_frames div").length),1);

function swapHerospace(override_banner_next, speed){
	clearInterval(banner_loop);
	if(typeof(override_banner_next) != 'undefined'){
		banner_next = override_banner_next
	}
	if(typeof(speed) == 'undefined'){
		speed = 500
	}
	
	$("#rotating_hero_frames div").stop();
	$("#rotating_hero_frames div").each(function(index) {
		if(index==banner_next){
			$(this).css('display','block');
			$(this).animate({opacity:1}, speed*2);
		}else{
			$(this).animate({opacity:0}, speed,
				function(){$(this).css('display','none');});
		}
	});
	banner_next = (banner_next+1)%($("#rotating_hero_frames div").length);
	banner_loop = setInterval("swapHerospace()", 7000);
}

$("#rotating_hero_controls a").click(function(){
	var s = $(this).attr("href");
	s = s.replace("#slide-","");
	swapHerospace(s-1);
	return false;
});
