$(function(){
	// Let the presence of the mighty hero module be known to the other promos!
	$("#moduleslot1, #moduleslot3").each(function(i){
		$(this).addClass("promo-hero-present");
	});
});
$(window).load(function(){

	$(".hero-970x430 h5").css("visibility","hidden");	

	$(".hero-970x430").each(function(i){
		var data = this.moduleProperties;
		var promo = this;
		
		$(".next:first", this).attr("id", "HNextButton"+i);
		$(".previous:first", this).attr("id", "HPrevButton"+i);
		$(".buttons", this).attr("id", "goHButton"+i);

		if (data.btngo) {
				$(data.btngo).each(function(t) {
					data.btngo[t] = "#goHButton" + i + data.btngo[t];
				});
		}
		var promoCopyInit = $("h5.promoCopy:first", this).text();
		$("td.buttonsdesc", this).fadeTo(1, 0).text(promoCopyInit).fadeTo(400, 1);					

		$(".promoList", this).jCarouselLite({
			auto : data.auto,
			btnNext : "#" + "HNextButton" + i,
			btnPrev : "#" + "HPrevButton" + i,
			circular : true,
			screenTime : data.screenTime,
			scroll : 1,
			speed : data.speed,
			start : 0,
			vertical : false,
			visible : 1,
			btnGo : data.btngo,
			
			beforeStart: function(a) {
				$("td.buttonsdesc", promo).fadeTo(100, 0); $(a).siblings(a).not(a).css("visibility","visible");
			},
			afterEnd: function(a) {
				var copyCopy = $("h5.promoCopy",a).text();
				$("td.buttonsdesc", promo).text(copyCopy).fadeTo(400, 1); $(a).siblings(a).not(a).css("visibility","hidden");
			}
		});
		
		$("li", this).css("visibility","hidden").filter("li:eq(1)", this).css("visibility","visible"); 
		
	});
});

