
var prloadedimgs = new Array(4);
var counter = 400;
var ino = 1;
var i,j,k;

for (i = 0; i < 4; i++)
{
  switch (i)
  {
   case 2: k = "http://www.avon-beach.co.uk/cms/template/coffee"; break;
   case 1: k = "http://www.avon-beach.co.uk/cms/template/shop"; break;
   case 0: k = "http://www.avon-beach.co.uk/cms/template/beach"; break;
   case 3: k = "http://www.avon-beach.co.uk/cms/template/news"; break;
   default: break;
  }
  prloadedimgs[i] = new Array(4);
  for (j = 0; j < 4; j++)
  {
    prloadedimgs[i][j] = new Image();
    prloadedimgs[i][j].src = k + (j + 1) + '.jpg';
  }
}

setTimeout("dochange()", 2500);




function setOpacity(obj, opx) 
{
var opacity = opx;
  if (opacity > 100)
   opacity = 100;
  if (opacity < 0)
   opacity = 0;
  opacity = (opacity == 100)?99.999:opacity;
  obj.style.filter = "alpha(opacity:"+opacity+")";
  obj.style.KHTMLOpacity = opacity/100;
  obj.style.MozOpacity = opacity/100;
  obj.style.opacity = opacity/100;
}

function dochange()
{
var period = 30; 

 shiftimg(0, "rot1", 400);
 shiftimg(1, "rot2", 370);
 shiftimg(2, "rot3", 340);
 shiftimg(3, "rot4", 310);

 counter -= 2;
 if (counter < 0)
 {
  ino++;
  if (ino > 3)
   ino = 0;
  counter = 400;
  period = 2500;
 }
 setTimeout("dochange()", period);
}

function shiftimg(idx, id, start)
{
var obj, op;
 if (counter > start)
  return;
 if (counter < (start - 200))
  return;
 obj = document.getElementById(id);
 if (counter == (start - 100)) 
  obj.setAttribute("src", prloadedimgs[ino][idx].src); 
 if (counter > start - 100)
  op = counter - (start - 100); 
 else
  op = Math.abs((start - 100) - counter);
 setOpacity(obj, op); 
}
