$(document).ready( function() {

    $('.print').click(function(){window.print();return(false);});

    // Attach slider collapse/expand behavior
    selected = $("#slider-bridalflowers");
    $("ul.slider li.slider-panel").click(
        function() {
            if (this != selected) {

                $(selected).animate( { width: "52px" }, 400, false, false);
                $(this).animate( { width: "589px" }, 400, false, false);

                $(selected).find(".slider-header").animate( { left: "0px" }, 400);
                $(this).find(".slider-header").animate( { left: "-52px" }, 400);
                $(selected).find(".slider-body").animate( { left: "52px" }, 400);
                $(this).find(".slider-body").animate( { left: "0px" }, 400);
                
                selected = this;
            }
        }
    );
    $(selected).click();
    
    // Attach 'next' button handling
    $("#button-next-bridalflowers").click(function () { $("#slider-bridalparty").click(); return(false); });
    $("#button-next-bridalparty").click(function () { $("#slider-boutonnieres").click(); return(false); });
    $("#button-next-boutonnieres").click(function () { $("#slider-corsages").click(); return(false); });
    $("#button-next-corsages").click(function () { $("#slider-ceremony").click(); return(false); });
    $("#button-next-ceremony").click(function () { $("#slider-reception").click(); return(false); });
    
    // Attach subtotal update calculation behavior
    $("#slider-bridalflowers select").change(function () { computeSubTotalBridalFlowers(); computeTotal(); });
    $("#slider-bridalparty select").change(function () { computeSubTotalBridalParty(); computeTotal(); });
    $("#slider-boutonnieres select").change(function () { computeSubTotalBoutonnieres(); computeTotal(); });
    $("#slider-corsages select").change(function () { computeSubTotalCorsages(); computeTotal(); });
    $("#slider-ceremony select").change(function () { computeSubTotalCeremony(); computeTotal(); });
    $("#slider-reception select").change(function () { computeSubTotalReception(); computeTotal(); });
    $("#slider-bridalflowers input").click(function () { computeSubTotalBridalFlowers(); computeTotal(); });
    $("#slider-bridalparty input").click(function () { computeSubTotalBridalParty(); computeTotal(); });
    $("#slider-boutonnieres input").click(function () { computeSubTotalBoutonnieres(); computeTotal(); });
    $("#slider-corsages input").click(function () { computeSubTotalCorsages(); computeTotal(); });
    $("#slider-ceremony input").click(function () { computeSubTotalCeremony(); computeTotal(); });
    $("#slider-reception input").click(function () { computeSubTotalReception(); computeTotal(); });
    computeSubTotalBridalFlowers();
    computeSubTotalBridalParty();
    computeSubTotalBoutonnieres();
    computeSubTotalCorsages();
    computeSubTotalCeremony();
    computeSubTotalReception();
    computeTotal();
    
});

function computeSubTotalBridalFlowers () {
    var subtotal = 0;
    if ($("#bridalflowers-location-bouquet").attr('checked')) {
        subtotal += parseInt($("#bridalflowers-cost-bouquet").val());
    }
    if ($("#bridalflowers-location-throwingbouquet").attr('checked')) {
        subtotal += parseInt($("#bridalflowers-cost-throwingbouquet").val());
    }
    subtotalbridalflowers = subtotal;
    $('#subtotal-bridalflowers').html(formatPrice(subtotal));
    $('#quicktotal-bridalflowers').html(formatQuicktotal(subtotal));
}

function computeSubTotalBridalParty () {
    var subtotal = 0;
    if ($("#bridalparty-location-maidofhonor").attr('checked')) {
        subtotal += parseInt($("#bridalparty-cost-maidofhonor").val());
    }
    if ($("#bridalparty-location-bridesmaids").attr('checked')) {
        subtotal += parseInt($("#bridalparty-quantity-bridesmaids").val() * $("#bridalparty-cost-bridesmaids").val());
    }
    if ($("#bridalparty-location-flowergirl").attr('checked')) {
        subtotal += parseInt($("#bridalparty-cost-flowergirl").val());
    }
    if ($("#bridalparty-location-floralheadpieces").attr('checked')) {
        subtotal += parseInt($("#bridalparty-quantity-floralheadpieces").val() * $("#bridalparty-cost-floralheadpieces").val());
    }
    subtotalbridalparty = subtotal;
    $('#subtotal-bridalparty').html(formatPrice(subtotal));
    $('#quicktotal-bridalparty').html(formatQuicktotal(subtotal));
}

