/*
 * 
 */

var maxSafeBMI = 25;
var maxCharsComments = 3000;
var rotateReasonTime = 5000; // msecs


/*  At Risk QUIZ Questions
 *  if the option user picked is also a key, then we'll list the corresponding value in results.  
 *  key and value can be different (Man, Male) or same (40+, 40+). if same, value can be '1'
 */

var questions = {
1: { question: "Pick One:",
	//Removed 'Man': 'Male', - So it doesn't flag male as a risk factor
	'': '',
	options: [ 'Man', 'Woman' ]},

2: { question: "Pick One:",
	'40+': 1,
	options: [ 'Under 40', '40+' ]},

3: { question: "Pick One:",
	'African American': 1,	
	optbtn: [ 'btnRiskCaucasian', 
	           'btnRiskAfricanAm',
	           'btnRiskAsian',
	           'btnRiskHispanic',
	           'btnRiskAmIndian',
	           'btnRiskOther' ],
	options: [ 'Caucasian', 
	    	           'African American',
	    	           'Asian/Pacific Islander',
	    	           'Hispanic',
	    	           'American Indian',
	    	           'Other' ]},
	    	           
4: { question: "Does heart disease run in your family?",
	'Yes' : 'Family History of Heart Disease',
	options: [ 'Yes', 'No' ]},
 
5: { question: "Do you have high blood pressure, 140/90 or higher?",
	'Yes' : 'High Blood Pressure',
	options: [ 'Yes', 'No', 'Don\'t Know' ]}, 
 
6: { question: "Are you a smoker or have you been a smoker in the last 3 years?",
	'Yes' : "Smoker",
	options: [ 'Yes', 'No' ]},
 
7: { question: "Do you exercise for 30 minutes or more on most days?",
	'No' : "Physical Inactivity",
	options: [ 'Yes', 'No' ]},

8: { question: "Do you have diabetes or take medicine for your blood sugar? ",
	'Yes' : 'Diabetes',
	options: [ 'Yes', 'No' ]},
 
9: { question: "Have you had a heart attack?  ",
	'Yes' : 'Previous Heart Attack',
	options: [ 'Yes', 'No' ]},
 
10: { question: "Have you had a stroke or TIA (mini-stroke)?  ",
	'Yes' : 'Previous Stroke',
	options: [ 'Yes', 'No' ]},
 
11: { question: "Do you have high cholesterol, 200 mg/dL or higher? ",
	'Yes' : 'High Cholesterol',
	options: [ 'Yes', 'No', 'Don\'t Know' ]}, 
 
12: { question: "Is your HDL (GOOD) cholesterol less than 40mb/dl? ",
	'Yes' : 'Low HDL Cholesterol',
	options: [ 'Yes', 'No', 'Don\'t Know' ]}, 

13: { question: "What is your body mass index (BMI)?",
	input: [ 'HEIGHT', 'WEIGHT' ]}
}

var allfacts =[]; // populated from html

/* see below for note about how long a 'reason' can be 
 */
