window.addEvent('domready', function() {
	
	size = window.getSize();
	
	if($('homeimage')){
		$('homeimage').setStyle('opacity', 0);
		$('homeimage').set('morph', {
			duration: 1000
			//transition: Fx.Transitions.Bounce.easeOut,
		});
		$('homeimage').morph({opacity: 1});
	}

	var fnChain = new Chain();
	var sayings = $$('#nieuwsberichten ul li');	
	sayings.each(function(saying) {
		saying.setStyle('opacity', 0);
		saying.set('morph', {
			duration: 2000,
			transition: Fx.Transitions.linear.easeOut,
			onComplete: function(){fnChain.callChain()}
		});
	});				
	fnChain.chain(
			$$('#nieuwsberichten ul li').each(function (but, n) {
				but.setStyle('left', $random(100, 750));
				but.morph({opacity: 1, left: 0});
			})
	);		
	(function(){fnChain.callChain();}).delay(1000);	

	if($('show')){
		var fotosets = $('fotos').getElement('ul').getChildren('li');
		var fotosetID = fotosets[0].getProperty('id');
		changeSlideshow(fotosetID);
	}

	$$('.fotoset').each(function (but, n) {
        but.addEvent('click', function (e) {
            if (e) new Event(e).stop();
			var fotosetID = but.getProperty('id');
			changeSlideshow(fotosetID);
        })

    })

	$$('.sheet a').each(function(sh, t){
		sh.addEvents({
			'mouseover': function(){
				prodinfo = this.getParent('li').getElement('input').getProperty('value');
				$('productomschrijving').set('html',prodinfo);
			}
		});
	});

	$$('#nieuwsflitsen li a').each(function(nf, f){
		nf.addEvents({
			'click': function(clck){
	            if (clck) new Event(clck).stop();
			},		 
			'mouseover': function(){
				nwsinfo = this.getParent('li').getChildren('input').getProperty('value');
				nwstkst = String(nwsinfo[0]);
				nwsfoto = String(nwsinfo[1]);
				$('nieuwsbericht').set('html',nwstkst);
				$('nieuwsfoto').set('html','<img src="/site/img/'+nwsfoto+'" />');
			}
		});
	});

	$$('#team li a').each(function(tm, m){
		tm.addEvents({
			'click': function(tmclck){
	            if (tmclck) new Event(tmclck).stop();
			},		 
			'mouseover': function(){
				var teaminfo = this.getParent('li').getChildren('input').getProperty('value');
				var teamtkst = String(teaminfo[0]);
				var teamfoto = String(teaminfo[1]);
				$('bio').set('html',teamtkst);
				$('portret').set('html','<img src="/site/team/'+teamfoto+'" />');
			}
		});
	});

	$$('#menu li a img').each(function(img, n){
		img.addEvents({
			'mouseover': function(){
				src = this.getProperty('src');
				mo = this.getParent('a').getElement('input').getProperty('value');
				this.setProperty('src', '/site/files/menu/'+mo);
			},
			'mouseleave': function(){
				this.setProperty('src', src);
			}
		});
	});

	$$('#diensten li a img').each(function(dienst, d){
		dienst.addEvents({
			'mouseover': function(){
				src = this.getProperty('src');
				mo = this.getParent('a').getElement('input').getProperty('value');
				this.setProperty('src', '/site/files/dienstverlening_menu/'+mo);
			},
			'mouseleave': function(){
				this.setProperty('src', src);
			}
		});
	});

	$$('#referenties area').each(function(area, a){
		area.addEvents({
			'mouseover': function(){
				var alt = this.getProperty('alt');
				if($(alt)){
					var referentie = $(alt).getProperty('value');
					$('referentie').set('html',referentie);				}
			},
			'mouseleave': function(){
				$('referentie').set('html','');
			}
		});
	});

	$$('#tegel area').each(function(area, a){
		area.addEvents({
			'mouseover': function(){
				var alt = this.getProperty('alt');
				poponload(alt);
			}
		});
	});

	$$('#dienstlogos area').each(function(d_area, da){
		d_area.addEvents({
			'mouseover': function(){
				var alt = this.getProperty('alt');
				if($(alt)){
					var referentie = $(alt).getProperty('value');
					$('tekstdienstlogos').set('html',referentie);
				}
			},
			'mouseleave': function(){
				$('tekstdienstlogos').set('html','');
			}
		});
	});

	$$('.categorie a.getSubs').each(function(cat, c){
		cat.addEvents({
			'click': function(e){
				if (e) new Event(e).stop();
				lis = this.getParent('li').getChildren('ul.subs');
				f = lis[0].getStyle('display');
				this.getParent('li').setStyle('background-image',((f=='block')?'url("http://www.forteezza.nl/site/img/plus.png")':'url("http://www.forteezza.nl/site/img/min.png")'));
				lis.setStyle('display',((f=='block')?'none':'block'));
			}
		})
	});

	$$('.subcategorie a.getSubSubs').each(function(subcat, c){
		subcat.addEvents({
			'click': function(sube){
				if (sube) new Event(sube).stop(); 
				sublis = this.getParent('li.subcategorie').getElement('ul');
				subf = sublis.getStyle('display');
				
				this.getParent('li.subcategorie').setStyle('background-image',((subf=='block')?'url("http://www.forteezza.nl/site/img/plus.png")':'url("http://www.forteezza.nl/site/img/min.png")'));
				sublis.setStyle('display',((subf=='block')?'none':'block'));
			}
		})
	});


});

function changeSlideshow(fotosetID){
		if($('show'))$('show').dispose();
		var fotoset = $(fotosetID).getChildren('input');
		var photos=String(fotoset[0].getProperty('value')).split("*****");
		var captions=String(fotoset[1].getProperty('value')).split("*****");
		var foldername=fotoset[2].getProperty('value');
		var allphotos=photos.length-1;
		var showdata = {};
		showdiv=new Element('div',{'class':'slideshow', 'id':'show'});
		showimg = new Element('img',{'src':'/site/content/'+foldername+'/'+photos[0], 'alt':captions[0]});
		showimg.inject(showdiv);
		showdiv.inject($('fotos'),'bottom');
		for(var f=0;f<allphotos;f++){
			var x = photos[f];
			var y={'caption':captions[f]};
			showdata[x] = y;
		}
		var newShow = new Slideshow(
			'show',
			showdata, 
			/*{ captions: true, controller: true, height: 275, hu: '/site/content/'+foldername+'/', width: 350 }*/
			{ captions: true, controller: true, height: 275, resize: 'height', hu: '/site/content/'+foldername+'/', width: 350 }
		);
}

/*
	options: {
		center: true,
		overlap: true,
		height: false,
		resize: 'width',
		width: false
	},
*/

function poponload(src){
	testwindow= window.open (src, "mywindow","location=0,status=0,scrollbars=0,width=550,height=550");
	testwindow.moveTo((size.x/2-275),(size.y/2-275));
}
