/////////////////////////////////////////////////////////////////////////////////////////
window.addEvent('load', function () {
/////////////////////////////////////////////////////////////////////////////////////////
								  									 
	///////////////////////////algemeen///////////////////////////
	if($('overlay_container') && $('overlay_container').getStyle('display')=='block'){
		$('back').setStyle('display','block');
		$('cnt').setStyle('position','fixed');
	}

	size = window.getSize();
	contentdiv = $('cnt').getSize();
	contentdivwidth = size.x;

	$('cnt').setStyle('width', contentdivwidth);
	
	$$('.card').each(function (x) {
		x.addEvents({
			'mouseenter': function(){
				var xtop = this.getStyle('margin-top').toInt();
				var xleft = this.getStyle('margin-left').toInt();
				this.setStyle('margin-top', (xtop+2));
				this.setStyle('margin-left', (xleft+2));
			},
			'mouseleave': function(){
				var xtop = this.getStyle('margin-top').toInt();
				var xleft = this.getStyle('margin-left').toInt();
				this.setStyle('margin-top', (xtop-2));
				this.setStyle('margin-left', (xleft-2));
			}
		});
	});

	if($('type_overview')){
		projects = 0;
		ProjectHeight = $('type_overview').getElement('ul').getElement('li').getSize().y;
		addHeight = (ProjectHeight+24);
		oc_height=$('overlay_content').getStyle('height').toInt();
		heightNumber=1;
		$('overlay_content').setStyle('height',oc_height+'px');
		$$('.project').each(function(p){
			pheight = p.getSize().y;
			if(pheight>ProjectHeight){
				ProjectHeight=pheight;
				addHeight = (ProjectHeight+24);
			}
			if(projects==4){
				heightNumber++;
				projects=0;
			}
			projects++;
		});
		$$('.project').setStyle('height', addHeight);
		newOCheight = (heightNumber*addHeight)+125;
		$('overlay_content').setStyle('height',newOCheight+'px');
	}
	
	///////////////////////////prive///////////////////////////
	if($('prive')){
		var fotos=String($('fotofolder').getProperty('value')).split("*****");
		var fotolinks=String($('fotolinks').getProperty('value')).split("*****");
		var allfotos = fotos.length-2;
		//var f=(-1);
		var z=100;
		for(var f = 0; f < allfotos; f++){
			fotosrc='/privefotos/'+fotos[f];
			fotolinksrc='/privefotos/'+fotolinks[f];
			foto= new Element('img',{'src':fotosrc});
			foto.setStyles({
				'position':'absolute',		   
				'width': $random(100, 400),	
				'height' : 'auto',
				'left': $random(10, size.x-410),
				'top': $random(10, size.y-300),
				'z-index':2
			});
			fotolink = new Element('a',{
				//'title':'dubbelklik voor grotere foto', 
				'href':'javascript:showfoto(\'' + fotolinksrc + '\')'
				//'onDblClick':'javascript:showfoto(\'' + fotolinksrc + '\')'
			});
			var myDrag = new Drag(foto).attach();
			foto.addEvent('mouseenter', function(){
				this.setStyle('z-index',z++);
			});
			foto.inject(fotolink);		
			fotolink.inject($('prive'),'top');
		}
		/*
		var addCount = function(){ 
			if((f++) < allfotos){
				fotosrc='/privefotos/'+fotos[f];
				fotolinksrc='/privefotos/'+fotolinks[f];
				foto= new Element('img',{'src':fotosrc});
				foto.setStyles({
					'position':'absolute',		   
					'width': $random(100, 400),		   
					'left': $random(10, size.x-410),
					'top': $random(10, size.y-300),
					'z-index':2
				});
				fotolink = new Element('a',{
					'title':'dubbelklik voor grotere foto', 
					'href':'javascript:void(0)', 
					'ondblclick':'javascript:showfoto(\'' + fotolinksrc + '\')'
				});
				var myDrag = new Drag(foto).attach();
				foto.addEvent('mouseenter', function(){
					this.setStyle('z-index',z++);
				});
				foto.inject(fotolink);		
				fotolink.inject($('prive'),'top');
			}
		};
		
		addCount.periodical(0.1);
		*/
		$('cnt').setStyle('position','fixed');
		//$('serafijn').setStyle('position','fixed');
		closeprive=new Element('div',{'id':'closeprive'});
		closeprive.inject($('prive'),'bottom');
		$('closeprive').addEvent('click', function(c){
				//if(c) new Event(c).stop();
				$('prive').setStyle('display','none');
				$('cnt').setStyle('position','absolute');
				//$('serafijn').setStyle('position','absolute');
		});
		
	}

	///////////////////////////beschrijving///////////////////////////
	if($('beschrijving'))$('beschrijving').setStyle('height', (size.y-205));	

	if($('meta')){
		o_height = $('meta').getStyle('height');
		$('info').setStyle('min-height',o_height);
	}

	if($('blog'))$('blog').addEvents({
		'mouseenter': function(){
			blogheader = this.getElement('h2');
			blogheader.setStyle('background','url("/img/sq2.jpg") no-repeat 0 2px');
		},
		'mouseleave': function(){
			blogheader = this.getElement('h2');
			blogheader.setStyle('background','url("/img/sq3.jpg") no-repeat 0 2px');
		}
	});

	$$('.proj_list').each(function(p){
		p.addEvents({
			'mouseenter': function(){
				headertext = this.getElement('h2');
				projectul = this.getElement('ul');
				headertext.setStyle('background','url("/img/sq2.jpg") no-repeat 0 2px');
				projectul.fade('in');
			},
			'mouseleave': function(){
				headertext.setStyle('background','url("/img/sq3.jpg") no-repeat 0 2px');
				projectul.fade('out');
			}
		});
	});
		
	$$('.small').each(function(s){
		fs=s.getStyle('font-size').toInt();
		lh=s.getStyle('line-height').toInt();
		s.setStyle('font-size', fs-2);
		s.setStyle('line-height', lh-2);
	});
	$$('.medium').each(function(s){
		fs=s.getStyle('font-size').toInt();
		lh=s.getStyle('line-height').toInt();
		s.setStyle('font-size', fs+6);
		s.setStyle('line-height', lh+6);
	});
	$$('.large').each(function(s){
		fs=s.getStyle('font-size').toInt();
		lh=s.getStyle('line-height').toInt();
		s.setStyle('font-size', fs+8);
		s.setStyle('line-height', lh+8);
	});
	
	if($('close_beschrijving')){
		$('close_beschrijving').getElement('a').addEvent('click', function(e){
				if(e) new Event(e).stop();
				$('beschrijving_container').setStyle('display','none');
		});
	}	
	if($('back'))backdisplay=$('back').getStyle('display');
	if(backdisplay=='block'){
		$('back').addEvent('click', function(){
				$('back').setStyle('display','none');
				$('overlay_container').setStyle('display','none');
				if($('beschrijving_container'))$('beschrijving_container').setStyle('display','none');
				$('cnt').setStyle('position','absolute');
		});
	}
	if($('close')){
		$('close').getElement('a').addEvent('click', function(cl){
				if(cl) new Event(cl).stop();
				$('back').setStyle('display','none');
				$('overlay_container').setStyle('display','none');
				if($('beschrijving_container'))$('beschrijving_container').setStyle('display','none');
				$('cnt').setStyle('position','absolute');
		});
	}
	
	if($('imgcount')){
		var imgcount=$('imgcount').getProperty('value');		
		max_width=845-(imgcount*20);
		highest_image=0;
		cnt_max_height=0;
		$$('.topimgdiv').each(function(img){
			img.setStyle('max-width',max_width);
		});
		$$('.image').each(function(img){
			img.setStyle('max-width', max_width);
			imgheightpx=img.getStyle('height');
			imgheight=imgheightpx.toInt();
			if(imgheight > highest_image){
				highest_image=imgheight;
			}
			cnt_max_height+=20;
		});
		$$('.img_cnt').each(function(imgc){
			imgc.setStyle('width',max_width);
			imgc.setStyle('height',450);
		});
		$$('.topimgdiv').each(function(timg){
			timg.setStyle('width',max_width);
			timg.setStyle('height',450);
		});
		$$('.topimgdiv_cnt').each(function(img){
			img.setStyle('width',max_width);
			img.setStyle('height',450);
		});
		cnt_max_height+=highest_image;
		
		$('img_container').setStyle('height',cnt_max_height);
	}

	if($('img_desc')){
		texts=String($('img_desc').getProperty('value')).split("*****");
	}
	
	if($('boektekst')){
		pagina_hoogte=475;
		paginas = [];
		paragraven_hoogte=0;
		pagina_nr=0;
		teller=0;
		paginas[pagina_nr]=new Element('div',{'class':'boekpagina'});	
		$$('.paragraaf').each(function(p,n){
			paragraaf = p.getSize();
			p_height = paragraaf.y+20;
			if((paragraven_hoogte+p_height) < pagina_hoogte){
				p.inject(paginas[pagina_nr],'bottom');
				paragraven_hoogte+=p_height;
				teller+=1;
			}else{
				paragraven_hoogte=0;
				teller=0;
				pagina_nr+=1;
				paginas[pagina_nr]=new Element('div',{'class':'boekpagina'});
				p.inject(paginas[pagina_nr],'bottom');
				paragraven_hoogte+=p_height;
				teller+=1;
			}
		});
		total_pages=paginas.length;
		
		for(var pg = 0; pg < total_pages; pg++){
			titel = String($('booktit').getProperty('value'));
			booktitle= new Element('h4',{'html':titel, 'class':'booktit'});
			booktitle.inject(paginas[pg],'top');
			bookpagenr = new Element('h4',{'html':(pg+1), 'class':'bookpagenr'});
			bookpagenr.inject(paginas[pg],'bottom');			
			paginas[pg].inject($('boektekst'), 'bottom');			
		}
		
	}	

	if($('booktext')){
		page_height=475;
		pages = [];
		paragraphs_height=0;
		page_nr=0;
		counter=0;
		pages[page_nr]=new Element('div',{'class':'bookpage'});	
		$$('.paragraph').each(function(p,n){
			paragraph = p.getSize();
			p_height = paragraph.y+20;
			if((paragraphs_height+p_height) < page_height){
				p.inject(pages[page_nr],'bottom');
				paragraphs_height+=p_height;
				counter+=1;
			}else{
				paragraphs_height=0;
				counter=0;
				page_nr+=1;
				pages[page_nr]=new Element('div',{'class':'bookpage'});
				p.inject(pages[page_nr],'bottom');
				paragraphs_height+=p_height;
				counter+=1;
			}
		});
		total_pages=pages.length;
		
		for(var pg = 0; pg < total_pages; pg++){
			titel = String($('booktit').getProperty('value'));
			booktitle= new Element('h4',{'html':titel, 'class':'booktit'});
			booktitle.inject(pages[pg],'top');
			bookpagenr = new Element('h4',{'html':(pg+1), 'class':'bookpagenr'});
			bookpagenr.inject(pages[pg],'bottom');			
			pages[pg].inject($('booktext'), 'bottom');			
		}
		
	}	

	$$('.zoom').each(function (but, n) {

        but.addEvent('click', function (e) {
            if (e) new Event(e).stop(); //dan wordt dit niet als href gebruikt
            href = but.getProperty('href');
            $('lightbox').setStyles({
                'display': 'block',
                'position': 'fixed',
                'top': '0',
                'left': '0',
                'text-align': 'center',
                'width': size.x,
                'height': size.y,
                'z-index': '4'
            });
			$('lightbox').setStyle('display', 'block');
			$('lightbox').set('html', '<table align="center" height="100%"><tr><td height="100%" valign="middle"><a href="javascript:si2(\'' + href + '\')"><img id="lb_img" src="' + href + '"></a></td></tr></table><div id=\"lb\">&nbsp;</div>');
			image = $('lightbox').getElement('img');
			image.setStyles({
				'max-height': size.y,
				'position': 'relative',
				'z-index': '5',
				'opacity':'0.97',
				'filter':'alpha(opacity=97)'
			});//einde setStyles 
			$('lb').addEvent('click', function () {
                $('lightbox').setStyle('display', 'none');
            })
        })

    })

	if($('eng')){
		$('infoeng').addEvents({
			'mouseenter': function(){this.setProperty('src','/img/en_bl.png');},
			'mouseleave': function(){this.setProperty('src','/img/en_zw.png');}
		});
		$('eng').addEvent('click', function(eng){
			if(eng) new Event(eng).stop();
			$('boektekst').setStyle('display','none');
			$('booktext').setStyle('display','block');
			$('eng').setStyle('display','none');
			$('ned').setStyle('display','block');
		});
	}
	if($('ned')){
		$('infoned').addEvents({
			'mouseenter': function(){this.setProperty('src','/img/ne_bl.png');},
			'mouseleave': function(){this.setProperty('src','/img/ne.png');}
		});
		$('ned').addEvent('click', function(ned){
			if(ned) new Event(ned).stop();
			$('booktext').setStyle('display','none');
			$('boektekst').setStyle('display','block');
			$('ned').setStyle('display','none');
			$('eng').setStyle('display','block');
		});
	}

	if($('language')){
		if($('taaleng'))$('taaleng').addEvents({
			'mouseenter': function(){this.setProperty('src','/img/en_bl.png');},
			'mouseleave': function(){this.setProperty('src','/img/en_zw.png');}
		});
		if($('blogeng'))$('blogeng').addEvents({
			'mouseenter': function(){this.setProperty('src','/img/en_bl.png');},
			'mouseleave': function(){this.setProperty('src','/img/en.png');}
		});
		$('language').addEvent('click', function(eng){
			if(eng) new Event(eng).stop();
			$('nedtekst').setStyle('display','none');
			$('engtext').setStyle('display','block');
			$('language').setStyle('display','none');
			$('taal').setStyle('display','block');
		});
	}
	if($('taal')){
		if($('taalned'))$('taalned').addEvents({
			'mouseenter': function(){this.setProperty('src','/img/ne_bl.png');},
			'mouseleave': function(){this.setProperty('src','/img/ne.png');}
		});
		if($('blogned'))$('blogned').addEvents({
			'mouseenter': function(){this.setProperty('src','/img/ne_bl.png');},
			'mouseleave': function(){this.setProperty('src','/img/ne_wit.png');}
		});
		$('taal').addEvent('click', function(ned){
			if(ned) new Event(ned).stop();
			$('engtext').setStyle('display','none');
			$('nedtekst').setStyle('display','block');
			$('taal').setStyle('display','none');
			$('language').setStyle('display','block');
		});
	}

	if($('infoknop')){
		$('infopng').addEvents({
			'mouseenter': function(){this.setProperty('src','/img/info_blauw.png');},
			'mouseleave': function(){this.setProperty('src','/img/info_wit.png');}
		});
		if($('beeldshr'))shr = $('beeldshr').getProperty('value');
		if($('shrtitle'))shrtit = $('shrtitle').getProperty('value');
		if($('infoknop')){
			$('infoknop').addEvent('click', function(knop){
				if(knop) new Event(knop).stop();
				$('shr_txt').set('html',shr);
				$('shr_tit').set('html', 'beschrijving bij: '+shrtit);
				$('beschrijving_container').setStyle('display','block');
			});
		}
		if($('klikhier')){
			$('klikhier').addEvent('click', function(klik){
				if(klik) new Event(klik).stop();
				$('shr_txt').set('html',shr);
				$('shr_tit').set('html', 'beschrijving bij: '+shrtit);
				$('beschrijving_container').setStyle('display','block');
			});
		}
	}

	if($('clickhere')){
		if($('english'))eng = $('english').getProperty('value');
		if($('shrtitle'))shrtit = $('shrtitle').getProperty('value');
		if($('clickhere')){
			$('clickhere').addEvent('click', function(clic){
				if(clic) new Event(clic).stop();
				$('shr_txt').set('html',eng);
				$('shr_tit').set('html', 'description for: '+shrtit);
				$('beschrijving_container').setStyle('display','block');
			});
		}
	}


/////////////////////////////////////////////////////////////////////////////////////////
});
/////////////////////////////////////////////////////////////////////////////////////////
