var ofDelay = 5000;
var ofFadeDelay = 1000;
var imagens = new Array();
imagens[0] = "image-1";
imagens[1] = "image-2";
imagens[2] = "image-3";

var arrLen = imagens.length;
var arrPos = 0;
var maxPos = parseInt(arrLen - 1);

function imPad(dir) {
	imClearAll();
	switch (dir) {
	case 0:
		arrPos--;
		if (arrPos < 0) { arrPos = maxPos; }
		break;
	case 1:
		arrPos++;
		if (arrPos > maxPos) { arrPos = 0; }
		break;
	default:
	}
	
	changeOpac(0, imagens[arrPos]);
	document.getElementById(imagens[arrPos]).className = 'image_on';
	opacity(imagens[arrPos],1,100);
}

function imClearAll() {
	for (i=0;i<arrLen;i++) {
		document.getElementById(imagens[i]).className = 'image_off';
	}
}

function imGallery() {
	imPad(1);
	setTimeout("imGallery()",ofDelay);
}

function opacity(id, opacStart, opacEnd) {
    //speed for each frame
    var speed = Math.round(ofFadeDelay / 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("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 