ids = Array('day','month','year','user');
colors = Array('#B0B1B2','#505153','#3E3F41','#B01A48');
messages = Array('transactions <br>per day:','transactions <br>per month:','transactions <br>per year:','number of users <br>online:');
values = Array('- - -','- - -','- - -','- - -');
heartbeatTimer=false;
heartbeatStatus='init';

function initHeartbeat(){
	if (heartbeatTimer) window.clearTimeout(heartbeatTimer);
	paras = document.getElementById('heartbeat').getElementsByTagName('P');
	for (i=0;i<paras.length;i++) {
		paras[i].style.display='block';
		paras[i].style.backgroundColor='';
		if(paras[i].firstChild) paras[i].firstChild.className='';
	}
	heartbeatMessage('<span>connecting ...</span>');
	window.setTimeout('getData()',2000);
}
function getData(){
	request('/heartbeat.php');
	heartbeatMessage('<span>receiving Data ...</span>');
}
function showData(id){

}
function showHeartbeat(index){
	id=ids[index];
	para=document.getElementById('heartbeat_'+id);
	para.firstChild.className='active';
	para.style.backgroundColor=colors[index];
	heartbeatMessage(index);

	images=document.getElementById('heartbeat').getElementsByTagName('IMG');
	image=images[0];
	image.style.marginLeft=(1-(index+1)*31)+'px';
	image.parentNode.style.marginLeft=((index+1)*34-15)+'px';

	if (ids[index+1]) window.setTimeout('showHeartbeat('+(index+1)+')',500);
	else {
		image.src='img/bar_ready.gif';
		if (heartbeatTimer) window.clearTimeout(heartbeatTimer);
		heartbeatTimer=window.setTimeout('heartbeatCountdown();',1000);
		window.setTimeout('heartbeatMessage(2);',500);
	};

}

function heartbeatCountdown(){
	images=document.getElementById('heartbeat').getElementsByTagName('IMG');
	image=images[0];
	margin=parseInt(image.parentNode.style.marginLeft);
	margin -=1;
	if (margin>-2){
		image.parentNode.style.marginLeft=margin+'px';
		if (heartbeatTimer) window.clearTimeout(heartbeatTimer);
		heartbeatTimer=window.setTimeout('heartbeatCountdown()',80);
	} else {
		image.src='img/bar_busy.gif';
		image.style.marginLeft='';
		initHeartbeat()
	}

}

function heartbeatMessage(html){
	if (typeof(html)=='number') html='<b>'+values[html]+'</b>'+'<span>'+messages[html]+'</span>';
	document.getElementById('heartbeatMessage').innerHTML=html;
}
function heartbeatStop(){
	if (heartbeatTimer) {
		window.clearTimeout(heartbeatTimer);
		heartbeatStatus='stopped';
	}
}
function heartbeatResume(){
	if (heartbeatStatus=='stopped'){
		heartbeatTimer=window.setTimeout('heartbeatCountdown();',100);
		heartbeatStatus='countdown'
	}
}