var slideshowPics = false;

new Event.observe(document,'dom:loaded',function(){
	// ! ga snel naar
	$$('div.gsn-placeholder').each(function(gsn){
		gsn.observe('click',function(){
			// de goede openen
			var open = false;
			if(!gsn.hasClassName('open')){
				open = true;
			}
			
			// de andere sluiten
			$$('div.gsn-placeholder').invoke('removeClassName','open');
			$$('div.gsn ul').each(function(lijst){
				if(lijst.visible()){
					new Effect.Fade(lijst,{duration:0.2});
				}
			});
			
			if(open){
				new Effect.Appear($('gsn-'+(gsn.id.split('-')[1])+'-lijst'),{duration:0.2});
				gsn.addClassName('open');
			}
		});
	});
    
});

// slideshow config
var ss_im_1 = false;
var ss_im_2 = false;
var ss_nu = 1;
var ss_aantal = 0;
var ss_target = false;
var ss_interval = 3000;
var ss_random = false;
var ss_animatie = false;
var ss_roling = true;

// init slideshow
function slideshow(){
	ss_target = $$('div.startpagina-image')[0];
	ss_aantal = slideshowPics.length;
	
	// containers
	var c1 = new Element('div',{'id':'ss_1','class':'slideshowImage'}).hide();
	var c2 = new Element('div',{'id':'ss_2','class':'slideshowImage'}).hide();
	ss_target.appendChild(c1);
	ss_target.appendChild(c2);
	
	// target afluisteren op een click
	if(ss_animatie){
		// flash bij klik
		slideshow_flash();
		
		// hint bij over
		var overlay = new Element('div',{'id':'slideshowOverlay','class':'slideshowOverlay','title':'Bekijk de volledige film'});//.hide();
		overlay.appendChild(new Element('div',{'class':'inner'}));//.update('Bekijk de volledige film'));
		ss_target.appendChild(overlay);
		new Event.observe(ss_target,'mouseenter',function(){
			overlay.addClassName('actief');
		});
		new Event.observe(ss_target,'mouseleave',function(){
			overlay.removeClassName('actief');
		});
		/*
		new Event.observe(ss_target,'mouseenter',function(){
			overlay.show();
		});
		new Event.observe(ss_target,'mouseleave',function(){
			overlay.hide();
		});
		*/
	}
	
	// eerste opstarten, daarna vanzelf
	var p1 = new Element('img');
	new Event.observe(p1,'load',function(){
		c1.appendChild(p1);
		new Effect.Appear(c1);//.show();
		
		setTimeout(function(){
			slideshow_shuffle(1);
		},ss_interval)		
	});
	p1.setAttribute('src',slideshowPics[0]);
}

// speel flash-animatie
function slideshow_flash(){
	$$('div.themas')[0].appendChild(new Element('div',{'id':'startpagina-flash'}));
	new Event.observe(ss_target,'click',function(){
		ss_roling = false;
		new Effect.Fade(ss_target);
		
		// eerst swfobject lazy-loaden
		LazyLoader.load('site/js/swfobject/swfobject.js', function(){
		
			// nu flash-ding spelen
		  	var params = {wmode:"transparent"};//
			swfobject.embedSWF(ss_animatie, "startpagina-flash", "877", "500", "9.0.0", "site/js/swfobject/expressInstall.swf",{},params);
		});		
	});
}

// volgende afbeelding
function slideshow_shuffle(nu){
	if(ss_roling){
		var show = nu == 1 ? 2 : 1;
		var hide = nu == 1 ? 1 : 2;
		var next = 0;
		
		$('ss_'+show).update();
		var p1 = new Element('img');
		new Event.observe(p1,'load',function(){
			$('ss_'+show).appendChild(p1);
			new Effect.Fade($('ss_'+hide));
			new Effect.Appear($('ss_'+show));//.show();
			
			setTimeout(function(){
				slideshow_shuffle(show);
			},ss_interval)		
		});
		
		// volgende?
		if(ss_random){
			next = Math.floor(Math.random()*ss_aantal);
		}else{
			next = ss_nu++;
			if(next >= ss_aantal){
				next = ss_nu = 0;
			}
		}
		
		p1.setAttribute('src',slideshowPics[next]);
	}
}