var reasons = [
	  "My children's laughter",
	  "Being with my Yosemite friends ",
	  "A good massage ",
	  "Tea with a girlfriend ",
	  "Taking my orchestra to Salzburg ",
	  "Exercising ",
	  "Learning a different language ",
	  "Throwing a party ",
	  "Learning to dance ",
	  "Seeing my children happy",
	  "Weddings ",
	  "Visiting Europe ",
	  "Getting back in shape ",
	  "Go skydiving ",
	  "Swimming with dolphins ",
	  "Chocolate ",
	  "Warm sheets in winter ",
	  "Fresh-cut grass ",
	  "Learning a new language",
	  "My family ",
	  "My husband ",
	  "Museums ",
	  "Lobster ",
	  "Leaf piles ",
	  "Canoes ",
	  "A good book ",
	  "Soaking in a claw-foot tub",
	  "Black-and-white photos ",
	  "Stalactites and stalagmites",
	  "The smell of stables and horses",
	  "My music collection ",
	  "Weekend road bike rides ",
	  "Fishing for salmon in Alaska",
	  "Not putting my wife through another scare ",
	  "My yard ",
	  "The ocean ",
	  "Going to the theater ",
	  "Barbecue ",
	  "Thrift shops ",
	  "Big socks ",
	  "The smell of a Christmas tree",
	  "A really good summer peach",
	  "Antique slips ",
	  "Butterflies ",
	  "Waking up in my husband's arms",
	  "Learning to speak new languages",
	  "Skiing the Alps ",
	  "Learning to design jewelry",
	  "Own a racehorse ",
	  "Learning to make good risotto",
	  "Drive the Alaskan Highway",
	  "Be in great shape ",
	  "Becoming a better golfer",
	  "Have a spa day ",
	  "Growing a field of lavender",
	  "Be with my family as long as possible",
	  "Be in a Broadway musical",
	  "Driving across the country in a trailer",
	  "Get a massage ",
	  "Go to Africa ",
	  "Go to Sweden ",
	  "Eat in all the best restaurants",
	  "Be like my grandmother ",
	  "Winning the lottery ",
	  "Adopt some mutts ",
	  "My initials ",
	  "The touch of my husband ",
	  "Live in Italy for a year ",
	  "Buying funky shoes ",
	  "Taking a train across Europe ",
	  "Performing in a cabaret act ",
	  "Great rings ",
	  "Singing in a jazz club ",
	  "Long Island ",
	  "Want to adopt a golden retriever ",
	  "Dumplings ",
	  "Scuba diving ",
	  "Any beach in the Bahamas",
	  "Swimming ",
	  "Flying a small plane ",
	  "Buying a house in Montauk",
	  "A nice overcoat ",
	  "Going to Chinatown ",
	  "I want to protect my loved ones ",
	  "Pistachio ice cream ",
	  "Seeing my daughter on Broadway ",
	  "Long walks ",
	  "Boats ",
	  "Cats ",
	  "Time with Mom ",
	  "Going to Ireland ",
	  "Growing my hair back",
	  "Holding my daughter",
	  "Watching T.V. ",
	  "Helping people ",
	  "Shopping with Suzie",
	  "Seeing the U.S.A. ",
	  "Dogs ",
	  "Never feeling that helpless again ",
	  "Going dancing ",
	  "Time with my family",
	  "Lobster sauce ",
	  "Old sweatshirts ",
	  "Visiting Canada ",
	  "Cross-country skiing",
	  "Cooking ",
	  "Being of service ",
	  "Word games ",
	  "The smell of fresh-cut grass",
	  "My health ",
	  "White cotton tee shirts",
	  "Taking a trip to Israel",
	  "Helping my family ",
	  "Mornings ",
	  "Getting stronger ",
	  "Riding a bike ",
	  "My home ",
	  "Hannah, my cat ",
	  "Creating a world youth orchestra"
];
/*
 *   NOTE regarding length of the string of a "reason"
 *   in order to fit in the callout box on the web page,
 *   any reason more than 'maxReasonChars' will be skipped
 */   
var maxReasonChars = 25;
/*   If you want to test a specific reason, uncomment the 
 *   reasons lines below.  This will replace the list of 
 *   reasons above with just the reasons you want to test.
 *   Then, of course, put your reasons in there.
 
reasons = [
     	  "Be with my family as long as possible ",
    	  "Be in a Broadway musical ",
    	  "Driving across the country in a trailer "
];
 */


var isIE6 = false;
var curNavId = '';


function documentReady() {	
	isIE6 = typeof document.body.style.maxHeight === "undefined";

	// populate random facts function
	$('#mainFacts li').each(function(i) {
	    allfacts.push($(this).html());
	});
	
	$('.navClickable').live("click",  function() {
		navClick( $(this).attr('id') );
	});
	
	//navClick('navHome');
	//navClick('navAboutAspirin');
	
	setupPageClicks();
}

