/**
 * Created by JetBrains PhpStorm.
 * User: mbakirov
 * Date: 16.06.11
 * Time: 13:26
 * To change this template use File | Settings | File Templates.
 */
$(document).ready(function(){
    $('.converterWrapper .converter .middle [class|="calc"]').bind('change keyup', function(){
        var from_currency = $('.calc-from-currency').val(),
            from_value = $('.calc-from-value').val(),
            to_currency = $('.calc-to-currency').val(),
            from_value_rub = 0,
            to_value = 0;

        re = /\,/g;
        from_value = from_value.replace(re, ".");
        from_value = parseFloat(from_value);

        if(from_value > 0 && from_currency != to_currency) {
            from_value_rub = rates[from_currency] * from_value;
            to_value = parseFloat((from_value_rub / rates[to_currency]).toFixed(2));
            $('.to-value').val(to_value);
            $('.bottom .rate').html('1 '+from_currency+' = '+parseFloat((rates[from_currency] / rates[to_currency]).toFixed(2))+' '+to_currency+'<br />');
            $('.bottom .course').html('По курсу Центробанка России на '+rates['DATE']);
        }
    });
});
