
var large_promo;

$(function() {
	
	large_promo = $("#large_promo");
	
	// select random promotion to show first
	var rand = Math.floor(Math.random()*3);
	changeLargePromo( $("#accordion div:eq(" + rand + ")") );
	beginCycle();
	$("#large_container").hover(endCycle, beginCycle);
	

	// Handle the click event
	$("#accordion a").click( function() {
		var cur = $(this).next();
		changeLargePromo(cur);
		return false;
	});
	
	
	$("#calendar").click( function() {
		window.location = "/calendar";
	});

});


// changing large promo
function beginCycle() {
	// add timing ability
	$(document).everyTime("6s", "cycle", function() {
		changeLargePromo();
	});
}

function endCycle() {
	$(document).stopTime("cycle");
}

function changeLargePromo(cur) {

	var old = $("#accordion div:visible");
	
	// go to next if cur not specified
	if (!cur) {
		if (old.prev().hasClass("last")) {
			cur = $("#accordion div:eq(0)");
		}
		else {
			cur = old.next().next();
		}
	}
	
	// Make sure the content that needs to be shown 
	// isn"t already visible
	if (cur.is(":visible")) {
		return;
	}

	
	promo_id = cur.attr("promo_id");
	image = cur.attr("image");

	large_promo.fadeOut("normal", function() {
		large_promo.css("background-image", "url('" + image + "')");
		large_promo.attr("promo_id", promo_id);
		large_promo.fadeIn("normal");
	});
	
	/*
	if (cur.prev().hasClass("first")) {
		old.hide();
		cur.slideDown("normal");		
	}
	else {
		cur.show();
		old.slideUp("normal");
	}
	*/
	
	old.hide();
	cur.show();
	
	cur.prev().addClass("active");
	old.prev().removeClass("active");
}


