$().ready( function() {
	$("div.accordion").each( function() {
		//add classes to the accordion element and the first and last children
		$(this).addClass("accordionEnabled");
		$(this).find(">div:first-child").addClass("first");
		$(this).find(">div:last-child").addClass("last");
		
		//find the total size of all headers except the first one (the first one is taken into account already) - this is to set other sizes and positions takig account of the accordion headers
		var modContainers = $(this).find("div.modContainer"),
			headerHeights = 0;
		for (var i = 1, j = modContainers.length; i<j; i++) {
			var header = $(modContainers[i]).find("div.hd")[0];
			if (!header) continue;
			headerHeights += header.offsetHeight;
		}
		//go through the promos and set their heights and the button positions
		modContainers.each( function() {
			var body = $(this).find("div.bd");
			var button = $(this).find("a.button");
			if (body.length > 0) {
				var newHeight = (parseInt(body.css("height")) - parseInt(body.css("paddingTop")) - parseInt(body.css("paddingBottom")) ) - headerHeights;
				body.css("height", newHeight + "px");
				var newButtonPos = parseInt(button.css("top")) - headerHeights;
				button.css("top", newButtonPos + "px");
			}
		} );
	} );
	$(".accordion").accordion( { header: '.hd', event: "mouseover", animated: "easeslide" } );
} );
$.extend($.ui.accordion.animations, {
	easeslide: function(options) {
		$.ui.accordion.animations.slide(options, { easing: "easeInOutQuad", duration: 700 } ) }
	}
);

