
(function()
{
    function init()
    {
        updateEpoch();
    }

    function format(amount)
    {
        amount = Math.round(amount);
        amount = String(amount);

        var delimiter = ","; // replace comma if desired
        var i = amount;
        if(isNaN(i)) { return ''; }
        var minus = '';
        if(i < 0) { minus = '-'; }
        i = Math.abs(i);
        var n = new String(i);
        var a = [];
        while(n.length > 3)
        {
            var nn = n.substr(n.length-3);
            a.unshift(nn);
            n = n.substr(0,n.length-3);
        }
        if(n.length > 0) { a.unshift(n); }
        n = a.join(delimiter);
        amount = n;
        amount = minus + amount;
        return amount;
    }

    function updateEpoch()
    {
        var milliseconds = (new Date()).getTime();
        var seconds = Math.round( milliseconds/1000 );

        var epoch = document.getElementById('epoch');
        epoch.innerHTML = format( seconds );
        setTimeout(updateEpoch, 100);
    }

    // Initialisation -- have init() run once page has finished loading
    var $;
    if( $ && $(document).ready )        // jQuery
    {
        $(document).ready( init );
    }
    else if( window.addEventListener)   // DOM Level-2
    {
        window.addEventListener('load', init, false);
    }
    else if( window.attachEvent)        // Sigh... Internet Explorer
    {
        window.attachEvent('onload', init);
    }

})();