function computeSubTotalBoutonnieres () {
    var subtotal = 0;
    if ($("#boutonnieres-location-groom").attr('checked')) {
        subtotal += parseInt($("#boutonnieres-cost-groom").val());
    }
    if ($("#boutonnieres-location-bestman").attr('checked')) {
        subtotal += parseInt($("#boutonnieres-cost-bestman").val());
    }
    if ($("#boutonnieres-location-groomsmen").attr('checked')) {
        subtotal += parseInt($("#boutonnieres-quantity-groomsmen").val() * $("#boutonnieres-cost-groomsmen").val());
    }
    if ($("#boutonnieres-location-fathers").attr('checked')) {
        subtotal += parseInt($("#boutonnieres-quantity-fathers").val() * $("#boutonnieres-cost-fathers").val());
    }
    if ($("#boutonnieres-location-grandfathers").attr('checked')) {
        subtotal += parseInt($("#boutonnieres-quantity-grandfathers").val() * $("#boutonnieres-cost-grandfathers").val());
    }
    if ($("#boutonnieres-location-others").attr('checked')) {
        subtotal += parseInt($("#boutonnieres-quantity-others").val() * $("#boutonnieres-cost-others").val());
    }
    subtotalboutonnieres = subtotal;        
    $('#subtotal-boutonnieres').html(formatPrice(subtotal));
    $('#quicktotal-boutonnieres').html(formatQuicktotal(subtotal));
}

function computeSubTotalCorsages () {
    var subtotal = 0;
    if ($("#corsages-location-motherofthebride").attr('checked')) {
        subtotal += parseInt($("#corsages-cost-motherofthebride").val());
    }
    if ($("#corsages-location-motherofthegroom").attr('checked')) {
        subtotal += parseInt($("#corsages-cost-motherofthegroom").val());
    }
    if ($("#corsages-location-grandmothers").attr('checked')) {
        subtotal += parseInt($("#corsages-quantity-grandmothers").val() * $("#corsages-cost-grandmothers").val());
    }
    if ($("#corsages-location-others").attr('checked')) {
        subtotal += parseInt($("#corsages-quantity-others").val() * $("#corsages-cost-others").val());
    }
    subtotalcorsages = subtotal;
    $('#subtotal-corsages').html(formatPrice(subtotal));
    $('#quicktotal-corsages').html(formatQuicktotal(subtotal));
}

function computeSubTotalCeremony () {
    var subtotal = 0;
    if ($("#ceremony-location-mainalter").attr('checked')) {
        subtotal += parseInt($("#ceremony-quantity-mainalter").val() * $("#ceremony-cost-mainalter").val());
    }
    if ($("#ceremony-location-aislerunner").attr('checked')) {
        subtotal += parseInt($("#ceremony-cost-aislerunner").val());
    }
    subtotalceremony = subtotal;
    $('#subtotal-ceremony').html(formatPrice(subtotal));
    $('#quicktotal-ceremony').html(formatQuicktotal(subtotal));
}

function computeSubTotalReception () {
    var subtotal = 0;
    if ($("#reception-location-centerpieces").attr('checked')) {
        subtotal += parseInt($("#reception-quantity-centerpieces").val() * $("#reception-cost-centerpieces").val());
    }
    if ($("#reception-location-caketop").attr('checked')) {
        subtotal += parseInt($("#reception-cost-caketop").val());
    }
    if ($("#reception-location-cakemiddle").attr('checked')) {
        subtotal += parseInt($("#reception-cost-cakemiddle").val());
    }
    if ($("#reception-location-cakebase").attr('checked')) {
        subtotal += parseInt($("#reception-cost-cakebase").val());
    }
    if ($("#reception-location-caketable").attr('checked')) {
        subtotal += parseInt($("#reception-cost-caketable").val());
    }
    subtotalreception = subtotal;
    $('#subtotal-reception').html(formatPrice(subtotal));
    $('#quicktotal-reception').html(formatQuicktotal(subtotal));
}

function computeTotal () {
    var total = subtotalbridalflowers + subtotalbridalparty + subtotalboutonnieres + subtotalcorsages + subtotalceremony + subtotalreception;   
    $("#total").html(formatPrice(total));
}
