//ADJUST PHOTO ARRAY HERE - FIRST ONE MUST EXIST TO RESERVE SPACE ON SCREEN
var photos=new Array("images/main-pic.jpg","images/main-pic2.jpg","images/main-pic3.jpg","images/main-pic4.jpg");
//TIME BETWEEN PHOTOS
tpause = 3000;
//FADE SPEED - USE 15 and UP - SMALLER MEANS FASTER
tfade = 15;
//FADE STEP (1-100) - USE MULTIPLE OF 100 IF POSSIBLE, THE SMALLER THE SMOOTHER THE EFFECT, THE LARGER THE QUICKER THE FADE
fadestep = 1
//ADJUST PHOTO WIDTH, HEIGHT, TOP POSITION, LEFT POSITION
phw = 480; phh = 320; pht = 132; phl = 210;
//TAKE THIS OUT IF YOU DO NOT WANT TO CENTER IN MAIN WINDOW
//phl = 150+(600-phw)/2;
//phl = window.innerWidth/2 - 165;

function justfilename(URL) {
   var xstart = URL.lastIndexOf("/") + 1;
   var xend = URL.length;
   var hereName = URL.substring(xstart,xend);
   return hereName;
}


function swap() {
    var x;
    for (x in photos) {
        if (justfilename(photos[x]) == justfilename(document.pic2.src) ) {
            currentone = x;
            next = parseInt(x) + 1;
        }
        lastone = x;
    }
    document.pic1.src = document.pic2.src;
    if (currentone == lastone) {
       document.pic2.src = photos[0];
    }
    else {
        document.pic2.src = photos[next];
    }

    var t=setTimeout("delayswap(" + 100 + ")",tpause);
}


function OpCtrl(x1) {
x1 = x1 - fadestep;
document.pic1.style.opacity=x1/100;
document.pic1.style.filter='alpha(opacity=' + x1 + ')';

x2 = 100 - x1
document.pic2.style.opacity=x2/100;
document.pic2.style.filter='alpha(opacity=' + x2 + ')';

delayswap(x1);
}


function delayswap(x1) {
    if (x1>0) {
        var t=setTimeout("OpCtrl(" + x1 + ")",tfade);
    }
    else {
        document.pic1.style.opacity=100;
        document.pic1.style.filter='alpha(opacity=' + 100 + ')';
        document.pic2.style.opacity=0;
        document.pic2.style.filter='alpha(opacity=' + 0 + ')';
        swap();
    }
}

function getX(obj)
{
  return( obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+getX(obj.offsetParent) );
}
function getY(obj)
{
return( obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+getY(obj.offsetParent) );
}

//ADJUST SIZE AND POSITION OF FADE PICTURE HERE
document.write("<p align='left'><img id='pic0' src=" + photos[0] + " style='opacity:0;filter:alpha(opacity=0);width:" + phw + "px;height:" + phh + "px;top:" + pht + "px;'/><br/>");

document.write("<img name='pic1' id='pic1' src=" + photos[0] + " style='z-index:2;position:absolute;'/><br/>");
document.write("<img name='pic2' id='pic2' src=" + photos[1] + " style='z-index:1;opacity:0;filter:alpha(opacity=0);position:absolute; float:left;'/>");

document.getElementById("pic1").style.width = document.getElementById("pic0").style.width;
document.getElementById("pic1").style.height = document.getElementById("pic0").style.height;
document.getElementById("pic1").style.left = document.getElementById("pic0").style.left;
document.getElementById("pic1").style.top = document.getElementById("pic0").style.top;
document.getElementById("pic2").style.width = document.getElementById("pic0").style.width;
document.getElementById("pic2").style.height = document.getElementById("pic0").style.height;
document.getElementById("pic2").style.left = document.getElementById("pic0").style.left;
document.getElementById("pic2").style.top = document.getElementById("pic0").style.top;

var t=setTimeout("delayswap(" + 100 + ")",tpause);

