Array.prototype.arrayIndex = function(m) {
	var i = 0;
	while(i < this.length && this[i] != m) { i++ };
	return i < this.length ? i : undefined;
}

$(document).ready(function() {
	
	$p				= $("#content .header .nav .pointer");
	$curY			= null;
	$curColor	= null;
	
	$("#content .header .nav ul").not(".subnav, .info").children().hover(
		function() {
			if($p.queue().length > 0) {	$p.stop(); }
			pX	= $(this).position().left + Math.round($(this).width() / 2) + 10;
			$p.fadeTo(100, 0, function() {
				$p.css({ left: pX + "px" });
				$p.fadeTo(100, 1.0);
			});
		},
		function() { return false; }
	);

	$("#content .benefits > ul > li").each(function() {
		bindEvents($(this));
	});
	
	$("#content .benefits .info .back a").click(function() {
		$("#content .benefits .active").click();
	});
	
});

function bindEvents(el) {
	el.click(function(e) {
		$curColor	= el.css("backgroundColor");
		$pos			= $("#content .benefits li").not(".info li").get().arrayIndex(el.get(0));
		$("#content .benefits > ul > li").not(el).not(".info").fadeTo(350, 0);
		el.addClass("active").animate({ top: -($pos * 79), backgroundColor: "#29506d", color: "#ffffff" }, { queue: false, duration: 300 });
		info			= $("#content .benefits .info")[$pos];
		$(info).fadeIn(500);
		el.unbind().click(function(e) {
			$(info).fadeOut(300);
			el.siblings().fadeTo(350, 1.0);
			el.removeClass("active").animate({ top: 0, backgroundColor: "#" + $curColor, color: "#093657" }, 300, function() {
				el.unbind();
				bindEvents(el);
			});
			e.stopPropagation();
		});
		e.stopPropagation();
	});
	$("#content .benefits .info, #content .benefits .info li").unbind();
}