// CircularCounter // Author: Aleksandar Kalanj var COUNTING_DOWN = 0; var WAITING = 1; var state; // Tacno vreme emitovanja jedne od emisija (GMT, sekunde): var radioTime = 1139083200; // Vreme trajanja emisije (u sekundama): var duration = 3600; // Da li poruku treba ispisati na cirilici: var isCyrillic = true; var countDownTime; // Brojac na dole (u sekundama). function initCounter(isCyr) { isCyrillic = isCyr; setCountDownTime(); countDown(); } function setCountDownTime() { // Trenutno vreme u sekundama. var now = Math.round((new Date()).getTime() / 1000); while (radioTime + duration < now) { // Ako je emisija vec prosla pomera se vreme za 7 dana kasnije. radioTime += 7 * 24 * 60 * 60; } if (radioTime < now) { state = WAITING; countDownTime = radioTime + duration - now; } else { state = COUNTING_DOWN; countDownTime = radioTime - now; } } function getDigit(number, digitPosition) { if (digitPosition == 1) { return number % 10; } else if (digitPosition == 2) { return parseInt(number / 10) % 10; } } function countDown() { var time = countDownTime; var text; var displayElement = document.getElementById("countDownText"); if (state == COUNTING_DOWN) { seconds = time % 60; minutes = parseInt(time / 60) % 60; hours = parseInt(time / (60 * 60)) % 24; days = parseInt(time / (24 * 60 * 60)) % 60; if (isCyrillic) { text = "До емисије је остало:
"; } else { text = "Do emisije je ostalo:
"; } text += ""; text += days; if (getDigit(days, 1) == 1 && getDigit(days, 2) != 1) { text += (isCyrillic ? " дан, " : " dan, "); } else { text += (isCyrillic ? " дана, " : " dana, "); } text += ""; text += ""; text += hours; if (getDigit(hours, 1) == 1 && getDigit(hours, 2) != 1) { text += (isCyrillic ? " сат, " : " sat, "); } else if ((getDigit(hours, 1) == 2 || getDigit(hours, 1) == 3 || getDigit(hours, 1) == 4) && getDigit(hours, 2) != 1) { text += (isCyrillic ? " сата, " : " sata, "); } else { text += (isCyrillic ? " сати, " : " sati, "); } text += "\n"; text += ""; text += minutes; if (getDigit(minutes, 1) == 1 && getDigit(minutes, 2) != 1) { text += (isCyrillic ? " минут, " : " minut, "); } else { text += (isCyrillic ? " минута, " : " minuta, "); } text += "\n"; text += ""; text += seconds; if (getDigit(seconds, 1) == 1 && getDigit(seconds, 2) != 1) { text += (isCyrillic ? " секунд." : " sekund."); } else if ((getDigit(seconds, 1) == 2 || getDigit(seconds, 1) == 3 || getDigit(seconds, 1) == 4) && getDigit(seconds, 2) != 1) { text += (isCyrillic ? " секунде." : " sekunde."); } else { text += (isCyrillic ? " секунди." : " sekundi."); } text += "\n"; } else { text = (isCyrillic ? "Емисија је у току." : "Emisija je u toku."); } displayElement.innerHTML = text; countDownTime--; if (countDownTime <= 0) { if (state == COUNTING_DOWN) { countDownTime = duration; state = WAITING; } else { setCountDownTime(); state = COUNTING_DOWN; } } window.setTimeout("countDown()", 1000); }