function navClick(navId) {
    //console.log('navClick('+navId+')');

    $('.navClickable').removeClass("selected");
    $('#' + navId).addClass('selected');


//    $('#mainContent').html($('#main' + id).html());
//    $('#mainContent').removeClass('main' + curNavId);
//    $('#mainContent').addClass('main' + id);
//    curNavId = id;

    //    updatePageClicks();

//    id = navId.replace(/^nav/, '').replace(/^main/, ''); //.replace('#','');
//    if (id == 'Home') {
//        $('#mainBanner').css('display', 'none');
//    } else {
//        /* using banners in img src
//        bannerId = id.replace(/-.*$/,'');
//        //alert('id and bannerid: '+ id+'--'+bannerId);
//        $('#mainBanner img').attr('src','img/banner'+bannerId+'.jpg');
//        // note: path to jpg here is different than in css/proheart.css, since css is relative to html
//        $('#mainBanner').css('background','url("img/banner'+bannerId+'-bg.jpg") top repeat-x');
//        $('#mainBanner').css('display', 'block');
//        */
//    }

//    $('#mainContent').html($('#main' + id).html());
//    $('#mainContent').removeClass('main' + curNavId);
//    $('#mainContent').addClass('main' + id);
  
//    curNavId = id;


    return false;
}



function setupPageClicks() {
	// also update in quiz below
	//$('.redButton').css(redButtonCSS).corners('8px');

	setupBtnHover();
	doEmailSubmitButton(); // bottom right, all pages
	showWarningSignsTrigger(); // am i at risk page
	doSubmitTellFriend();   // tell friend page

	$('#bottom .middle p').html( randomOne(allfacts) );

	// could move this to html
	$("#startQuiz").live("click", function(event) {
		event.preventDefault(); 
		quiz(1,0,0);
	});
	
	setupCommentsModal();
	setup81reasons();
	//setupStories();


}

function updatePageClicks() {
	//containerShadowHeight();
}

function setupStories() {
	return;
	$('.mainStories .nextStory').click(function(event) {
		event.preventDefault(); 
		$('.mainStories .indentLeft').html( 
			'<div id="mainStories2id">'+$('#mainStories2').html()+'</div>' );
		
		$('#mainStories2id .nextStory').live("click", function(event) {
			event.preventDefault(); 
			$('.mainStories .indentLeft').html( 
				'<div id="mainStories3id">'+$('#mainStories3').html()+'</div>' );
		});
	});
	$('#shareYourStory').live("click", function(event) {
		event.preventDefault(); 
		$('.mainStories .indentLeft').html( 
			'<div id="mainStoriesShareFormId">'+$('#mainStoriesShareForm').html()+'</div>' );
		$('#mainStoriesShareFormId .submitButton').live("click", function(event) {
			event.preventDefault(); 
			doStoriesShareForm();
		});
	});

}

function containerShadowHeight() {
	/* Fix CSS - equalHeights() needs to be called whenever main content changes height, or else shadow is off
	 */
	// reset height of shadows in case middle height shrinks
	if ($.browser.msie && $.browser.version == 6.0) { $('#upperContainer > div').css({'height': '200px'}); }
	$('#upperContainer > div').css({'min-height': '200px'});
	
	$('#upperContainer').children().each(function(i){
		//console.log('containerShadowHeight children height='+$(this).height(), this); 
	});

	$("#upperContainer").equalHeights();
}

function setupBtnHover() {
    $("img.btnHover").live('mouseover', function () {
    	imgsrc = $(this).attr('src').replace(/\.gif/,'Hover.gif').replace(/(Hover)+/,'Hover');
    	$(this).attr('src', imgsrc);
    }).live('mouseout', function () {
    	imgsrc = $(this).attr('src').replace(/(Hover)*\.gif/,'.gif');
    	$(this).attr('src', imgsrc);
    });
}

function rotate81reasons() {
	reason = randomOne(reasons);
	sanityCheck = 200;  // prevent runaway script in case maxReasonChars is too low
	while (sanityCheck && (reason.length > maxReasonChars)) {
		//console.log('reason too long: '+sanityCheck+' - '+reason);
		reason = randomOne(reasons);
		sanityCheck--;
	}
	$('#aspirinCallout1 h4').html( reason );
	setTimeout("rotate81reasons()", rotateReasonTime);
	//console.log('aspirinCallout1 changed html ', this);

	/*
	$('#aspirinCallout1 h4').hide( 500, function (){
		$('#aspirinCallout1 h4').html( randomOne(reasons) );
		$('#aspirinCallout1 h4').show(500, function (){
			setTimeout("rotate81reasons()", rotateReasonTime-1000);
			console.log('aspirinCallout1 changed html ', this);
		});
	});
	*/
}

