$(document).ready(function(){

    $('a[rel=image]').fancybox({

        transitionIn: 'elastic',
        transitionOut: 'elastic',
        easingIn: 'easeOutBack',
        easingOut: 'easeInBack',
        cyclic: true

    });

});

/**
 * Highlight compartive table
 * 
 * @param hash
 */
function HostingHighlight(hash)
{
    var m_hash = hash.charAt(0).toUpperCase() + hash.substr(1);

    $('div.HostingCompare table td').removeClass('Highlight');
    $('td.All, td.' + m_hash).addClass('Highlight');
    
    document.location.hash = hash;
}

/**
 * Update order prices
 *
 * @param string form
 * @param integer base_price
 * @param integer install_fees
 */
function UpdatePrice(form, base_price, install_fees, tva)
{
    var total = parseFloat(base_price);

    $('form[name=' + form + '] input[type=text], form[name=' + form + '] input:checked, form[name=' + form + '] select option:selected').each(function(){

        if($(this).attr('type') == 'text')
        {
            if($(this).attr('id') == 'ace_form_kw')
            {
                total+= parseFloat($(this).attr('price') * ($(this).val()));
            }
            else if($(this).attr('price'))
            {
                total+= parseFloat($(this).attr('price') * ($(this).val() - 1));
            }
        }
        else if($(this).attr('type') == 'checkbox' || $(this).attr('type') == 'radio')
        {
            if($(this).attr('unique'))
            {
                install_fees += parseFloat($(this).attr('price'));
            }
            else
            {
                total += parseFloat($(this).attr('price'));
            }
        }
        else
        {
            if ($(this).attr('unique')) {
                install_fees += parseFloat($(this).attr('price'));
            }
            else {
                total += parseFloat($(this).attr('price'));
            }
        }

    });

    var tva = (total + install_fees) * tva;

    $("#OrderTotal").html(format_number(total));
    $("#OrderFees").html(format_number(install_fees));
}

function format_number(num, floor)
{
    if(floor === true)
    {
        num = Math.floor(num);
    }

    return num.toFixed(2);
}
