$(document).ready(function(){

    valimg = new Array('<img src="images/zero.png" alt="0" />','<img src="images/one.png" alt="1" />','<img src="images/two.png" alt="2" />','<img src="images/three.png" alt="3" />','<img src="images/four.png" alt="4" />','<img src="images/fife.png" alt="5" />','<img src="images/six.png" alt="6" />','<img src="images/seven.png" alt="7" />','<img src="images/eight.png" alt="8" />','<img src="images/nine.png" alt="9" />');

    tooltip();
    $('a[href="#"]').click(function(){
        return false;
    });

    $(':input[type="checkbox"]').change(function(){   
        var day_now = parseFloat($('#pday span').html());
        var pos = $(this).attr('name');
        pos = pos.substring(pos.search('_')+1,pos.length);
        var take = parseFloat($('div.table._2 ul:eq('+pos+') li.col_5').html());
        if(this.checked==false){
            $(this).after('<span class="overlay"></span>');
            $('#pday span').html(Math.round((day_now-take)* 10000) / 10000);
            $('#pmonth span').html(30*Math.round((day_now-take)* 10000) / 10000);
        }else{
            $("[name='"+this.name + "'] + .overlay").remove();
            $('#pday span').html(Math.round((day_now+take)* 10000) / 10000);
            $('#pmonth span').html(30*Math.round((day_now+take)* 10000) / 10000);
        }
    });
    var wert=0.000;
    var i=1;
    var count = $('div.table._2 ul:not(".table_top")').length;

    for(var i=1;i<=count;i++){

        wert=wert+parseFloat($('div.table._2 ul:eq('+i+') li.col_5').html());


    }
    $('#pday span').append(Math.round(wert * 10000) / 10000);
    $('#pmonth span').append(30*Math.round(wert * 10000) / 10000);

    function topval(){
        var max =  $('#pmonth span').html();
        var string = '<img src="images/dollar.png" alt="$" />&nbsp;';
        for(var i=0;i<max.length;i++){
            if(max.substr(i,1)!='.'){
                string += valimg[parseInt(max.substr(i,1))];
            }else{
                string += '<img src="images/comma.png" alt="," />';
            }
        }
        $('p#topval').html(string);
    }
    topval();

});