const ID = 0;
const COMMENT = 1;
const START = 2;
const LEFT = 3;
const TOP = 4;
const DEFAULT_LEFT = 420
const COMMENT_NUM = 11;
var comments = [
// [element, comment, start_time, default_left, top]
[null, "comment0", 0, DEFAULT_LEFT, 60],
[null, "comment1", 1000, DEFAULT_LEFT, 40],
[null, "comment2", 1000, DEFAULT_LEFT, 80],
[null, "comment3", 2000, DEFAULT_LEFT, 40],
[null, "comment4", 3000, DEFAULT_LEFT, 140],
[null, "comment5", 5000, DEFAULT_LEFT, 40],
[null, "comment6", 5000, DEFAULT_LEFT, 80],
[null, "comment7", 5000, DEFAULT_LEFT, 100],
[null, "comment8", 6000, DEFAULT_LEFT, 80],
[null, "comment9", 6500, DEFAULT_LEFT, 100],
[null, "comment10", 7000, DEFAULT_LEFT, 160]
];
var rtime;
var time=0;
var min = 0;
var index=0;
function controlComments()
{
var child;
time += 50;
if (index < COMMENT_NUM)
while (comments[index][START] < time){
comments[index][ID] = document.createElement("span");
child = comments[index][ID];
document.getElementById("comments").appendChild(child)
child.innerHTML = comments[index][COMMENT];
child.style.color = "black";
child.style.position = "absolute";
child.style.left = comments[index][LEFT] + "px";
child.style.top = comments[index][TOP] + "px";
document.getElementById("comments").appendChild(comments[index][ID])
index += 1;
}
for (i=min;i<index;i++){
if (comments[i][LEFT] > 0){
comments[i][LEFT] -= 5;
comments[i][ID].style.left = comments[i][LEFT] + "px";
}else{
// TODO: spanタグの削除
if (i>min)
min = i;
}
}
}
function doPlay()
{
rtime = setInterval('controlComments()', 50);
}
function doPause()
{
clearInterval(rtime);
}