window.addEventListener?window.addEventListener("load",init,false):window.attachEvent("onload",init);

var TRANS_WAIT = 10;       // amount of seconds in between transitions
var IMG_DIR = "./images/"; //the image directory
var IMAGES  = new Array( IMG_DIR + "header_1.jpg",
                         IMG_DIR + "header_2.jpg" );

var front,
    back;

var nCur  = 0;
var nNext = nCur + 1,
    d     = document;


function init() {
    TRANS_WAIT *= 1000;
    setInterval( changePic, TRANS_WAIT );
}

function changePic() {

    img = d.getElementById( "header" ).getElementsByTagName( "img" );

    if( !d.getElementById || ! d.getElementsByTagName ){ return false; }

    if( !IMAGES[nNext] ) {
        front = IMAGES[IMAGES.length-1];
        back  = IMAGES[0];
        nCur = 0
        nNext = 1;

    }else {
        front = IMAGES[nCur++];
        back  = IMAGES[nNext++];
      }


    var b = "<a href=\"./\"><img id=\"back\" style=\"position:absolute;top:11px;height:189px;border:0;\" src=\""+back+"\" / >";
    var f = "<img id=\"front\" style=\"position:absolute;top:11px;height:189px;border:0;\" src=\""+front+"\" / ></a>";


    d.getElementById( "header" ).innerHTML = b+f;

    img[1].xOpacity = .99;
    setOpacity( img[1] );

    img[0].xOpacity = .00;
    setOpacity( img[0] );

    trans();
}

function trans() {

    if( img[1].xOpacity < .0 || img[0].xOpacity > .99 ){ return false; }

        img[1].xOpacity -= .05;
        setOpacity( img[1] );

        img[0].xOpacity += .05;
        setOpacity( img[0] );

        setTimeout( trans, 50 );
}

function setOpacity(obj) {
	if(obj.xOpacity>.99) {
		obj.xOpacity = .99;
		return;
	}
	obj.style.opacity = obj.xOpacity;
	obj.style.MozOpacity = obj.xOpacity;
    obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
}