/**
 * 
 */
function ajax_update_wishlist_counter(count)
{
    $("#ajax-wishlist-counter").fadeOut().html(count).fadeIn();
    
}

/**
 * Count real image dimension
 */
function dep_count_real_dimension(x, y, z)
{
    // max width and height of image, set by css
    var max_x = 335;
    var max_y = 335;
    
    if (x > y)
    {
        var css_x = max_x;
        var y_ratio = max_x / x;
        var css_y = Math.floor(y * y_ratio);
        //console.log(css_x + '|' + css_y);
    }
    else if (y > x)
    {
        var css_y = max_y;
        var x_ratio = max_y / y;
        var css_x = Math.floor(x * x_ratio);
        //console.log(css_x + '|' + css_y);
    }
    else
    {
        var css_x = max_x;
        var css_y = max_y;
        //console.log(css_x + '|' + css_y);
    }
    if (z == 'x') return css_x;
    if (z == 'y') return css_y;
    if (z == 'm')
    {
        var margin = Math.floor((max_x - css_x) / 2);
        return margin + 5;
    }
}

function get_x(x, y)
{
    return count_real_dimension(x, y, 'x');
}
function get_y(x, y)
{
    return count_real_dimension(x, y, 'y');
}
function get_margin(x, y)
{
    return count_real_dimension(x, y, 'm');
}
function get_xy(x, y)
{
    var xx = get_x(x, y);
    var yy = get_y(x, y);
    
    if (xx < yy)
    {
        return xx;
    }
    else if (yy < xx)
    {
        return yy;
    }
    else
    {
        return xx;
    }
}
function set_initial_values(x, y)
{
    $('input[name="x1"]').val(0);
    $('input[name="y1"]').val(0);
    //
    var second = get_xy(x, y);
    //
    $('input[name="x2"]').val(second);
    $('input[name="y2"]').val(second);
}
function count_new_aspect_ratio()
{
    var final_width = $('input[name="final_width"]').val();
    var final_height = $('input[name="final_height"]').val();
    //console.log(final_width + ' x ' + final_height);
    // ratio
    var ratio = (final_width + ':' + final_height);    
    console.log(ratio);
}

/* basket */
//
function order_check()
{
    var payment = $("input[name=payment]:checked").val();
    var delivery = $("input[name=delivery]:checked").val();
    
    if (delivery == 'dpd')
    {
        window.delivery_cost = delivery_dpd;
    }
    else
    {
        window.delivery_cost = 0;
    }
    
    set_amount();
}

function set_amount()
{
    window.total_amount = total_basket + delivery_cost;
   
    var delivery_cost_html = delivery_cost.toFixed(2);
    $("#ajax-total-delivery span").hide().html(delivery_cost_html).fadeIn(500);
    
    var total_basket_html = total_amount.toFixed(2);
    $("#ajax-total-basket span").hide().html(total_basket_html).fadeIn(500);
    
    $("input[name=total_amount]").val(total_basket_html);
    $("input[name=delivery_cost]").val(delivery_cost_html);
}

