/*-------------Adjustments----------------------------------*/

// Delay between slides (milliseconds)
var delay = 4000;

// Delay between fade frames (milliseconds)- higher number slows down the fade
var fadedelay = 2;

// Smooth out the fade.  Lower number = smoother, but needs more processing power on the client
var smooth = 1;


/*-------------Don't adjust below this line-----------------*/
function addLoadEvent(func) {
    if (window.addEventListener) {
        window.addEventListener("load", func, false);
    }
    else if (window.attachEvent) {
        window.attachEvent("onload", func);
    }
    else {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        }
        else {
            window.onload = function() {
                if (oldonload) {
                    oldonload();
                }
                func();
            };
        }
    }
}

var images = '';
var topimage = 0;


function setupFade()
{
	images = document.getElementById('gallerycontent').getElementsByTagName('img');
	
	for(var i=0; i<images.length; i++)
	{
		images[i].style.zIndex = i+10;
		images[i].style.display="block";
	}
	
	topimage = images.length-1;
	setTimeout("fadeout()", delay);
}

addLoadEvent(setupFade);


function fadenext()
{	
	var temp = images[0].style.zIndex;
	
	for(var i=0; i<images.length-1; i++)
	{
		images[i].style.zIndex = images[i+1].style.zIndex;
	}
	
	images[images.length-1].style.zIndex = temp;
	
	setopacity(100);
	topimage--;
	
	if(topimage<0)
	{
		topimage=images.length-1;
	}
	
	setTimeout("fadeout()", delay);
}

function fadeout()
{
	for(i=100; i>=0; i-=smooth)
	{
		setTimeout("setopacity("+i+")", fadedelay*(100-i));
	}
	setTimeout("fadenext()", fadedelay*(100+smooth));
}

function setopacity(perct)
{
	images[topimage].style.opacity=(perct/100);
	images[topimage].style.MozOpacity=(perct/100);
	images[topimage].style.khtmlOpacity=(perct/100);
	images[topimage].style.filter='alpha(opacity='+perct+')';
}