var timer='';
var timer1='';
var ssinit=false;
var slidetime='7000';

document.write("<style>.slideshow {overflow: hidden;}</style>");

function ss_init(ssid, fade) {

if(ssinit) {return;}
ssinit=true;

if(!document.childNodes){
document.getElementById(ssid).style.overflow='auto';
return;
}

document.getElementById(ssid).style.overflow='hidden';

var x=document.getElementById(ssid).childNodes;

var firstdiv=-1;
for(i=0;i<x.length;i++) {
if(x[i].nodeName=='DIV'){

//var childdiv=x[i].getElementsByTagName('div')[0]
//var childimg=x[i].getElementsByTagName('img')[0]

x[i].style.position="absolute";
x[i].style.top="0px";
x[i].style.left="0px";

if(firstdiv==-1){
   firstdiv=i;
   x[i].style.zIndex="99";
}else{
   x[i].style.zIndex="0";
//if(childdiv){childdiv.style.zIndex="-1";}else{x[i].style.zIndex="-1";}
//if(childdiv&&childimg){childimg.style.zIndex="-1";}
}

var childdiv=x[i].getElementsByTagName('div')[0]
if(childdiv){thediv=childdiv;}else{thediv=x[i];}

var captiontext=thediv.innerHTML;
var newcaptiontext="<table onmouseover=\"ss_mouseover(this)\"  onmouseout=\"ss_mouseout(this)\"><tr><td class=\"ssnav\"><a href=\"javascript:ss_next('"+ssid+"',-1)\">&laquo;</a></td><td>"+captiontext+"</td><td class=\"ssnav\"><a href=\"javascript:ss_next('"+ssid+"',1)\">&raquo;</a></td></tr></table>";
thediv.innerHTML=newcaptiontext;
thediv.style.paddingLeft="0px";
thediv.style.paddingRight="0px";

}
}

document.getElementById(ssid).toppage=firstdiv;
document.getElementById(ssid).fade=fade;

var newdiv= document.createElement('div');
var newdivtext = document.createTextNode('Paused');
newdiv.appendChild(newdivtext);
newdiv.setAttribute('id','ss_paused');
document.getElementById(ssid).appendChild(newdiv);

timer=setTimeout('ss_next("'+ssid+'",1,'+fade+')',slidetime);
}

function ss_next(ssid,dir,fade) {

clearTimeout(timer)

var tp=document.getElementById(ssid).toppage;
var x=document.getElementById(ssid).childNodes;

var np=tp+dir;
if(np<0){np=x.length-2}else{if(np>x.length-2){np=0}}
/*nb using x.length-2 as extra childnode added in init function*/


while(x[np].nodeName!='DIV'||x[np].id=='ss_paused') {
np=np+dir;
if(np>x.length-1){np=0}
if(np<0){np=x.length-1}
}


//tpdiv=x[tp].getElementsByTagName('div')[0];
//npdiv=x[np].getElementsByTagName('div')[0];
//tpimg=x[tp].getElementsByTagName('img')[0];
//npimg=x[np].getElementsByTagName('img')[0];


if(fade>0) {
/*give toppage higher zindex so next page will have the appropriate z-index for the top layer once the fade has finished; toppage will be lowered at end of fade by animateFade */
x[tp].style.zIndex="100";

//tpdiv.style.zIndex="61";
//tpimg.style.zIndex="60";

document.getElementById(ssid).FadeTimeLeft=fade;
setTimeout("animateFade(" +new Date().getTime()+ ",'" + ssid + "',"+fade+","+tp+")", 33);
}else{

x[tp].style.zIndex="0";

//if(tpdiv){tpdiv.style.zIndex="-1";}else{x[tp].style.zIndex="-1";}
//if(tpdiv&&tpimg){tpimg.style.zIndex="-1";}
}

x[np].style.zIndex="99";

//if(npdiv){npdiv.style.zIndex="51";}else{x[np].style.zIndex="51"}
//if(npdiv&&npimg){npimg.style.zIndex="50";}

document.getElementById(ssid).toppage=np;
timer=setTimeout('ss_next("'+ssid+'",1,'+fade+')',slidetime);
}

function animateFade(lastTick, ssid, TimeToFade, oldTopPage)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var show = document.getElementById(ssid);
 
  var oldtpdiv=show.childNodes[oldTopPage].getElementsByTagName('div')[0];
  var oldtpimg=show.childNodes[oldTopPage].getElementsByTagName('img')[0];  

  if(show.FadeTimeLeft <= elapsedTicks)
  {
    /*change z-index then make fully opaque again*/
    show.childNodes[oldTopPage].style.zIndex="0";

    //oldtpdiv.style.zIndex="-1";
    //oldtpimg.style.zIndex="-1";
    oldtpdiv.style.opacity =  '0.9';
    oldtpdiv.style.filter = "alpha(opacity = '90')";
    oldtpimg.style.opacity =  '1';
    oldtpimg.style.filter = "alpha(opacity = '100')";
    return;
  }
 
  show.FadeTimeLeft -= elapsedTicks;
  var newOpVal = show.FadeTimeLeft/TimeToFade;
  var newOpVal1 = show.FadeTimeLeft/TimeToFade*0.9;

  oldtpdiv.style.opacity = newOpVal1;
  oldtpdiv.style.filter = 'alpha(opacity = ' + (newOpVal1*100) + ')';
  oldtpimg.style.opacity = newOpVal;
  oldtpimg.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';

  setTimeout("animateFade(" + curTick + ",'" + ssid + "',"+TimeToFade+","+oldTopPage+")", 33);
}

function ss_mouseover() {
/* pause after 1 sec of hovering */
timer1=setTimeout(ss_pause,1000)
}

function ss_mouseout(obj) {

while(obj.className!="slideshow") {obj=obj.parentNode;}
ssid=obj.id


/* stop hover-timer from mouseover() */
clearTimeout(timer1);
/*if had already paused then start transition timer*/
if(timer==''){
timer=setTimeout('ss_next("'+ssid+'",1,'+document.getElementById(ssid).fade+')',slidetime);}
document.getElementById('ss_paused').style.zIndex='-2';
}

function ss_pause() {

clearTimeout(timer);
timer='';
document.getElementById('ss_paused').style.zIndex='100';
}



