/* Slide Show */

//////////////////////////
// CONFIGURABLE

// the delay in seconds
// between changing slides
var slide_interval = 6;

// duration of time spent
// fading the slide in
// value is in seconds
var fade_interval = 1;

// END CONFIGURABLE
//////////////////////////

// holds all slide images
// retrieved from the html
var fc_slides = new Array();

function start_the_show()
{ 
  // retrieve the children of the slide show container to determine the slides
  var nodes = document.getElementById('home-slideshow-slides').childNodes;
  
  // initialize the slide show slides
  for (var i = 0; i<nodes.length; i++)
  {
    if (get_class(nodes[i]) == 'slide')
      fc_slides[fc_slides.length] = nodes[i];      
  }
  fc_slides[0].style.visibility = 'visible';

  
  // use the standard technique
  // for preloading all images 
  // that are a part of show
  var d = document;
  if (d.images)
  {
    if (!(d.ROT_imgs instanceof Array)) d.ROT_imgs = new Array();
    var j = d.ROT_imgs.length;
    for (var i=0; i<fc_slides.length; i++)
    {
      document.ROT_imgs[j] = new Image();
      document.ROT_imgs[j].src = fc_slides[i].src;
      j++;
    }
  }
  // advance to the next slide after an initial delay 
  setTimeout("next_slide()", (slide_interval*1000));
}

function next_slide()
{
//   if (document.getElementById('logo2').style.visibility == 'hidden')
//	document.getElementById('logo2').style.visibility = 'visible';
  // this function determines the next
  // slide by checking the current visible
  // image among the slides then advances 
  // to the next slide and displays it with
  // the appropriate fade in transition
  
  var next = 0;  
  for (var i = 0; i<fc_slides.length; i++)
    if (fc_slides[i].style.display == 'block')
    {
      next = (i+1) % fc_slides.length;      
      break;
    }
  
  for (var i = 0; i<fc_slides.length; i++)
  {
    fc_slides[i].style.display = 'none';
    changeOpac(0, fc_slides[i].id);
  }
  
  fc_slides[next].style.display = 'block';
  fc_slides[next].style.visibility = 'visible';

//  if (fc_slides[next].id == 'home-slide-blank') {
//	document.getElementById('logo2').style.visibility = 'hidden';
//  }
  opacity(fc_slides[next].id, 0, 100, (fade_interval*1000));
  setTimeout("next_slide()", (slide_interval*1000));
}

function get_class(el)
{
  // internet explorer stores the 
  // class name in a non standard
  // attribute so safely retrieve
  // the class name with this method

  if (!el) return null;
  else 
    if (el.className) return el.className;
    else 
      if (el.getAttribute) return el.getAttribute('class');
      else return null;
}

/* Incorporated From "www.brainerror.com" */

// Cross-browser transparency functions (source: http://www.brainerror.net/scripts_js_blendtrans.php)
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
    
} 