function countReasonsLength() {
	reasonlen = {};
	$.each( [25,27,28,29,30,31,32,33,34], function( index, n){
		reasonlen[n] = 0;
	});
	for (ii in reasons) {
		//console.log('checking reason:'+ reasons[ii].length +' - '+ reasons[ii]);

		$.each([25,27,28,29,30,31,32,33,34], function( index, n){
			if (reasons[ii].length < n) {
				reasonlen[n] = reasonlen[n] + 1;
				//console.log('adding one to n: '+n+'('+reasonlen[n]+') reason:'+ reasons[ii].length +' - '+ reasons[ii]);
			}
		});
	}
	for (jj in reasonlen) {
		//console.log('number of reasons with string length < '+jj+': '+reasonlen[jj]);
	}
}
function setup81reasons() {
	//$('#aspirinCallout1 h4').html( randomOne(reasons) );
	//setTimeout("rotate81reasons()", rotateReasonTime);
	rotate81reasons();
	
	//countReasonsLength();
	
	// about aspirin callouts 
	$('#aspirinCallout1 a').live("click", function(event) {
		event.preventDefault(); 
		$('#aspirinCallout1').hide();
		$('#aspirinCallout2').show();
	});
	$('#aspirinCallout2 #submit81Reason').live("click", function(event) {
		event.preventDefault(); 
		/*
		 * submit reason form here
		 */
		$('#aspirinCallout2').hide();
		$('#aspirinCallout3').show();
	});
	$('#aspirinCallout3 a').live("click", function(event) {
		event.preventDefault(); 
		$('#aspirinCallout3').hide();
		$('#aspirinCallout1').show();
	});
}

function setupCommentsModal() {
	$("#emailCommentsTrigger").live("click", function(event) {
		event.preventDefault();
		if (!document.getElementById("emailCommentsJQM")) {
			$('#mainContent').append('<div id="emailCommentsJQM" class="jqmWindow">');
			$('#emailCommentsJQM').html( $('#emailCommentsModal').html() );		
			// http://dev.iceburg.net/jquery/jqModal
			$('#emailCommentsJQM').jqm();
			
			$('#emailCommentsJQM textarea').keyup(function() {
				$('#charsLeft').html(maxCharsComments - $(this).val().length);
				if ($(this).val().length > maxCharsComments)
					$('#charsLeft').html('<strong>You may only have up to 3,000 characters.</strong> ' 
						+$('#charsLeft').html() );
			});
			$('#emailCommentsJQM #emailCommentsModalReset').live("click", function(event) {
				event.preventDefault();
				$('#emailCommentsJQM select').val('--');
				$('#emailCommentsJQM .input').val('');
			});
			$('#emailCommentsJQM #emailCommentsModalSubmit').live("click", function(event) {
				event.preventDefault();
				/*
				 *  validate / submit comments form here
				 */
				$('#emailCommentsJQM').html($('#emailCommentsModalThankYou').html() );
			});
		}
		$('#emailCommentsJQM').jqmShow();
	});
}
		
function doStoriesShareForm() {
	/*
	 * validate name, email and story and submit to server
	 */
	// say thank you
	$('.mainStories .indentLeft').html($('#mainStoriesThanks').html() );
}

function doEmailSubmitButton() {
	$('#emailSubmitButton').live("click", function(event) {
		event.preventDefault(); 
		/*
		 * validate email and friends email and submit to server
		 */
		
		// say thank you
		$('#bottom .rightSide').html($('#emailSubmitThankyou').html() );
	})
}

function showWarningSignsTrigger() {
	$("#warningSignsTrigger").show();
	$("#warningSignsTrigger a").live("click", function(){
		//alert('chads');
		//$("#warningSignsReadMoreTrigger").hide();
	    $('#warningSignsMore').show('slow');
		$("#warningSignsTrigger").hide();
		$("#warningSignsMore").live("click", function(){
			$("#warningSignsMore").hide('slow');
			showWarningSignsTrigger();
		    return false;
		});
	    return false;
	});
}



function doSubmitTellFriend() {
	// below is covering for typo - display:hidden should be none 
	$('#mainTellFriendThankYou').hide();

	$('#submitTellFriend').live("click", function(event) {
		event.preventDefault(); 
		/*
		 * validate email and submit to server
		 */
		
		// say thank you
		$('#mainTellFriendForm').html($('#mainTellFriendThankYou').html() );
		$('#mainTellFriendForm').css('margin-bottom','140px');
	})
	
}

