function countDown(time) {
    var day = new Date(time);
    this.period = day.getTime();
}

countDown.prototype.message = '終了しました！';

countDown.prototype.display = function(ele){
    this.obj = document.getElementById(ele);
    this._getCounter(this);
}

countDown.prototype._getCounter = function(_this){
    var timer = setTimeout(function(){_this._getCounter(_this);}, 1000);

    var now = new Date();
    var total = parseInt((this.period - now.getTime()) / 1000);
    if (0 >= parseInt(total)) {
        _this.obj.innerHTML = _this.message;
        clearTimeout(timer);
        return;
    }
    var sec = total % 60;
    var min = ((total - sec) % 3600) / 60;
    var hour = (total - min * 60 - sec) / 3600;

    _this.obj.innerHTML = '';

    var data = {
        '時間': hour,
        '分':   min,
        '秒':   sec
    };

    for (var i in data) {
        var node = document.createElement('span');
        node.className = 'counter';
        var value = document.createTextNode(data[i]);
        node.appendChild(value);
        _this.obj.appendChild(node);
        _this.obj.appendChild(document.createTextNode(i));
    }
}


