//delaybar.js - Last update: 14 May 2010

var delaytime;							//number of seconds for progress bar	external defined
var redirect;								//redirection URL											external defined
var unloadedcolor;					//colour unloaded bar area						external defined
var txt;										//printed text above the bar					external defined
var loadedcolor='#F0D020';	//colour progress bar
var bordercolor='#F0F0A0';	//border colour
var barheight=12;						//height of progress bar in pixels
var barlength=440;					//length of the bar in pixels

var ns4=(document.layers)?true:false;
var ie4=(document.all)?true:false;
var blocksize=(barlength-2)/delaytime/20;
var loaded=0;
var PBouter;
var PBdone;
var PBbckgnd;
var Pid=0;

if(ns4){
txt+='<table border=0 cellpadding=0 cellspacing=0><tr><td>';
txt+='<ilayer name="PBouter" visibility="hide" height="'+barheight+'" width="'+barlength+'" onmouseup="hidebar()">';
txt+='<layer width="'+barlength+'" height="'+barheight+'" bgcolor="'+bordercolor+'" top="0" left="0"></layer>';
txt+='<layer width="'+(barlength-2)+'" height="'+(barheight-2)+'" bgcolor="'+unloadedcolor+'" top="1" left="1"></layer>';
txt+='<layer name="PBdone" width="'+(barlength-2)+'" height="'+(barheight-2)+'" bgcolor="'+loadedcolor+'" top="1" left="1"></layer>';
txt+='</ilayer>';
txt+='</td></tr></table>';
}else{
txt+='<div id="PBouter" onmouseup="hidebar()" style="position:relative; visibility:hidden; background-color:'+bordercolor+'; width:'+barlength+'px; height:'+barheight+'px">';
txt+='<div style="position:absolute; top:1px; left:1px; width:'+(barlength-2)+'px; height:'+(barheight-2)+'px; background-color:'+unloadedcolor+'; font-size:1px"></div>';
txt+='<div id="PBdone" style="position:absolute; top:1px; left:1px; width:0px; height:'+(barheight-2)+'px; background-color:'+loadedcolor+'; font-size:1px"></div>';
txt+='</div>';
}

document.write(txt);

function incrCount(){
loaded++;
if(loaded<0)loaded=0;
//display the remaining delay time in the window status bar
window.status="Waiting "+parseInt(delaytime-loaded/20+1)+" seconds...";
if(loaded>=delaytime*20){
clearInterval(Pid);
loaded=delaytime*20;
//after countdown is complete, wait before new page
setTimeout('hidebar()',250);
}
resizeEl(PBdone, 0, blocksize*loaded, barheight-2, 0);
}

function hidebar(){
clearInterval(Pid);
window.status='';
//redirect to a new URL when the delay is done
window.location=redirect;
}

function findlayer(name,doc){
var i,layer;
for(i=0;i<doc.layers.length;i++){
layer=doc.layers[i];
if(layer.name==name)return layer;
if(layer.document.layers.length>0)
if((layer=findlayer(name,layer.document))!=null)
return layer;
}
return null;
}

function progressBarInit(){
PBouter=(ns4)?findlayer('PBouter',document):(ie4)?document.all['PBouter']:document.getElementById('PBouter');
PBdone=(ns4)?PBouter.document.layers['PBdone']:(ie4)?document.all['PBdone']:document.getElementById('PBdone');
resizeEl(PBdone,0,0,barheight-2,0);
if(ns4)PBouter.visibility="show";
else PBouter.style.visibility="visible";
Pid=setInterval('incrCount()',45);
}

function resizeEl(id,t,r,b,l){
if(ns4){
id.clip.left=l;
id.clip.top=t;
id.clip.right=r;
id.clip.bottom=b;
}else id.style.width=r+'px';
}

window.onload=progressBarInit;
