// Michelle Rajunov
// Binary Clock
// Oct 31, 2008


var imgPath = "img/";

function updateBinaryClock() {
	var today = new Date();
		

	update("S", today.getSeconds());
	update("M", today.getMinutes());
	update("H", today.getHours()%12);
	setTimeout('updateBinaryClock()',1000);
}


function update(group, time){
	
	time = Math.round(time);	
	$("#"+group).text(""+ time);
	
	var lim = 6;
	if(group == "H")	lim = 4;
	
	for(var x = 1; x<=lim; x++){
		var rand = (Math.floor(Math.random()*8)) %8;	
		rand++;	
		if(rand!=1 && rand!=2 && rand!=3 && rand!=4 && rand!=5 && rand!=6 && rand!=7 && rand!=8)
			rand = 1;
		
		if(time%2 == 0)	{		// change to 0
			if($("#bc"+group+x).hasClass("1")){		//only change if it is 1
				$("#bc"+group+x).attr("src", imgPath+"binary0_"+rand+".png");
				$("#bc"+group+x).attr("class", "0"); 
				}
		}
		else{					// change to 1
			if($("#bc"+group+x).hasClass("0")){		//only change if it is 0
				$("#bc"+group+x).attr("src", imgPath+"binary1_"+rand+".png");
				$("#bc"+group+x).attr("class", "1");
			}	
		}

		time = (time - time%2)/2;	
	}
}




