var delay = 2000;
var current_frame = 0;
var end_frame = 0;
var isPlay = true;
var isFading = false;
var lis1;
function init() {
	lis = $('promos').getElementsByTagName('li');
	
	for( i=0; i < lis.length; i++){
		if(i!=0){
			lis[i].style.display = 'none';
		}
	}
	end_frame = lis.length -1;
	start_slideshow(delay, lis);
}

function start_slideshow(delay, lis) {
	setTimeout(fadeInOut(delay, lis), delay);
}

function fadeInOut(delay, lis) {
    return (function() {
        if (isPlay) {
            lis = $('promos').getElementsByTagName('li');
            Effect.Fade(lis[current_frame]);
            if (current_frame == end_frame) {current_frame = 0; } else {current_frame++; }
            lisAppear = lis[current_frame];
            setTimeout("Effect.Appear(lisAppear);", 0);
            setTimeout(fadeInOut(delay, lis), delay + 1850);
        }
    })
}

function PauseShow() {

    if (isPlay) {
        isPlay = false;
        $("play").style.backgroundPositionY = "0px";
        $("pause").style.backgroundPositionY = "-60px";
    }
    
}


function PlayShow() {
    if (!isPlay) {
        isPlay = true;
        $("pause").style.backgroundPositionY = "0px";
        $("play").style.backgroundPositionY = "-60px";
        setTimeout(fadeInOut(delay, lis), delay);
    }
}

function NextFrame() {
    isPlay = false;
    if (!isFading) {
        $("play").style.backgroundPositionY = "0px";
        $("pause").style.backgroundPositionY = "-60px";
        isFading = true;
        Effect.Fade(lis[current_frame]);
        if (current_frame == end_frame) { current_frame = 0; } else { current_frame++; }
        lisAppear = lis[current_frame];
        Effect.Appear(lisAppear, { afterFinish: function() { isFading = false; } });
    }
}

function PrevFrame() {
    isPlay = false;
    if (!isFading) {
        $("play").style.backgroundPositionY = "0px";
        $("pause").style.backgroundPositionY = "-60px";
        isFading = true;
        Effect.Fade(lis[current_frame]);
        if (current_frame == 0) { current_frame = end_frame; } else { current_frame--; }
        lisAppear = lis[current_frame];
        Effect.Appear(lisAppear, { afterFinish: function() { isFading = false; } });
    }
}

Event.observe(window, 'load', init, false);
