/* http://www.brainerror.net/scripts_js_blendtrans.php */

var pictures;
var holder;
var destbox;

var jspictures = new Array(15);
var jscounter = 0;

jspictures[0] = 'images/SAWA/pic1.jpg';
jspictures[1] = 'images/SAWA/pic2.jpg';
jspictures[2] = 'images/SAWA/pic3.jpg';
jspictures[3] = 'images/SAWA/pic4.jpg';
jspictures[4] = 'images/SAWA/pic5.jpg';
jspictures[5] = 'images/SAWA/pic6.jpg';
jspictures[6] = 'images/SAWA/pic7.jpg';
jspictures[7] = 'images/SAWA/pic8.jpg';
jspictures[8] = 'images/SAWA/pic9.jpg';
jspictures[9] = 'images/SAWA/pic10.jpg';
jspictures[10] = 'images/SAWA/pic11.jpg';

jspictures[11] = 'images/SAWA/pic12.jpg';
jspictures[12] = 'images/SAWA/pic13.jpg';
jspictures[13] = 'images/SAWA/pic14.jpg';
jspictures[14] = 'images/SAWA/pic15.jpg';

function initPics()
{
   //get cached picture holder
   holder = document.getElementById('pichold');
   
   destbox = document.getElementById('csimageshow');
   
   pictures = holder.childNodes;
}

function startTrans()
{
   //fade out
   opacity('slidery',100,0,600);
   setTimeout("opacity('slidery',0,100,600)",800); //Delay CHange OVER 0.8 Sec
   setTimeout("startTrans()",20000); //Stay on 20 Sec
   
   
    //opacity('slidery',100,0,600);
   //setTimeout("opacity('slidery',0,100,600)",800);
  // setTimeout("startTrans()",10000);
}

//change the opacity for different browsers
function changeOpacUp(opacity, id)
{
   var object = document.getElementById(id).style;
   object.opacity = (opacity / 101);
   object.MozOpacity = (opacity / 101);
   object.KhtmlOpacity = (opacity / 101);
   object.filter = "alpha(opacity=" + opacity + ")";
} 

function changeOpacObj(opacity, objecter)
{
   var object = objecter.style;
   object.opacity = (opacity / 101);
   object.MozOpacity = (opacity / 101);
   object.KhtmlOpacity = (opacity / 101);
   object.filter = "alpha(opacity=" + opacity + ")";
} 

function changeOpacDown(opacity, id)
{
   var object = document.getElementById(id).style;
   object.opacity = (opacity / 101);
   object.MozOpacity = (opacity / 101);
   object.KhtmlOpacity = (opacity / 101);
   object.filter = "alpha(opacity=" + opacity + ")";

   if(opacity == 0)
   {
      var new_img = new Image();
      new_img.src = jspictures[getLoadPic()];
      
      var newpic = getNewPic().cloneNode(false);
      holder.removeChild(getNewPic());
      var oldpic = getOldPic().cloneNode(false);
      //set newpic opcaity to 0
      newpic.setAttribute('id','tobezeroed');
      changeOpacObj(0,newpic);
      
      oldpic.setAttribute('id','');
      //stick next pic on back of holder queue
      
      oldpic.src = new_img.src;
      holder.appendChild(oldpic);
      destbox.replaceChild(newpic,getOldPic());
      newpic.setAttribute('id','slidery');
      
      jscounter++;
      
      if(jscounter >= jspictures.length)
      {
         jscounter = jscounter - jspictures.length;
      }
   }
}

function getLoadPic()
{
   var nextimg = jscounter+2;
   if(nextimg >= jspictures.length)
   {
      nextimg = nextimg - jspictures.length;
   }
   
   return nextimg;
}

function getNewPic()
{
   for(var x = 0;x < pictures.length;x++)
   {
      if(pictures[x].nodeName == 'SPAN' || pictures[x].nodeName == 'IMG')
      {
         return pictures[x];
      }
   }
}

function getOldPic()
{
   return document.getElementById('slidery')
}


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("changeOpacDown(" + i + ",'" + id + "')",(timer * speed));
         timer++;
      }
   }
   else if(opacStart < opacEnd)
   {
      for(i = opacStart; i <= opacEnd; i++)
      {
         setTimeout("changeOpacUp(" + i + ",'" + id + "')",(timer * speed));
         timer++;
      }
   }
}

