var delay = 3000; 
var start_frame = 0;  

function init() { 	
	var lis = $('slide-images').getElementsByTagName('li');
 	for( i=0; i < lis.length; i++){ 		//if(i!=0){ 			
		lis[i].style.display = 'none'; 		//} 	
	} 	
	end_frame = lis.length -1; 	 	
	start_slideshow(start_frame, end_frame, delay, lis); 	 	 
}    

function start_slideshow(start_frame, end_frame, delay, lis) {
	setTimeout(fadeInOut(start_frame,start_frame,end_frame, delay, lis), delay); 
}

function fadeInOut(frame, start_frame, end_frame, delay, lis) { 	
	return (function() { 		
		lis = $('slide-images').getElementsByTagName('li'); 		
		Effect.Fade(lis[frame]);
		if (frame == end_frame) { frame = start_frame; } else { frame++; }
		lisAppear = lis[frame];
		Effect.Appear(lisAppear, { duration: 2.0 }); 		
		setTimeout(fadeInOut(frame, start_frame, end_frame, delay), delay + 1850);
	}) 	 
}   
//Event.observe(window, 'load', init, false);  
// properties are directly passed to `create` method 
var SlideTV = Class.create({
	initialize: function(target, delay) {
		this.delay = delay;
		this.currentImg = 0;
		this.appearDuration = 1.0;
		this.fadeDuration = 1.0;
		this.lis = target.getElementsByTagName('li');
		for( i=0; i < this.lis.length; i++){
			this.lis[i].style.display = 'none';
		} 
		/*
		lis.each(function(img){
			img.style.display = 'none';
			return false;
		});
		*/
		var that = this;
		Effect.Grow(this.lis[this.currentImg]);
		setInterval(function() { that.fade();}, that.delay*1000);
		
	},   
	fade: function() {
		//alert("out now!");
		var nextImg = (this.currentImg+1)%this.lis.length;
		Effect.Fade(this.lis[this.currentImg], { duration: this.fadeDuration })
		Effect.Appear(this.lis[nextImg], { duration: this.fadeDuration });
		this.currentImg = nextImg;   
	}
});

function start(){
	TVinst = new SlideTV($("slide-images"), 2);
}

var SlideMenu = Class.create({
	initialize: function(target, delay) {
		this.delay = delay;
		this.currentImg = 0;
		this.appearDuration = 2.0;
		this.fadeDuration = 3.0;
		this.lis = target.getElementsByTagName('li');
		for( i=1; i < this.lis.length; i++){
			this.lis[i].style.display = 'none';
		} 
		var that = this;
		setInterval(function() { that.fade();}, that.delay*1000);
		
	},   
	fade: function() {
		var nextImg = (this.currentImg+1)%this.lis.length;
		//var fad = new Effect.Fade(this.lis[this.currentImg], {sync: true });
		this.lis[this.currentImg].setStyle({zIndex: 2});
		this.lis[nextImg].setStyle({zIndex: 1});
		this.lis[nextImg].show();
		//Effect.Appear(this.lis[nextImg], { duration: this.appearDuration });
		new Effect.Fade(this.lis[this.currentImg], { duration: this.fadeDuration });
		//new Effect.Parallel([app, fad], {duration: 4});		
		this.currentImg = nextImg;   
	}
});


function start_menu(){
	MENUinst = new SlideMenu($("slide-head"), 5);
}
//window.observe('load', new SlideTV($("slide-images"), 2));
//Event.observe(window, 'load', start);