//alert('aaap');
var slide_effects	= new Array();
var this_		= "";
var timer		= "";
var current_active 	= 0;


var imgs='';
var slideShow= new Class( { 
	  initialize: function(beeldEl, options){
	
	  	this.options = Object.extend({
		module: 	100,
		id: 		0,
		actie: 		0
	  	}, options || {});
		this_		= this;
		this.beeldEl	=$(beeldEl);
		$('gallerie').setStyle("opacity", "1");
		$('pauze').style.display='block';
		$('stop').style.display='block';
		
		//this.module	= this.options.module;
		this.id		= this.options.id;
		this.path	= "images/fotos/";
		this. img_width1='';
		this. img_width2='';
		
		
		
		if(timer){
		window.clearInterval(timer);
		$('gallerie').innerHTML='';
		}
		
		//if(this_){
		//delete(this.images);
		//}
		
		this.getVars();
		
		this.pauze	= 0;
		//this.images	= new Array("sp1.jpg", "sp2.jpg", "sp3.jpg", "sp4.jpg");
		//this.comments	= new Array("sp1.jpg", "sp2.jpg", "sp3.jpg", "sp4.jpg");
		
		
		this.createEls();
		
		
		
		this.current_active 	= 0;
		this.current_image 	= 0;
		
		
		//this.Slide();
		
		//this.setActions();
			
		this.timer 		= this.Slide.periodical(2500);
		timer			= this.timer;
		//alert(timer);
	
	  },

getVars: function(){	
		new Ajax('updater.php', {method: 'post', update: 'floatwindow', data: 'f=getimages&serie='+this.id, evalResponse:true}).request();;
		},		
		
Stop: function(){
		window.clearInterval(timer);
		delete(this_);
		//delete(this);
		$('stop').style.display='none';
		$('pauze').style.display='none';
		slide_s=new Fx.Styles($('gallerie'), {duration:200, wait:false});
		slide_s.start({
		'opacity': 0
		});
		
		(function(){
		$('gallerie').innerHTML='';	
		}).delay(275); 
		
		},
	
Pauze: function(status){
		this.actie=(status==2) ? 0 : this.actie;
		this.actie=(status==1) ? 1 : this.actie;
		if(!status){
		this.actie=(this.pauze==1) ? 0 : 1;
		}
		
		
		this.isrc=(this.actie==1) ? "images/play.gif" : "images/pauze.gif";
		this.itxt=(this.actie==1) ? "play" : "pauze";
		this.pauze=this.actie;
		$('pauze_img').src=this.isrc;
		$('pauzespan').innerHTML=this.itxt;
		//window.status=this.pauze;
		},
		
createEls: function(){
		
	
		if(!this.images){
		(function(){
		this_.createEls();		
		}).delay(175); 

		}else{
		
		this.canvas0	= document.createElement("DIV");
		this.canvas0.id	= "canvas0_0";
		
		
		
		this.beeldEl.appendChild(this.canvas0);
		
		
		this.canvas1	= document.createElement("DIV");
		
		this.canvas1.id	= "canvas0_1";
		
		this.beeldEl.appendChild(this.canvas1);
		this.canvas1.style.position='absolute';
		this.canvas1.style.top='0px';
		this.canvas1.style.Zindex='10';
		//this.canvas1.setStyles('position: absolute; top:430px;z-index: 10;');
	

		this.img1	= document.createElement("IMG");	
		
		this.img1.src	= this.path+this.images[0];
		this.img1.width= 580;
		this.img1.id	= "slide_img1"
		this.img1.className="slide_img";
		
		this.span1	= document.createElement("SPAN");	
		this.span1.id	= "span1"
		this.span1.innerHTML="-";
		
		
		this.canvas0.appendChild(this.img1);
		
		this.canvas0.appendChild(this.span1);
		
		
		
		$('slide_img1').setStyles('position: absolute; top:0px');
		$('span1').setStyles('width:580px;position: absolute; top:440px;text-align:center');
				
		this.img2	= document.createElement("IMG");	
		this.img2.src	=this.path+this.images[1];
		this.img2.width= 580;
		this.img2.id	="slide_img2"
		this.img2.className="slide_img";
		
		//alert(this_.comments);	
		this.canvas0.appendChild(this.img2);
		$('slide_img2').setStyles('position: absolute; top:0px');
		
		
		slide_effects[0] = new Fx.Styles($('slide_img1'), {duration:2500, wait:false});
		slide_effects[1] = new Fx.Styles($('slide_img2'), {duration:2500, wait:false});
		
		this.setActions();
		
		}
		
		},
		
	
Slide: function(){
		this.even	= (this_.current_active % 2== 0) ? 1 : 0; //voor de interval in het effect
		this.cimage	= (this_.current_image % 2== 0) ? 1 : 0; //actieve img
	
		if(this_.pauze==0){
		
		if(this.even==1){ 	
	
		
		/************** effecten ***************/
		
		
		if(this.cimage==1){
		this.nimg1='';
		this.nimg1=new Image();
		this.nimg1.src=this_.path+""+this_.images[this_.current_image];
		this.img_width1=(this.nimg1.width>=this.nimg1.height) ? 580: 326 ;//
		window.status=1+" | "+this.img_width1+" w:"+this.nimg1.width+" h:"+this.nimg1.height;
		$('slide_img1').src=this_.path+""+this_.images[this_.current_image];
		$('slide_img1').alt=this_.comments[this_.current_image];
		
		$('slide_img1').width=this.img_width1;
		
		$('span1').innerHTML=this_.comments[this_.current_image];
		slide_effects[0].start({
		'opacity': 1
		});
		
		slide_effects[1].start({
		'opacity': 0
		});
		/**/
		}else{
		this.nimg2='';
		this.nimg2=new Image();
		this.nimg2.src=this_.path+""+this_.images[this_.current_image];
		
		this.img_width2=(this.nimg2.width>=this.nimg2.height) ? 580: 326 ;//
		window.status=2+" | "+this.img_width2+" w:"+this.nimg2.width+" h:"+this.nimg2.height;
		$('slide_img2').src=this_.path+""+this_.images[this_.current_image]; 
		$('slide_img2').alt=this_.comments[this_.current_image];
		$('slide_img2').width=this.img_width2;
		$('span1').innerHTML=this_.comments[this_.current_image];	
		slide_effects[0].start({
		'opacity': 0
		});
		
		slide_effects[1].start({
		'opacity': 1
		});
		/**/
		}
		
		/************** effecten ***************/		
		
		this_.current_image++;	
		}
		
		
			
		this_.current_image =(this_.current_image<this_.images.length) ? this_.current_image : 0;	//curr image
		this_.current_active++;	
		this_.current_active =(this_.current_active<this_.images.length) ? this_.current_active : 0;	//teller		
		}
		
		},
		
setActions: function(){
		this.imgs = $$('.slide_img');
		
		this.imgs.each(function(imgEL){ 
		
		imgEL.addEvent('mouseenter', function(){
		this_.pauze=1;	
		this_.Pauze(1);	
		});
		
		
		imgEL.addEvent('mouseleave', function(){
		this_.pauze=0;	
		this_.Pauze(2);	
		
		});
		
		});
		}


});