// JavaScript Document   

//========================================================================================================================================
//========================================================================================================================================
//========================================================================================================================================

//change these two to change the speed of the transition and the interval between each transition noob
var switchInterval = 8000;
var switchSpeed = 1;

//========================================================================================================================================
//========================================================================================================================================
//========================================================================================================================================

var fadeCount = 0;
var fadeCountOut = 0;
var intervalOut = 20;
var interval = 20;

function fadeInObject(object, speed ){
  fadeCount = 0;
  interval = speed;
  faderIn(object);
  document.getElementById(object).style.display = 'block';
}
function faderIn(object){
  if(fadeCount < 10){
    document.getElementById(object).style.opacity = fadeCount/10;
    document.getElementById(object).style.filter = 'alpha(opacity='+fadeCount*10+');';
    
    fadeCount = fadeCount + .1;
    t = setTimeout("faderIn('"+object+"')",interval);
  }
}

function fadeOutObject(object, speed ){
  fadeCountOut = 10;
  intervalOut = speed;
  faderOut(object);
}
function faderOut(object){
  if(fadeCountOut > 0){
    document.getElementById(object).style.opacity = fadeCountOut/10;
    document.getElementById(object).style.filter = 'alpha(opacity='+fadeCountOut*10+');';
    
    fadeCountOut = fadeCountOut - .1;
    t = setTimeout("faderOut('"+object+"')",intervalOut);
  }else{
    document.getElementById(object).style.display = 'none';
  }
}

var objectList = new Array();
var length = 0;
var current = 0;
var playStatus = 'stop';

function startSlideshow(itemName){
  var object;
  var count = 0;

  while(object = document.getElementById(itemName+count)){
    objectList[count] = itemName+count;
    count ++;
  }
  
  var objectID = 0;
  length = objectList.length;

  playStatus = 'play';
  loopThrough();

}

function loopThrough(){
  if(playStatus == 'play'){
    fadeInObject(objectList[current],switchSpeed);
    showStop();
    var lastItem = current - 1;
  
    if(lastItem != -1){
      fadeOutObject(objectList[lastItem],switchSpeed);
    }else{
      fadeOutObject(objectList[length-1],switchSpeed);
    }
  
    current ++;
    if(current == length){
      current = 0;
    }
    
    t = setTimeout("loopThrough()",switchInterval);
  }else{
    showPlay();
  }
}

function showPlay(){
  //var controls = "<button onclick=\"startSlideshow('block')\">Start</button>";
  
  //document.getElementById('blockControls').innerHTML = controls;
}

function showStop(){
  //var controls = "<button onclick=\"playStatus='stop';\">Pause</button>";
  
 //document.getElementById('blockControls').innerHTML = controls;
}