function randomOne(arr) {
	n = Math.floor(Math.random() * arr.length);
	//console.log('picked '+n+' out of '+arr.length+': '+ arr[n]);
	return arr[n];
}

var riskHtml ='';

/*
 * when making results, create <div class='quizResults'> and put quizHeader, quizYesRisk/quizNoRisk, quizFooter
 */
function quiz(questionNum,answerNum,answer) {

	if (answerNum > 0) {
		saveLastAnswer(answerNum,answer);
	} else {
		riskHtml =''; // reset when they start over
	}
	
	//questionNum = isdigit(questionNum) ? questionNum : 1;
	var html = '';
    var q = questions[questionNum];

    html += '<p>Question ' + questionNum + ' of 13</p><h3>'
         + q.question
    	 +'</h3>';
    if (q['input']) {
        //html += $('#bmiform').html;
        html += bmiHtml();
    } else {
    	nextNum = questionNum+1;
    	for (var opt in q.options) {
        	//if (opt == 3) html += '<div class="quizOptionSpacer">';
        	if (q.optbtn) {
        		img = q.optbtn[opt];
        	} else {
        		img = 'btnRisk'+ q.options[opt].replace(/[' ]/g,''); // btnRiskDontKnow
        	}
        	html += "<span class='quizButton'><img onclick='quiz("+nextNum
        	+","+questionNum+","+opt+"); return false;' class='btnHover' src='img/"
        	+img+".gif'></img></span>";
        	/*
        	if (0) { // old way
        	html += "<span class='quizButton'><a href='' onclick='quiz("+nextNum
        	+","+questionNum+","+opt+"); return false;' class='redButton' title='"
        	+q.options[opt]+"'>"+q.options[opt]+"</a></span>\n";
        	}
        	*/
        }
    }
	//console.log('quiz html:'+ html, answers);
    $("#quizId").data('orightml', $("#quizId").html());
    $("#quizId").html(html);
	//$('.redButton').css(redButtonCSS).corners('8px');

	
	//console.log('quiz('+questionNum+') returning false');
	return false;
}
function saveLastAnswer(num, answer) {
	q = questions[num];
	if (q[q.options[answer]] != undefined) {
		factor = q[q.options[answer]] == 1 ? q.options[answer] : q[q.options[answer]];
		riskHtml += '<li>'+factor+'</li>';
	}
}

    function bmiHtml() {
	    return '<div class="quizBMI clearfix form">'
		    + '<label>Height (feet):</label>'
		    + '<input class="input" type="text" id="bmiFeet" />'
		    + '<label>Height (inches):</label>'
		    + '<input class="input" type="text" id="bmiInches" />'
		    + '<label>Weight (lbs):</label>'
		    + '<input class="input" type="text" id="bmiLbs" />'
		    + '<label id="bmiError"> &nbsp;</label><div class="submitdiv clearfix">'
		    + '<img id="submitBMI" onclick="quizCalc(); return false;" class="btnHover" src="img/btnRiskSubmit.gif">'
		    + '</div><div class="spacer"></div></div>';
    }

function quizCalc() {
	// validate BMI
	n = {};
	valid = true;
	$.each(['bmiInches','bmiFeet','bmiLbs'], function( index, id){
		n[id] = parseInt( $('#'+id).attr('value') );
		if (isNaN(n[id]) || (n[id] < 0) || (n[id] > 800)) {
			valid = false;
		}
	});
	if (!valid) {
		$(".quizBMI input").attr('value','');
		$("#bmiError").html('Valid Numbers, Please');
		return;
	}
	bmi = cal_bmi( n['bmiLbs'], n['bmiInches'] + 12*n['bmiFeet']);
	if (bmi > maxSafeBMI) {
		riskHtml += '<li>BMI is '+bmi+'</li>';
	}
	
	html = "<div class='quizResults'>" + $('#quizHeader').html() + "<div id='quizResultsContent'>";
	if (riskHtml.length == 0) {
		html += $("#quizNoRisk").html();
	} else {
		html += $("#quizYesRisk").html();
	}
    $("#quizId").html(html+ "</div>"+ $("#quizFooter").html() +"</div>");
    
	if (riskHtml.length > 0) {
		$('#listRiskyFactors').html(riskHtml);
	}
	updateQuizLinks();
}

function updateQuizLinks() {
	
	//$('.redButton').css(redButtonCSS).corners('8px');
	
	// best to move these out to .html
    //$('#quizId .learnMoreQuiz').attr('href', 'pdf/riskfactors.pdf').attr('TARGET', '_NEW');
	$('#quizId .printQuiz').live("click", function(event) {
	    event.preventDefault();
	    resultsHtml = $('#quizResultsContent').html();

	    var printForm = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
        + ' <html xmlns="http://www.w3.org/1999/xhtml" >'
        + ' <head>'
        + '     <title></title>'
        + ' 	<link rel="stylesheet" href="../css/blueprint/screen.css"   type="text/css" media="screen, projection">'
        + ' 	<link rel="stylesheet" href="../css/blueprint/print.css"    type="text/css" media="print">	'
        + ' </head>'
        + ' <body id="bodyId" style="background-color: #FFFFFF;">'
	    + ' 			  <img src="img/i_am_proHeart-logo-white-bg.jpg" width="273px" height="109px"></img>'
        + ' 		  <div id="quizHeader2" style="text-align: center;">'
        + ' 			      <p></p>'
        + ' 			  </div>'
        + ' 			  <div class="content clearfix">'
                            + resultsHtml +
        +' 			  </div>'
        +'<br> '
        + '<h3>www.iamproheart.com</h3>'
        + '</body>'
        + '</html>'

	    var w = window.open('QuizResults.htm', "Print", "status=0,menubar=1,toolbar=0");
	    w.document.open();
	    w.document.write(printForm.replace('NaN', ''));
	    w.document.close();

	});
	$('#quizId .startOverQuiz').live("click", function(){ quiz(1,0,0); });
	$('#quizId .shareQuiz').live("click", function(){
		html = "<div class='quizResults'>" + $('#quizHeader').html();
		html +=  $('#quizShare').html() + '</div>';
	    $("#quizId").html(html);
	    $('#quizId #submitShareQuiz').live("click", function(){ submitShareQuizProcess(); });
	    updateQuizLinks();
	});
}

function printQuizResults() {
	
	resultsHtml = $('#quizResultsContent').html();
	
	// create new div and hide the rest of the page
	$('#bodyId').html( '<div id="quizPrintable"></div><div style="display:none">' + $('#bodyId').html() +'</div>');
	
	$('#quizPrintable').html(
			  '<img src="img/i_am_proHeart-logo-white-bg.jpg" width="273px" height="109px"></img>'
			  + '<div id="quizHeader2" style="text-align: center;">'
			  +	'    <img src="img/icon-share.jpg"> <a href="tell_a_friend.aspx?ref=quiz" class="redlink" id="hypTellAFriend">Share</a>&nbsp;|&nbsp;'
			  +	'	 <img src="img/icon-print.jpg"> <a href="javascript:window.print();" class="redlink printQuiz" id="hypPrint">Print</a>&nbsp;|&nbsp;'
			  +	'    <p></p>'
			  +	'</div>'
			  + '<div class="content clearfix">' +resultsHtml+'</div>'
			  //+ '<p>&nbsp;</p>'
			  + '<h3>www.iamproheart.com</h3>');
	
	$('#bodyId').css({
		'background-image' : 'none',
		'background-color' : '#FFFFFF'
	});

	//setTimeout("window.print()", 800); // delay so there's time for ie6 to get img
	window.print();
}

function submitShareQuizProcess() {

	/*
	 * submit form here
	 */
	

	html = "<div class='quizResults'>" 
		 + $('#quizHeader').html()
		 + $('#quizShareThanks').html() 
		 + '</div>';
    $("#quizId").html(html);
    updateQuizLinks();
}

// from http://www.nhlbisupport.com/bmi/bmicalc.htm
function cal_bmi(lbs, ins)
{
   h2 = ins * ins;
   bmi = lbs/h2 * 703
   f_bmi = Math.floor(bmi);
   diff  = bmi - f_bmi;
   diff = diff * 10;
   diff = Math.round(diff);

   if (diff == 10)    // Need to bump up the whole thing instead
   {
      f_bmi += 1;
      diff   = 0;
   }
   bmi = f_bmi + "." + diff;
   return bmi;
}


function loadFlash() {
	  if (AC_FL_RunContent == 0) {
		    alert("This page requires AC_RunActiveContent.js.");
		  } else {

	AC_FL_RunContent(
		'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
		'width', '820',
		'height', '290',
		'src', 'homeFlash',
		'quality', 'high',
		'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'loop', 'true',
		'scale', 'showall',
		'wmode', 'window',
		'devicefont', 'false',
		'id', 'homeFlash',
		'bgcolor', '#ffffff',
		'name', 'homeFlash',
		'menu', 'true',
		'allowFullScreen', 'false',
		'allowScriptAccess','sameDomain',
		'movie', 'homeFlash',
		'salign', ''
		); //end AC code
	}
}




// http://www.cssnewbie.com/equalheights-jquery-plugin/
// does not work in safari

// http://www.filamentgroup.com/lab/setting_equal_heights_with_jquery/
// works in safari, but gets height wrong some times

/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights" & "EqualWidths"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2007 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Description: Compares the heights or widths of the top-level children of a provided element 
 		and sets their min-height to the tallest height (or width to widest width). Sets in em units 
 		by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method	(article: 
 * 		http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)							  
 * Usage Example: $(element).equalHeights();
   		Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
 * Version: 2.0, 07.24.2008
 * Changelog:
 *  08.02.2007 initial Version 1.0
 *  07.24.2008 v 2.0 - added support for widths
--------------------------------------------------------------------*/

$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			//console.log(' equalHeights currentTallest='+currentTallest, this);
			if ($(this).height() > currentTallest) { 
				currentTallest = $(this).height(); 
			}
		});
		if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};

