var DHTML =
   (document.getElementById || document.all || document.layers);
if (!DHTML) {
   alert('Your browser is not capable of displaying DHTML');
}

function getObj(name) {
   if (document.getElementById) {
      this.obj = document.getElementById(name);
      this.style = document.getElementById(name).style;
   } else
   if (document.all) {
      this.obj = document.all[name];
      this.style = document.all[name].style;
   } else
   if (document.layers) {
      this.obj = document.layers[name];
      this.style = document.layers[name];
   }
}

function visib(objName, flag) { // triggers layer visibility
   x = new getObj(objName);
   x.style.visibility = (flag) ? 'visible' : 'hidden';
}


slides = new Array(
   'slide0',
   'slide1',
   'slide2',
   'slide3',
   'slide4',
   'slide5',
   'slide6'
   );

var fadeOn = true;
function setFade(switchFade) {// Fade switch function
   if ( !fadeOn ) {
      prepLyr(slides[curImg], true);
      } else { // No fade
      stopFade();
      for ( var i = 0; i < 7; i++ ) {
         prepLyr(slides[i], true);
         if ( slides[i] != slides[curImg] )
            visib(slides[i], false);
      }
   }
   fadeOn = switchFade;
}


var curImg = 0; // index of the array entry
var lastImg = 0;

function changeSlide ( change ) {
   if (!DHTML) return;
   //curImg += change;
   //if ( curImg < 0 ) curImg = slides.length-1;
   //else
     // if ( curImg >= slides.length ) curImg = 0;
  
curImg = Math.ceil(Math.random() * 1000) % 7;

   
   if ( fadeOn ) {
      firstFade = true;
      prepLyr(slides[lastImg], true );
      fadeLayer(slides[lastImg], 10, 50);
   } else {
      visib(slides[lastImg], false);
      visib(slides[curImg], true);
   }
   lastImg = curImg;
}

var clipTop, clipWidth, clipBottom, lyrheight;
var time,amount,theTime,middle;
var slideSize = new Array()

function prepLyr(lyr, vis) {
   if (!DHTML) return;
   x = new getObj( lyr );
   if (document.layers) {
      if ( !slideSize[lyr] ) {
         lyrheight = x.style.clip.bottom;
         clipWidth = x.style.clip.right;
         slideSize[lyr] = lyrheight + 'x' + clipWidth;
      } else {
         lyrheight = parseInt(slideSize[lyr]);
         clipWidth = slideSize[lyr].substr(
            slideSize[lyr].indexOf('x')+1);
      }
      if ( vis ) {
         clipTop = 0;
         middle = Math.round(lyrheight/2);
         clipBottom = lyrheight;
      } else {
         middle = Math.round(lyrheight/2);
         clipBottom = middle;
         clipTop = middle;
      }
      x.style.clip.top = clipTop;
      x.style.clip.left = 0;
      x.style.clip.right = clipWidth;
      x.style.clip.bottom = clipBottom;
      x.style.visibility = 'show';
   } else
   if (document.getElementById || document.all) {
      lyrheight = x.obj.offsetHeight;
      clipWidth = x.obj.offsetWidth;
      if ( vis ) {
         clipTop = 0;
         middle = Math.round(lyrheight/2);
         clipBottom = lyrheight;
      } else {
         middle = Math.round(lyrheight/2);
         clipBottom = middle;
         clipTop = middle;
      }
      x.style.clip =
        'rect('+clipTop+' '+clipWidth+' '+ clipBottom +' 0)';
      visib(lyr, true);
   }
}


function fadeLayer(layername, amt, tim) {
   if (!DHTML) return;
   thelayer = new getObj( layername );
   if (!thelayer) return;
   amount = amt;
   theTime = tim;
   realFade();
}

function stopFade() {
   if (time) clearTimeout(time);
}

function realFade() {
   clipTop += amount;
   clipBottom -= amount;
   if (clipTop < 0 || clipBottom > lyrheight || clipTop > middle) {
      if ( clipTop > middle ) thelayer.style.visibility = 'hidden';
      if ( firstFade ) nextFade();
      return;
   }
   if (document.getElementById || document.all) {
      clipstring = 'rect('+clipTop+' '+clipWidth+' '+clipBottom+' 0)'
      thelayer.style.clip = clipstring;
   }   else
   if (document.layers) {
      thelayer.style.clip.top = clipTop;
      thelayer.style.clip.bottom = clipBottom;
   }
   time = setTimeout('realFade()',theTime);
}

var firstFade = true;
function nextFade() {
   firstFade = false;
   prepLyr(slides[curImg], false);
   fadeLayer(slides[curImg], -10, 50);
}

