var originalHeight;

function showBenefit(benefit_id) {
	$(".benefit").each(function() {
		$(this).removeClass("benefit_active");
	});
	$("#benefit_"+benefit_id).addClass("benefit_active");
	
	//scrollToPos=findPos(document.getElementById("benefit_"+benefit_id));
	//scrollToPos=scrollToPos.y - 95;
	scrollToPos=$("#benefit_"+benefit_id)[0].offsetTop;
	
	/*newBoxHeight=$("#benefit_"+benefit_id).height() + 5;
	oldBoxHeight=$("#body_box").height();
	if(newBoxHeight > 553) {
		newBoxHeight=553;
	} else if(newBoxHeight <= 330) {
		newBoxHeight=330;
		$("#features_close_button").hide();
	}
	
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		scrollToPos=scrollToPos -15;
	}*/
	
	newHeight=scrollToPos + $("#benefit_"+benefit_id).height();
	if(newHeight > originalHeight) {
		$("#body_box").height(newHeight);
	}
}

$(document).ready(function() {
	originalHeight=$("#body_box").height();
	$("#click_directions").css("display", "block");
	
	$(".benefit").each(function() {
		idParts=$(this).attr("id").split("_");
		theID=idParts[1];
		//featurePos=findPos(document.getElementById("feature_"+theID));
		//featurePos=featurePos.y - 103;
		featurePos=$("#feature_"+theID)[0].offsetTop;
	
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
			featurePos=featurePos-15;
		}
		
		$(this).css("top", featurePos);
	});
});

function findPos ( obj ) {
	var left = !!obj.offsetLeft ? obj.offsetLeft : 0,
		top = !!obj.offsetTop ? obj.offsetTop : 0;
	
	while( (obj = obj.offsetParent) ) {
		left += !!obj.offsetLeft ? obj.offsetLeft : 0;
		top += !!obj.offsetTop ? obj.offsetTop : 0;
	}
	
	return{ x:left, y:top };
}

/*function animateBox(targetHeight, oldScroll, direction) {
	if(($("#body_box").height() == targetHeight) || (direction=="smaller" && oldHeight < targetHeight) || (direction=="bigger" && oldHeight > targetHeight)) {
		clearTimeout(animateTimer);
		if(direction=="bigger") $("#features_close_button").show();
		return true;
	}
	oldHeight=$("#body_box").height();
	
	if(typeof(direction)=="undefined") {
		if(oldHeight < targetHeight) {
			direction="bigger";
		} else {
			direction="smaller";
		}
		timerLength=(animationLength / 40);
		stepLength=Math.ceil(Math.abs((targetHeight-oldHeight) / 40));
	} else {
		if(direction=="bigger") {
			oldHeight=oldHeight+stepLength;
		} else {
			oldHeight=oldHeight-stepLength;
		}
	}
	
	featureBoxHeight=oldHeight-15;
	$("#features_box").height(featureBoxHeight);
	
	//Keep the scroll at the right spot
	$("#features_box").scrollTop(oldScroll);
	
	$("#body_box").height(oldHeight);
	
	animateTimer=setTimeout("animateBox("+targetHeight+", "+oldScroll+", '"+direction+"')", timerLength);
}*/