// just in case you need it...
$.fn.equalWidths = function(px) {
	$(this).each(function(){
		var currentWidest = 0;
		$(this).children().each(function(i){
				if($(this).width() > currentWidest) { currentWidest = $(this).width(); }
		});
		if(!px || !Number.prototype.pxToEm) currentWidest = currentWidest.pxToEm(); //use ems unless px is specified
		// for ie6, set width since min-width isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'width': currentWidest}); }
		$(this).children().css({'min-width': currentWidest}); 
	});
	return this;
};


/*-------------------------------------------------------------------- 
 * javascript method: "pxToEm"
 * by:
   Scott Jehl (scott@filamentgroup.com) 
   Maggie Wachs (maggie@filamentgroup.com)
   http://www.filamentgroup.com
 *
 * Copyright (c) 2008 Filament Group
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 *
 * Description: Extends the native Number and String objects with pxToEm method. pxToEm converts a pixel value to ems depending on inherited font size.  
 * Article: http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/
 * Demo: http://www.filamentgroup.com/examples/pxToEm/	 	
 *							
 * Options:  	 								
 		scope: string or jQuery selector for font-size scoping
 		reverse: Boolean, true reverses the conversion to em-px
 * Dependencies: jQuery library						  
 * Usage Example: myPixelValue.pxToEm(); or myPixelValue.pxToEm({'scope':'#navigation', reverse: true});
 *
 * Version: 2.0, 08.01.2008 
 * Changelog:
 *		08.02.2007 initial Version 1.0
 *		08.01.2008 - fixed font-size calculation for IE
--------------------------------------------------------------------*/

Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
	//set defaults
	settings = jQuery.extend({
		scope: 'body',
		reverse: false
	}, settings);
	
	var pxVal = (this == '') ? 0 : parseFloat(this);
	var scopeVal;
	var getWindowWidth = function(){
		var de = document.documentElement;
		return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	};	
	
	/* When a percentage-based font-size is set on the body, IE returns that percent of the window width as the font-size. 
		For example, if the body font-size is 62.5% and the window width is 1000px, IE will return 625px as the font-size. 	
		When this happens, we calculate the correct body font-size (%) and multiply it by 16 (the standard browser font size) 
		to get an accurate em value. */
				
	if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
		var calcFontSize = function(){		
			return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
		};
		scopeVal = calcFontSize();
	}
	else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };
			
	var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
	return result;
};
