	window.addEvent('domready',function(){
		
		$$('.main').setStyle('display', 'none');								
		$$('.files').setStyle('display', 'none');								
		$$('#pg >.child >.main').setStyle('display', 'block');
		
		////////////////////////////////////////////////////////////////

		var slide_cont=$('slides');
		slide_cont.slides=slide_cont.getElements('.slide');
		slide_cont.active_slide=0;
		
		slide_cont.slides.each(function(s,n){
				s.parent=slide_cont;
				s.fx=new Fx.Tween(s,{
					'duration': 500,
					'onComplete':function(item){
						item.parent.swapDepth();
					}});
				s.fx.set('opacity',1);
		})
		
		slide_cont.swapDepth=function(){
			// z-index + activty
			this.slides[this.active_slide].setStyle('z-index', '0');
			
			this.active_slide=((this.active_slide)? 0 :1 );
			
			this.slides[this.active_slide].setStyle('z-index', '1');
			
		}
		
		slide_cont.swapSrc=function(loaded_img){
			var not_active=((this.active_slide)? 0 :1 );
			this.slides[not_active].getElement('img').src=loaded_img.src;
			this.slides[not_active].fx.set('opacity',1);
			this.slides[this.active_slide].fx.start('opacity',0);
			//alert( "swapsource");
			$('info').set('html', g_info);
			$('pl').setStyle('z-index', '0');						
		}	
			
		slide_cont.load_slide=function(src){
				$('pl').setStyle('z-index', '3');
				//$('pl').set('html', '<img src="/site/lib/preloader.gif" />');
				var once=false;
	
				var im= new Asset.image(src,{'width':'100%','height':'',
					onload: function(){
						if(once){
							return;
						}else{
							once = true;
							this.swapSrc(im);
						
						}
					}.bind(this)
				})
		}	
		
		////////////////////////////////////////////////////////////////
		
		$$('.viewbut').each(function(but,n){
			
			//beeld + caption
			var imgs = but.getParent('div.file').getChildren('input');				 
			but.vimg = String(imgs[0].value);
			but.vtit = String(imgs[1].value);
			//titel en tekst
			var txts = but.getParent('div.file').getParent('div.files').getParent('div.main').getChildren('input');
			but.tit = String(txts[1].value);if(but.tit!=""){but.cttit='<div class="blk" id="tit">'+but.tit+'</div>';}else{but.cttit="";}
			but.txt = String(txts[2].value);if(but.txt!=""){but.cttxt='<div class="blk" id="txt">'+but.txt+'</div>';}else{but.cttxt="";}		
				
			but.slide_cont=slide_cont;
			
			but.addEvent('click',function(e){
				if(e) new Event(e).stop(); //dan wordt dit niet als href gebruikt
					//beeld plaatsen
					this.slide_cont.load_slide('/content/'+this.vimg);
					//this.setStyle('background', 'none');
					//this.setStyle('background', '#cccccc');
					//teksten plaatsen
					if(this.vtit!=""){
						//$('info').set('html', this.cttit+this.cttxt+'<div class="blk" id="cap">'+this.vtit+'</div>');
						g_info = this.cttit+this.cttxt+'<div class="blk" id="cap">'+this.vtit+'</div>';
					}else{
						//$('info').set('html', this.cttit+this.cttxt);
						g_info = this.cttit+this.cttxt;
					}
			})
		
		})
		
		$$('.main').each(function(but2,n){
			but2.slide_cont=slide_cont;
			but2.getElement('a').addEvent('click',function(e){
				if(e) new Event(e).stop();	 //dan wordt dit niet als href gebruikt
			
				// show/hide files 
				fls = but2.getElement('div.files');
				if(fls){
					if (fls.getChildren('div.file')[1]){
						f = fls.getStyle('display');
						//alert("f="+f);
						fls.setStyle('display',((f=='block')?'none':'block'));
					}
				}
				// show/hide child 
				cld = but2.getElement('div.child');
				if(cld){
					m = cld.getChildren('div.main').getStyle('display');
					//alert("m="+m);
					cld.getChildren('div.main').setStyle('display',((m[0]=='block')?'none':'block'));
				}
				
				//eerste beeld + eerste caption ophalen
				if(this.getParent('div.main').getElement('div.files')){
					ifolder = this.getParent('div.main').getElement('div.files');
					if(ifolder.getElement('div.file')){
						fimg = ifolder.getElement('div.file').getChildren('input');
						mimg = String(fimg[0].value);
						mcap = String(fimg[1].value);if(mcap!=""){ctcap='<div class="blk" id="cap">'+mcap+'</div>';}else{ctcap="";}
						//beeld plaatsen
						but2.slide_cont.load_slide('/content/'+mimg);
					}else{
						ctimg="";ctcap="";
					}
				}else{
					ctimg="";ctcap="";
				}
				
				// vimeo, titel en tekst ophalen
				mchilds = this.getParent('div.main').getChildren('input');
				mvm = String(mchilds[0].value);
				mtit = String(mchilds[1].value);if(mtit!=""){cttit='<div class="blk" id="tit">'+mtit+'</div>';}else{cttit="";}
				mtxt = String(mchilds[2].value);if(mtxt!=""){cttxt='<div class="blk" id="txt">'+mtxt+'</div>';}else{cttxt="";}
				if(mvm!=0){
					$('vm').setStyles({'display': 'block',
										  'position':'fixed',
										  'top':'0',
										  'left':'0',
										  'width':'100%',
										  'height':'100%',
										  'background':'url("/site/lib/back.png")',
										  'z-index':'4'});
					$('vm').set('html', vm(mvm)+'<div id="vmback">&nbsp;</div>');
					$('vimeo').addEvent('click',function(){
						//alert('vimeo');
					})	
					$('vmback').addEvent('click',function(){
						//alert('vmback');
						$('vm').setStyle('display', 'none');
					})	
				}
				
				// teksten plaatsen/vervangen	
				//$('info').set('html', cttit+cttxt+ctcap);
				g_info =  cttit+cttxt+ctcap;					
				//but2.slide_cont.load_slide('/content/'+mimg);
			})
			
		})	
	})
	
function vm(num){
	if(num!=0){
			return '<div id="vimeo"><object width="750" height="600"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='+num+'&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id='+num+'&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="750" height="600"></embed></object></div>';
	}else{
		return '';
	}
}
