$(document).ready(function() {

    $('#home .box').hover(
        function(){
            $(this).children('.hover').animate({bottom: '0px'}, 400);
        },
        function(){
            $(this).children('.hover').animate({bottom: '-100px'}, 400);
    });

    $('.expanding-text').focus(function () {
		bigSmlCmts(this)
	}).blur(function () {
		bigSmlCmts(this)
    });


    $('.btn_next').live("click",lead_form_page_change);
    $('.btn_previous').live("click",lead_form_page_change);

    $('.tip').hover(function(){
        $(this).children('.tooltip').removeClass('hide');
    },
    function(){
         $(this).children('.tooltip').addClass('hide');
    });

    $('.tip_perio').hover(function(){
        $(this).children('.tooltip_perio').removeClass('hide');
    },
    function(){
         $(this).children('.tooltip_perio').addClass('hide');
    });

});

function lead_form_page_change(){
    var stepName = $(this).attr("href").split("#")[1];
        var prev = (stepName*1)-1;
        var next = (stepName*1)+1;

        if( stepName == 2 ){
            $('#step2').removeClass('hide');
            $('#step1').addClass('hide');
            $('#step3').addClass('hide');
        }
        else if( stepName == 3 ){
            $('#step3').removeClass('hide');
            $('#step1').addClass('hide');
            $('#step2').addClass('hide');
        }
        else{
            $('#step1').removeClass('hide');
            $('#step2').addClass('hide');
            $('#step3').addClass('hide');
        }
}
// allows for expandable comments box to save space when not typing in them
function bigSmlCmts(node) {
	var curr_h = node.style.height;
	var new_h;

	if( curr_h == "" || curr_h == "1.25em" )
		new_h = "7em";
	else if( curr_h == "7em" )
		new_h = "1.25em";

	node.style.height = new_h;
}

//calculates perio program form
function perio_cal(){
    var total = 0;
    var prophy_percent =0;
    var maintenance_percent =0;
    var root_four_percent = 0;
    var root_one_percent = 0;    
        
    var prophy = document.getElementById('1110').value*1;
    var maintenance = document.getElementById('4910').value*1;
    var root_four = document.getElementById('4341').value*1;
    var root_one = document.getElementById('4342').value*1;
    total = prophy + maintenance + root_four + root_one;

    document.getElementById('perio_total').value = total;

    prophy_percent = Math.round((prophy/total)*100);
    maintenance_percent = Math.round((maintenance/total)*100);
    root_four_percent = Math.round((root_four/total)*100);
    root_one_percent = Math.round((root_one/total)*100);

    if(total == 0)
        {
            document.getElementById('1110_percent').value = 0+'%';
            document.getElementById('4910_percent').value = 0+'%';
            document.getElementById('4341_percent').value = 0+'%';
            document.getElementById('4342_percent').value = 0+'%';
        }
    else
        {
            document.getElementById('1110_percent').value = prophy_percent+'%';
            document.getElementById('4910_percent').value = maintenance_percent+'%';
            document.getElementById('4341_percent').value = root_four_percent+'%';
            document.getElementById('4342_percent').value = root_one_percent+'%';
        }
    


    
}

