$(document).ready(function(){



    $('.dot_convert').each(function()
    {
        var x = $(this).html();

        if (x[0] == '-')
        {
            x = x.substr(2);
            m = true;
        }

        if (x.length > 3)
        {
            var temp_x = "";
            var counter = 0;
            for (var i = x.length - 1; i >= 0; i--)
                {
                    if ((counter % 3 == 0) && (counter > 0))
                        temp_x += ".";
                    temp_x += x[i];
                    counter++;
                }

                x = "";
                for (var j = temp_x.length - 1; j >= 0; j--)
                {
                    x += temp_x[j];
                }
        }
        $(this).html(x);
    });




    

    function colorMinerals( className, planetMinerals )
    {
        var x;

        $( className ).each(function()
        {
            x = $(this).html();

            if( parseInt(x.replace('.','')) <= parseInt(planetMinerals.replace('.','')) )
                x = '<span class="hmin">' + x + '</span>';
            else
                x = '<span class="nmin">' + x + '</span>';

            $(this).html(x);

        });
    }

    colorMinerals( '.wmin1', $(".min1").html() );
    colorMinerals( '.wmin2', $(".min2").html() );
    colorMinerals( '.wmin3', $(".min3").html() );



function aaa(wsk) {
 
    $(wsk).each(function()
    {
        var x = $(this).html();

        var year = x[0] + x[1] + x[2] + x[3];
        var month = x[5] + x[6];
        var day = x[8] + x[9];

        var hour = x[11] + x[12];
        var minute = x[14] + x[15];
        var second = x[17] + x[18];

        var now = new Date().getTime();
        var future_action = new Date(year,month-1,day,hour,minute,second).getTime();

        second = Math.abs( ( now - future_action ) / 1000 );
        minute = Math.floor( second / 60 ); 
        hour = Math.floor( minute / 60 );
        day = Math.floor( hour / 24 );
        year = Math.floor( day / 365 );

        second = Math.floor( second - minute * 60 );
        minute = Math.floor( minute - hour * 60 );
        hour = Math.floor( hour - day * 24 );
        day = Math.floor( day - year * 365 );

        if( now < future_action)
        {
            x = x[0] + x[1] +  x[2] +  x[3] + '-' +  x[5] + x[6] + '-' + x[8] + x[9] + ' ' + x[11] + x[12] + ':' + x[14] + x[15] + ':' + x[17] + x[18] + "<br />("+((day==0)?"":day+".")+((day==0) &&(hour==0) ?"":((hour<10)?"0"+hour+":":hour+":"))+
            ((hour==0) && (minute==0)?"":((minute<10)?"0"+minute+":":minute+":"))+
            ((hour==0) && (minute==0) && (second==0)?"":((second<10)?"0"+second:second))+")";
        }
        else
            x = "-";

        $(this).html(x);
    });

   
setTimeout(function(){ aaa(wsk); },1000);
}

aaa('.finish_date');
aaa('.finish_build');

});



