var timeline = new Array();

timeline[0]=new Array(3000, "teletypeBlock('an_text1',70)");
timeline[1]=new Array(3000, "teletypeBlock('an_text2',30)");
timeline[2]=new Array(3000, "showBlocks(['an_text1'])");
timeline[3]=new Array(200, "hideBlocks(['an_text1'])");
timeline[4]=new Array(200, "showBlocks(['an_text1'])");
timeline[5]=new Array(200, "hideBlocks(['an_text2'])");
timeline[6]=new Array(200, "showBlocks(['an_text2'])");
var cur_line=-1;

function do_animation() {
	if(cur_line>timeline.length-2) cur_line=-1;
	cur_line++;
	setTimeout(timeline[cur_line][1], timeline[cur_line][0]);
}

function showBlocks(arr_blocks) {
	for(i=0; i<arr_blocks.length; i++) {
		if(document.getElementById(arr_blocks[i])) document.getElementById(arr_blocks[i]).style.display='block';
	}
	do_animation();
}

function hideBlocks(arr_blocks) {
	for(i=0; i<arr_blocks.length; i++) {
		if(document.getElementById(arr_blocks[i])) document.getElementById(arr_blocks[i]).style.display='none';
	}
	do_animation();
}

function teletypeBlock(block_id, adelay) {
	if(document.getElementById(block_id)) {
		var str=document.getElementById(block_id).innerHTML;
		document.getElementById(block_id).innerHTML='';
		document.getElementById(block_id).style.display='block';
		textticker(block_id, str, adelay);
	}
	do_animation();
}

function textticker(block_id, str, adelay) {
	var t_length=str.length;
	var pos=document.getElementById(block_id).innerHTML.length;//alert(pos)
	document.getElementById(block_id).innerHTML=str.substring(0,pos+1);
	if(pos++==t_length) {
		pos=0;
	}else{
		setTimeout("textticker('"+block_id+"','"+str+"','"+adelay+"')", adelay); 
	}
}
