function weapsTimer() {
    var weaps = document.getElementsByName('weap'),
        opacity = {},
        currentTime = {},
        timeAction = {},
        timeOut,
        speed = 1000,
        time = {};

    if (weaps.length > 0) {
        for (var i = 0; i < weaps.length; i++) {
            currentTime[i] = weaps[i].attributes.time.value * 1000;
            timeAction[i] = 0;
            opacity[i] = null;
            if (weaps[i].attributes.weapId !== undefined) {
                opacity[i] = document.getElementById('weap_' + weaps[i].attributes.weapId.value);
            }
            if (weaps[i].attributes.timeact !== undefined) {
                timeAction[i] = weaps[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);
                weaps[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]);
                            weaps[index].style.color = 'white';
                            weaps[index].innerHTML = currentTime[index];
                            timeAction[index] = 0;
                            console.log(currentTime[index]);
                        } else {
                            opacity[index].style.opacity = 1;
                            weaps[index].innerHTML = '';
                            clearInterval(time[index]);
                        }
                    } else {
                        weaps[index].innerHTML = currentTime[index];
                    }
                }, speed);
            }, timeOut, i);
        }
    }
}
weapsTimer();

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

