var fotoSlide = Class.create();
fotoSlide.prototype = {
        initialize: function(_photoList,_txtList,_timeout) {
		if($('fotoSlide')){


			if(typeof(_timeout) == 'undefined' || _timeout == null){
				this.timeout = 3;
			} else {
				this.setTimeout(_timeout);
			}

			if(typeof(_photoList) == 'undefined' || _photoList == null){
				this.photoList = ['','/images/tpl/f1.jpg','/images/tpl/f2.jpg','/images/tpl/f3.jpg'];
				this.txt = ['','Lorem ipsum dolor sit amet','Consectetur adipisicing elit','Ut enim ad minim veniam, quis nostrud exercitation ']
			} else {
				this.photoList = _photoList;
				this.txt = _txtList;
			}
		
			this.count = 1;
			var div = $('fotoSlide');
			div.setStyle({
				textAlign: 'center'
			});

			var obj = this;	
		
			if(typeof(_photoList) != 'undefined'){
				div.innerHTML = "<img src=' " + this.photoList[1] + "' border='0'><br><br><em>" + this.txt[1] + "</em>";
			} else {
				div.innerHTML = "<img src=' " + this.photoList[1] + "' border='0'><br><br><em>" + this.txt[1] + "</em>";
			}
			
			$R(1,this.txt.size(),true).each(
				function(item){
					obj.preload(obj.photoList[item]);		
				}
			);
	
			new PeriodicalExecuter(
				function(pe) {
					obj.count++;
					obj.fadeOut();		
				}, this.timeout
			);
		}
	},

	fadeOut: function(){

		var obj = this;
		new Effect.Opacity('fotoSlide',
		{
			duration: 0.5, 
      			from: 1.0, 
			to: 0,
			afterFinish: function(){
				if(obj.count> (obj.txt.size() -1)) obj.count=1;
				obj.fadeIn();
			},
			beforeStart: function(){
				obj.preload(obj.count + 1 );
			}
			 
		});

	},

	fadeIn: function(){
		var obj = this;
		var div = $('fotoSlide');
		div.innerHTML = "<img src='" + this.photoList[this.count] + "' border='0'><br><br><em>" + obj.txt[obj.count] + "</em>" ;
		new Effect.Opacity('fotoSlide',
		{
			duration: 0.5, 
      			from: 0, 
			to: 1.0 
		});

	},

	preload: function(nFoto){
      		preload_image_object = new Image();
             	image_url = new Array();
 		image_url = nFoto;
		preload_image_object.src = image_url;
	},

	setTimeout: function(val){
		this.timeout = val;
	}
	
}
