<script type="text/javascript" >
var timer=null;
var aNow=null;
var g_aImg=[];//用来存图片
var g_oImgWeek=null;//用来存显示星期几的图片
var g_aWeekName=["one","two","three","four","five","six","seven"];
window.onload=function(){
var a=document.getElementById('clock');
var b=a.getElementsByTagName('img');
var i=0;
for(i=0;i<b.length;i++){
if(!isNaN(parseInt(b[i].alt))){
g_aImg.push(b[i])
}
}
g_aImg.push(b[b.length-2]);
aNow=getTimeArray();
for(i=0;i<g_aImg.length;i++){
g_aImg[i].now=-1
}
checkSwitch();//让时钟开始运行
setInterval(checkSwitch,1000)//每隔一秒钟时钟动一次
};
var g_iImgHeigth=0;
var g_iTarget=0;
var g_iMax=0;
function checkSwitch(){
var i=0;
aNow=getTimeArray();
g_imgHeigth=g_aImg[0].offsetHeight;
g_iTarget=-g_imgHeigth;
g_iMax=g_imgHeigth;
timer=setInterval(doSwitch,30)
}
function doSwitch(){
var a=false;
var i=0;
g_imgHeigth-=10;
if(g_imgHeigth<=g_iTarget){
g_imgHeigth=g_iTarget;
a=true
}
for(i=0;i<g_aImg.length;i++){
if(g_aImg[i].now!=aNow[i]){
if(g_imgHeigth>0){
g_aImg[i].style.height=g_imgHeigth+'px';
g_aImg[i].style.top=-(g_iMax-g_imgHeigth)/2+'px'
}else{
if(i==g_aImg.length-1){
g_aImg[i].src="images/"+g_aWeekName[aNow[i]]+".png"
}else{
g_aImg[i].src="images/"+aNow[i]+".png";
}
g_aImg[i].style.height=-g_imgHeigth+'px';
g_aImg[i].style.top=-(g_iMax+g_imgHeigth)/2+'px'
}
}
}
if(a){
for(i=0;i<g_aImg.length;i++){
g_aImg[i].now=aNow[i]
}
clearInterval(timer)
}
}
function toDouble(a){//把小于10的时间补成两位数,比如把5补成05
if(a<10)
return'0'+a
else
return''+a
}
function getTimeArray(){//做一个时间数组,把时间放在数组里,便于操作
var a=new Date();
var b=[];
var c=a.getYear();
var d=a.getMonth();
var e=a.getDate();
var f=a.getHours();
var g=a.getMinutes();
var h=a.getSeconds();
var j=(a.getDay()+6)%7;
if(c<1900){c+=1900}
var k=''+(c)+toDouble(d+1)+toDouble(e)+toDouble(f)+toDouble(g)+toDouble(h)+j;
var l=k.split('');
for(i=0;i<l.length;i++){
b[i]=parseInt(l[i])
}
return b
}
</script>