$(document).ready(function() {
    if ($('#tefProductId').val() > 0)
        tb_show("Share with a friend", "/#TB_inline?height=600&amp;width=708&amp;inlineId=shareWithFriend");
    if ($('#askProductId').val() > 0)
        tb_show("Ask a question", "/#TB_inline?height=710&amp;width=708&amp;inlineId=askQuestion");
});

function paymentPlanUpdate(id) {
    if (id == null)
        id = $('#ppProductId').val();
    else
        $("#paymentPlan2").attr("checked", "true");
    var payments = $("input[name='paymentPlan']:checked").val();
    if (!(payments > 1)) payments = 2;
    $.getJSON("ajaxPaymentPlan.do?productId=" + id + "&paymentPlan=" + payments, function(data) {
        $("#ppPrice").html(data.price);
        $("#ppTitle").html(data.title);
        $("#ppProductId").val(id);
        for (var i=1; i<=6; i++)
            $("#ppMonth" + i).css("display", "none");
        $("#ppDeposit").html(data.deposit);
        for (var i=1; i <= payments; i++) {
            $("#ppMonth" + i).css("display", "inline");
            if (i < payments)
                $("#ppPayment" + i).html(data.next);
            else
                $("#ppPayment" + i).html(data.last);
        }
    });
}

function tefUpdate(id) {
    $('#tefProductId').val(id);
}

function askUpdate(id) {
    $('#askProductId').val(id);
    $('#askSubject').val($('#productTitle' + id).html() + " / " + id);
    $('#askSubject').blur();
}

function showImage(productId, imageId) {
    $('#mainImage' + productId).attr('src', $('#image' + imageId).attr('src'));
    $('#mainImage' + productId).attr('imageId', imageId);
}

function mainImageClick(productId) {
    Shadowbox.open(document.getElementById('imageLink' + $('#mainImage' + productId).attr('imageId')));
}
