function spellsTimer() {
    var spells = document.getElementsByName('spell'),
        opacity = {},
        currentTime = {},
        timeAction = {},
        timeOut,
        speed = 1000,
        time = {};

    if (spells.length > 0) {
        for (var i = 0; i < spells.length; i++) {
            currentTime[i] = spells[i].attributes.time.value * 1000;
            timeAction[i] = 0;
            opacity[i] = null;
            if (spells[i].attributes.spellId !== undefined) {
                opacity[i] = document.getElementById('spell_' + spells[i].attributes.spellId.value);
            }
            if (spells[i].attributes.timeact !== undefined) {
                timeAction[i] = spells[i].attributes.timeact.value;
            } else {
               opacity[i].style.opacity = 0.7;
            }
            timeOut = isFloat(currentTime[i]) ? currentTime[i] - Math.floor(currentTime[i])  : 0;
            timeOut = Math.floor(timeOut * 1000);
            setTimeout(function (index) {
                currentTime[index] = Math.floor(currentTime[index] / 1000);
                spells[index].innerHTML = currentTime[index];
                time[index] = setInterval(function () {
                    currentTime[index] -= 1;
                    if (currentTime[index] <= 0) {
                        if (timeAction[index] > 0) {
                            opacity[index].style.opacity = 0.7;
                            currentTime[index] = parseInt(timeAction[index]);
                            spells[index].style.color = 'white';
                            spells[index].innerHTML = currentTime[index];
                            timeAction[index] = 0;
                            console.log(currentTime[index]);
                        } else {
                            opacity[index].style.opacity = 1;
                            spells[index].innerHTML = '';
                            clearInterval(time[index]);
                        }
                    } else {
                        spells[index].innerHTML = currentTime[index];
                    }
                }, speed);
            }, timeOut, i);
        }
    }
}
spellsTimer();

function isFloat(n) {
    return n === +n && n !== (n|0);
}