$(document).ready(function(){
	var topMargin = 150;
	var minContentHeight = 150;
	var expanded = false;
	var maxHeight = $("#expandable").height();
	var maxContentHeight = $("#expandable .content").height();
	var divDiff = maxHeight - maxContentHeight;
	$(window).resize(function(){
		if(expanded) {
			targetContentHeight = maxContentHeight;
			if( ( targetContentHeight + divDiff + topMargin ) > $(window).height() ) {
				targetContentHeight = $(window).height() - topMargin - divDiff;
			}
			$("#expandable .content").stop(true,false).animate({
				height: targetContentHeight
			},0,"linear",function(){
				resizeExpandable();
			});
		}
		$("#expandable").stop(true,false).animate({
			top: $(window).height() - $("#expandable").height()
		},0);
	});
	$("#expandable .toggle").click(function(e){
		e.preventDefault();
		if(expanded){
			id = setInterval("resizeExpandable()",1);
			$("#expandable .content").stop(true,false).animate({
				height: minContentHeight
			},500,"linear",function(){
				clearInterval(id);
			$("#expandable").stop(true,false).animate({
				top: $(window).height() - $("#expandable").height()
			},0);
			$("#expandable").find(".outer").css({"margin":"0px auto 0px auto"});
				$("#expandable .toggle img").attr("src","/images/iri_expand.png");
			});
			expanded = false;
			OmnitureCustom("Collapse Important Risk Information");
		} else {
			targetContentHeight = maxContentHeight;
			if( ( targetContentHeight + divDiff + topMargin ) > $(window).height() ) {
				targetContentHeight = $(window).height() - topMargin - divDiff;
			}
			id = setInterval("resizeExpandable()",1);
			$("#expandable .content").stop(true,false).animate({
				height: targetContentHeight
			},500,"linear",function(){
				clearInterval(id);
				$("#expandable").stop(true,false).animate({
					top: $(window).height() - $("#expandable").height()
				},0);
				$("#expandable").find(".outer").css({"margin":"0px auto 0px auto"});
				$("#expandable .toggle img").attr("src","/images/iri_collapse.png");
			});
			expanded = true;
			OmnitureCustom("Expand Important Risk Information");
		}
	});
	$("#expandable .content").height(minContentHeight);
	resizeExpandable();
});

function resizeExpandable(){
	$("#expandable").stop(true,false).animate({
		top: $(window).height() - $("#expandable").height()
	},0);
	$("#expandable").find(".outer").css({"margin":"0px auto 0px auto"});
};

