references = new Class({
	Implements: [Options,Events,Chain,Swiff],
	
	options: {
		contentContainer: $('content'),
		referenceContainer: $('references')
	},
	
	initialize: function(options){
		// SETUP BASE OPTIONS
		this.setOptions(options);
		
		// SET DEFAULT VARIABLE VALUES
		this.refsInfo = null;
		this.currentRef = 0;
		this.maxRefs = 0;
		this.currentRefInfo = null;
		this.currentImage = 0;
		this.loadedImages = 0;
		this.firstStart = true;
		this.siteWidth = 1050;
		this.sliderLock = false;
		this.sliderOpen = false;
		this.productFilter = [];
		this.filteredRefs = [];
		this.oldSentPictures;
		this.squeezeBox = null;
		this.flashActivated = false;
		this.close = true;
		
		this.refShown = false;
		this.readMore = false;
		this.imageRotatorTimer = null;
		this.rotatorTime = 8000;
		this.originalBlockSize = new Hash({top: $('refcontent').getStyle('top'), height: $('refcontent').getStyle('height'), width: $('refcontent').getStyle('width')});
		
		// PRE-START THE MAGIC
		this.setupFlashSlider();
		this.createElements();
		this.setEffects();
		this.setSizes();
		
		//SETUP INTERACTION
		this.setEvents();
		
		this.loadRefs();
		
		var myCSS = new Asset.css('/css-js/SqueezeBox.css', {id: 'squeezeboxstyle', title: 'squeezeboxstyle'});
		var myScript = new Asset.javascript('/css-js/SqueezeBox.js', {
			id: 'squeezeboxscript'
		});
    },
    
    setupFlashSlider: function() {
		/*var flashvars = {
				  images: "http://verbeekrinzema.websdesign.nl/img/testcontent/ref1.jpg,http://verbeekrinzema.websdesign.nl/img/testcontent/ref2.jpg,http://verbeekrinzema.websdesign.nl/img/testcontent/ref3.jpg",
				  refid: 1
				};
		var params = {
		  wmode: "transparent",
		  allowscriptaccess : "always"
		};
		var attributes = {
		  id: "flashbgswf",
		  name: "flashbgswf"
		};
		swfobject.embedSWF("http://verbeekrinzema.websdesign.nl/swf/background.swf", "flashbg", "100%", "100%", "10.0.0",false, flashvars, params, attributes);*/
		/*this.backgroundSWF = new Swiff('/swf/background.swf', {
		    id: 'backgroundMovie',
		    width: '100%',
		    height: '100%',
		    params: {
		        wmode: 'opaque',
		        allowscriptaccess : 'always'
		    }
		});
		this.backgroundSWF.inject($('flashbg'), 'top');*/
        /*if (navigator.appName.indexOf("Microsoft") != -1) {
        	this.backgroundSWF = window['flashbgswf'];
        } else {
        	this.backgroundSWF = document['flashbgswf'];
        }*/
    },
    
    flashActive: function() {
    	this.flashActivated = true;
    },
    
    setSizes: function() {
    	windowDimensions = document.getSize();
    	
    	if(windowDimensions.x > 1050) {
    		this.siteWidth = (windowDimensions.x-30)+'px';
    	}
    	$('maincontainer').setStyle('width',this.siteWidth);
		$('flashbg').setStyle('width',this.siteWidth);
		if(this.showRef) $('references').setStyle('width',this.siteWidth);
		if($('sliderbar')) $('sliderbar').setStyle('width', (this.siteWidth.toInt()-40)+'px');
		if($('refslider')) $('refslider').setStyle('width', (this.siteWidth.toInt()-141)+'px');
    	$('flashbg').setStyle('height',(windowDimensions.y)+'px');
    },
    
    loadRefs: function() {
    	currentProduct = null;
    	currentPage = null
    	if($('currentpage') != null && $('currentpage').value != '') currentPage = $('currentpage').value;
    	if($('currentproduct') != null && $('currentproduct').value != '') currentProduct = $('currentproduct').value;
    	windowSize = window.getSize();
    	var jsonRequest = new Request.JSON({
    		url: '/include/json/references.json.php', 
    		onSuccess: this.setRefs.bind(this)
    	}).post({'cat': currentProduct, 'page': currentPage, 'width':windowSize.x,'height':windowSize.y});
    },
    
    setRefs: function(refs) {
    	this.refsInfo = new Hash(refs);
    	this.maxRefs = refs.length;
    	
    	refFilterContainer = new Element('div', {
    		'class': 'reffilter',
    		'id': 'reffilter'
    	});
    	refText = new Element('h3', {
    		'class': 'refcounttext',
    		'html': '<span class="currentrefnr">'+(this.currentRef+1)+'</span>/<span class="refcount">'+refs.length+'</span> referenties'
    	});
    	refText.inject(refFilterContainer,'bottom');
    	this.filterButton = new Element('a', {
    		'class': 'filterbutton',
    		'html': '+ filteren',
    		events: {
    			'click': this.openFilter.bind(this)
    		}
        });
    	this.filterButton.inject(refFilterContainer,'bottom');
    	refFilterContainer.inject(this.sliderElm,'top');
    	
    	filterTags = new Element('span', {
    		'id': 'filtertags',
    		'html': 'gefilterd op: '
    	});
    	filterTags.inject(refFilterContainer, 'bottom');
    	
    	prevRefButton = new Element('a', {
			'class': 'prevrefsmall',
			'html': 'vorige referentie',
			events: {
    			'click': this.slideRefsLeft.bind(this)
    		}
    	});
    	prevRefButton.inject(this.sliderElm,'bottom');
    	
    	leftShade = new Element('img', {
			'src': '/img/sprites/slidershadeleft.png',
			'class': 'slidershadeleft'
			
    	});
    	leftShade.inject(this.sliderElm,'bottom');
    	
    	refImagesContainer = new Element('div', {
			'class':'refslider',
    		'id':'refslider',
    		styles: {
    			'width' : (this.siteWidth.toInt()-141)+'px'
			}
        });
    	refImagesContainer.inject(this.sliderElm,'bottom');
    	refImages = new Element('ul');
    	refImages.inject(refImagesContainer,'top');
    	this.sliderScroll = new Fx.Scroll(refImagesContainer ,{offset: {'x':20,'y':0},wheelStops: false, duration: 'normal', transition: Fx.Transitions.Sine.easeInOut})
    	
    	liWidth = 0;
    	refNr = 0
    	$each(refs, function(refInfo){
    		productClassString = '';
    		$each(refInfo.producten, function(product) {
    			titleClass = product.title.replace(" ","-");
    			productClassString += titleClass+' ';
    			this.productFilter.include(product.title);
    		}.bind(this));
    		productClassString.trim();
    		refImage = new Element('li',{
    				styles: {
    					'background-color': '#000',
    					'background-image': 'url('+refInfo.refpic+')',
    					'background-repeat': 'no-repeat',
    					'background-position': 'center center'
    				},
    				'id': 'ref'+refInfo.refid,
    				'rel': refNr,
    				'class': productClassString,
    				'events': {
    					'click': this.setCurrentRef.bindWithEvent(this)
    				}
    		});
    		refImage.inject(refImages,'bottom');
    		liWidth += 128;
    		refNr++;
    	}.bind(this));
    	refImages.setStyle('width', liWidth+'px');
    	
    	leftShade = new Element('img', {
			'src': '/img/sprites/slidershaderight.png',
			'class': 'slidershaderight'
    	});
    	leftShade.inject(this.sliderElm,'bottom');
    	
    	filterBlock = new Element('div', {
			'class': 'filterblock',
			'id': 'filterblock'
    	});
    	
    	this.productFilter.each(function(filter) {
    		var id = filter.toLowerCase().replace(' ','')+'box';
    		var filterContainer = new Element('div',{
    			styles: {
    				'overflow':'hidden',
    				'float': 'left',
    				'clear': 'both'
    			}
    		})
    		var boxLabel = new Element('label',{'for':id, 'html': filter.capitalize()});
    		var checkBox = new Element('input', {
    			'id':id, 
    			'value': filter,
    			'type': 'checkbox', 
    			events: {
    				'change': this.changeFilter.bind(this)
    			}
    		});
    		boxLabel.inject(filterContainer, 'top');
    		checkBox.inject(filterContainer, 'top');
    		filterContainer.inject(filterBlock, 'top');
    	}.bind(this));
    	
    	filterSpan = new Element('span',{'html': 'Filter op:'});
    	filterSpan.inject(filterBlock,'top');
    	
    	filterBlock.inject(document.getElement('body'), 'bottom');
    	
    	nextRefButton = new Element('a', {
			'class': 'nextrefsmall',
			'html': 'volgende referentie',
			events: {
    			'click': this.slideRefsRight.bind(this)
    		}
		});
    	nextRefButton.inject(this.sliderElm,'bottom');
    	

    	this.setRef();
    },
    
    setRef: function() {
      clearInterval(this.imageRotatorTimer);
    	this.currentRefInfo = this.refsInfo[this.currentRef];
    	this.activateRef();
    },
    
    updateRefInfo: function() {
		links = [];
		$each(this.currentRefInfo.producten, function(product){
			links.include('<a href="'+product.link+'" title="'+product.title+'">'+product.title+'</a>');
		});
		links = links.join(', ');
    	if(this.readMore) {
			$('refcontainer').set('html','<h3>'+this.currentRefInfo.title+'</h3><a href="#" class="readless">x sluiten</a><div class="deliverablescontainer"><span class="deliverables">Wij leverden: </span>'+links+'</div><div class="desc">'+this.currentRefInfo.desc+'</div><div class="buttons"><a href="#offerte" class="narrowbutton contactform"><span class="extrabuttoninfo">Interesse in onze producten?</span>offerte aanvragen <img src="/img/sprites/spacer.gif" class="arrowicon" /></a></div> <a href="#" class="previmage">previous image</a><span class="picturecount">foto <span class="currentpicture">'+this.currentImage+'</span> van <span class="totalpictures">'+this.currentRefInfo.pictures.length+'</span></span><a href="#" class="nextimage">next image</a>');
			$$('a.readless').addEvent('click', this.closeReadMore.bind(this));
		} else if(this.refShown) {
			$('refcontainer').set('html','<div class="shortdesc">'+this.currentRefInfo.shortdesc+' <a href="#" class="readmore" title="Lees meer over deze referentie">+&nbsp;lees&nbsp;meer</a></div><h3>'+this.currentRefInfo.title+'</h3><div class="deliverablescontainer"><span class="deliverables">Wij leverden: </span>'+links+'</div><a href="#" class="previmage">previous image</a> <span class="picturecount">foto <span class="currentpicture">'+this.currentImage+'</span> van <span class="totalpictures">'+this.currentRefInfo.pictures.length+'</span></span> <a href="#" class="nextimage">next image</a>');
			$$('a.readmore').addEvent('click', this.openReadMore.bind(this));
		} else {
			links = [];
			i = 0;
			$each(this.currentRefInfo.producten, function(product){
				if(i < 2) links.include('<a href="'+product.link+'" title="'+product.title+'">'+product.title+'</a>');
				i++;
			});
			links = links.join(', ');
			$('refcontainer').set('html','<h3>'+this.currentRefInfo.title+'</h3><h5>'+links+'</h5><a href="" class="filterbutton showref" title="Bekijk de details van deze referentie">bekijk details</a>');
		}
	   	this.refFx.start('opacity',1);
	   	
	   	this.setEvents();
    },
    
    setRefPictures: function(pictures) {
    	if((this.oldSentPictures == null || this.oldSentPictures != this.currentRef)) {
    		$$('#flashbg div.bgimg').destroy();
    		$('ajaxloader').setStyle('display','inline');
    		this.oldSentPictures = this.currentRef;
	    	var picturesArray = [];
	    	$each(pictures, function(picture){
	    		picturesArray.include(picture);
	    	});
	    	
	    	this.loadedImages = 0;
	    	
	    	var myImages = new Asset.images(picturesArray, {
	    	    properties: {
	    	        'class': 'myImage',
	    	        title: 'myImage'
	    	    },
	    	    onProgress: function(counter, index) {
	    	    	
	    	    	imgElm =  new Element('div', {
	    	    		'id': 'bgimage'+(index+1),
	    	    		'class': 'bgimg',
	    	    		'styles': {
	    	    			'background-image':'url('+picturesArray[index]+')'
	    	    		}
	    	    	});
	    	    	imgElm.inject($('flashbg'),'bottom');
	    	    	this.loadedImages++;
	    	    	if(index == 0) {
	    	    		this.currentImage = 1;
		    	    	$('bgimage'+this.currentImage).setStyle('z-index',2);
		    	    	$('bgimage'+this.currentImage).setStyle('display','block');
		    	    	$('ajaxloader').setStyle('display','none');
	    	    	}
	    	    }.bind(this)
	    	});

        if(this.refShown) {
          this.imageRotatorTimer = this.nextImage.periodical(this.rotatorTime, this);
        }
	    	/*picturesString = picturesArray.join(',');
	    	$(this.backgroundSWF).setCurrentRef(this.currentRef);
	    	$(this.backgroundSWF).setImages(picturesString);*/
    	}
    },
    
    openReadMore: function(e) {
    	if(e != null) e.preventDefault();
    	this.refFx.start('opacity',0);
    	
    	currentBlockDimensions = $('refcontent').getCoordinates();
    	newTop = currentBlockDimensions.top-240;
    	
    	this.readMore = true;
    	
    	this.blockFx.start('top', newTop+'px').chain(
    			function() {this.blockFx.start('height', '280px')}.bind(this),
    			function() {this.updateRefInfo()}.bind(this)
    	);    	
    },
    
    closeReadMore: function(e) {
    	if(e != null) e.preventDefault();
    	this.refFx.start('opacity',0);
    	
    	this.readMore = false;
    	
    	this.blockFx.start('height', '110px').chain(
    			function() {this.blockFx.start('top', this.currentRefTop)}.bind(this),
    			function() {this.updateRefInfo()}.bind(this)
    	);    	
    },
    
    setCurrentRef: function(e) {
    	if(e != null) {
    		e.preventDefault();
    		e.stopPropagation();
    	}
    	if(e.target.get('rel')) {
	    	this.currentRef = e.target.get('rel').toInt();
	    	this.setRef();
    	}
    },
    
    activateRef: function() {
    	$$('#refslider ul li img').destroy();
    	
    	currentRefContainer = this.sliderElm.getElement('li[id=ref'+this.currentRefInfo.refid+']');
    	
    	currentImage = new Element('img',{'src':'/img/refoverlay.png'});
    	currentImage.inject(currentRefContainer,'top');
    	
    	sliderElm = this.sliderScroll.element.getDimensions();
    	
    	this.sliderScroll.start(currentRefContainer.getPosition().x-(sliderElm.x/2)).chain(
    			function(){this.refFx.start('opacity',0).chain(
    					this.updateRefInfo.bind(this)
    			)}.bind(this)
    	);
    	
    	var refNr = (this.currentRef+1);
    	if(this.filteredRefs.length > 0) refNr = (this.filteredRefs.indexOf(currentRefContainer.get('id')))+1;
    	$$('span.currentrefnr').set('html', refNr);
    	
    	this.setRefPictures(this.currentRefInfo.pictures);
    },
    
    slideRefsRight: function() {
    	sliderElm = this.sliderScroll.element.getDimensions();
    	sliderScrollSize = this.sliderScroll.element.getScroll();
    	this.sliderScroll.start(sliderScrollSize.x+sliderElm.x);
    },
    
    slideRefsLeft: function() {
    	sliderElm = this.sliderScroll.element.getDimensions();
    	sliderScrollSize = this.sliderScroll.element.getScroll();
    	this.sliderScroll.start(sliderScrollSize.x-sliderElm.x);
    },
	
	toggleContent: function(e) {
    	if(e != null) e.preventDefault();
    	
    	if(!this.refShown) {
    		this.showRef();
    	} else {
    		this.closeRef();
    	}
    },
    
    showRef: function() {
    	// GET CURRENT FLASH BACKGROUND SCREEN SIZE
    	flashSizes =  $('flashbg').getCoordinates();
    	this.refFx.start('opacity',0);
    	$('references').setStyle('width', flashSizes.width+8);
    	$('references').setStyle('height', (flashSizes.height+80));
    	this.currentScroll = window.getScroll().y;
    	
    	//SET NEW ELEMENT STYLES
    	topStart = $('references').getCoordinates().top;
    	contentTop = (flashSizes.height-(200+topStart));
    	refButtonsTop = (contentTop-67)/2;
  		this.nextRefLink.setStyle('top', refButtonsTop+'px');
  		this.prevRefLink.setStyle('top', refButtonsTop+'px');
  		this.currentRefTop = (flashSizes.height-(260+topStart))+'px';
      	
      	// START ANIMATION CHAIN
  		this.contentFx.start('opacity',0).chain(
  				function(){this.blockFx.start('top', this.currentRefTop).chain(
  						function(){this.blockFx.start('width', '625px');}.bind(this),
  						function(){this.start('height', '110px');},
  						function(){this.placeElements();}.bind(this)
  				);}.bind(this)
  		);
		
		// REFERENCES ARE SHOWN SO TELL THE SCRIPT
    },
    
    placeElements: function() {
    	this.prevRefLink.inject('references','top');
    	this.nextRefLink.inject('references','top');
    	if(this.close) this.closeLink.inject('references','top');
    	this.quoteBlock.set('html', '<h3>Advies voor uw inrichting</h3><p>Wij helpen u graag bij het maken van de juiste keuzes!</p><a href="" class="filterbutton contactform advies">AFSPRAAK MAKEN&nbsp;<img class="arrowicon" src="/img/sprites/spacer.gif"></a>');
    	this.quoteBlock.setStyle('top', this.currentRefTop);
    	this.quoteBlock.inject('references','top');
    	if(!$('sliderbar')) this.sliderElm.inject('references','bottom');
    	else this.sliderElm.setStyle('display','block');
    	
    	$('footer').setStyle('display','none');
    	
    	
		this.refShown = true;
		
		clearInterval(this.imageRotatorTimer);
		this.imageRotatorTimer = this.nextImage.periodical(this.rotatorTime, this);
		//this.updateRefInfo();
    	
    	this.startReferenceControl();
    },
    
    startReferenceControl: function(){
    	this.myFx.toElement(this.closeLink).chain(
    			function(){this.showSliderbar}.bind(this),
    			function(){this.hideSliderbar}.bind(this)
    	);
    	
    	$$('a.contactform').removeEvent('click');
    	$$('a.contactform').addEvent('click', this.openContact);
    	
    	this.activateRef();
    },
    
    closeRef: function() {
      clearInterval(this.imageRotatorTimer);
    	this.refFx.start('opacity',0);
  		this.closeLink.destroy();
  		this.quoteBlock.destroy();
  		this.prevRefLink.destroy();
  		this.nextRefLink.destroy();
  		this.sliderElm.setStyle('display','none');
  		$('footer').setStyle('display','block');
  		this.blockFx.start('height', this.originalBlockSize.height).chain(
  				function(){this.blockFx.start('width', this.originalBlockSize.width)}.bind(this),
  				function(){this.blockFx.start('top', this.originalBlockSize.top)}.bind(this),
  				function(){this.closeEnd();}.bind(this)
  		);
    },
    
    closeEnd: function() {
    	this.contentFx.start('opacity',1).chain(
    			function(){this.myFx.start(0,this.currentScroll);}.bind(this)
    	);
    	
    	this.readMore = false;
		this.refShown = false;
		this.updateRefInfo();
		
    	$$('a.contactform').removeEvent('click');
    	$$('a.contactform').addEvent('click', this.openContact);
    	
    	$('references').setStyles({width: '0px', height: '0px'});
    	return true
    },
    
    nextRef: function() {
    	this.currentRef++;
    	if(this.currentRef >= this.maxRefs) this.currentRef = 0;
    	if($('refslider').getElement('li[rel='+this.currentRef+']').getStyle('display') == 'none') {
    		this.nextRef();
    		return false;
    	}
    	this.setRef();
    },
    
    prevRef: function() {
    	this.currentRef--;
    	if(this.currentRef < 0) this.currentRef = this.maxRefs-1;
    	if($('refslider').getElement('li[rel='+this.currentRef+']').getStyle('display') == 'none') {
    		this.prevRef();
    		return false;
    	}
    	this.setRef();
    },
    
    setEffects: function() {
		this.contentFx = new Fx.Tween($('content'),{
			duration: 'short', 
			transistion: Fx.Transitions.linear.easeIn
		});
		this.blockFx = new Fx.Tween($('refcontent'),{
			duration: 300, 
			transistion: Fx.Transitions.linear.easeInOut
		});
		this.refFx = new Fx.Tween($('refcontainer'),{
			duration: 'short', 
			transistion: Fx.Transitions.linear.easeInOut
		});
		this.myFx = new Fx.Scroll(window, {
		    duration: 300,
		    offset: {'x':0,'y':-20}
		});

    },
    
    createElements: function() {
    	windowDimensions = window.getSize();
    	// CREATE CLOSE BUTTON
			this.closeLink = new Element('a', {
				'class': 'refclose',
				'events': {
					'click': this.toggleContent.bind(this)
				}
			});
		
		this.quoteBlock = new Element('div', {
			'id': 'quoteblock',
			'html': '<h3>Advies voor uw inrichting</h3><p>Wij helpen u graag bij het maken van de juiste keuzes!</p><a href="" class="filterbutton contactform">AFSPRAAK MAKEN&nbsp;<img class="arrowicon" src="/img/sprites/spacer.gif"></a>'
		});
		
    	// CREATE NEXT REFERENCE BUTTON
		this.nextRefLink = new Element('a', {
			'class': 'nextref',
			'events': {
				'click': this.nextRef.bind(this)
			}
		});
		
    	// CREATE PREV REFERENCE BUTTON
		this.prevRefLink = new Element('a', {
			'class': 'prevref',
			'events': {
				'click': this.prevRef.bind(this)
			}
		});
		
    	// CREATE SLIDER ELEMENT
		this.sliderElm = new Element('div', {
			'id': 'sliderbar',
			styles: {
				'width': (windowDimensions.x.toInt()-70)+'px',
				'bottom': '90px'
				/*'opacity': 0.6,
				'height': '50px',
				'overflow': 'hidden',
				'bottom': '110px'*/
			}/*,
			events: {
				'mouseenter': function(){
					if(this.sliderTimeOut != null) $clear(this.sliderTimeOut);
					this.sliderTimeOut = this.showSliderbar.delay(200, this);
				}.bind(this),
				'mouseleave': function(){
					if(this.sliderTimeOut != null) $clear(this.sliderTimeOut);
					this.hideSliderbar();
				}.bind(this)
			}*/
		});
		
		this.sliderFx = new Fx.Morph(this.sliderElm, {duration: 'short', transition: Fx.Transitions.Sine.easeInOut});
    },
    
    showSliderbar: function(e) {
    	/*if(!this.sliderLock && !this.sliderOpen) {
	    	this.sliderFx.start({
			   'height': (this.sliderElm.scrollHeight.toInt()+30)+'px',
			   'opacity': 1,
			   'bottom': '0px'
			}).chain(function(){this.sliderOpen = true;}.bind(this));
    	}*/
    	
    },
    
    hideSliderbar: function(e) {
    	/*if(!this.sliderLock && this.sliderOpen) {
	    	this.sliderFx.start({
				   'height': '50px',
				   'opacity': 0.6,
				   'bottom': '110px'
			}).chain(function(){this.sliderOpen = false;}.bind(this));
	    	
    	}*/
    },
    
    imageRotator: function() {
      
    },
    
    nextImage: function(e) {
    	if(e != null) e.preventDefault();
    	clearInterval(this.imageRotatorTimer);
    	$$('div.bgimg').setStyle('display','none');
    	this.currentImage++;
    	if(this.currentImage > this.loadedImages) this.currentImage = 1;
    	$('bgimage'+this.currentImage).setStyle('z-index',2);
    	$('bgimage'+this.currentImage).setStyle('display','block');
    	/*var imageNr = this.backgroundSWF.remote('nextImage');*/
    	this.setImageNr();
      this.imageRotatorTimer = this.nextImage.periodical(this.rotatorTime, this);
    },
    
    prevImage: function(e) {
    	if(e != null) e.preventDefault();
    	clearInterval(this.imageRotatorTimer);
    	$$('div.bgimg').setStyle('display','none');
    	this.currentImage--;
    	if(this.currentImage < 1) this.currentImage = this.loadedImages;
    	$('bgimage'+this.currentImage).setStyle('z-index',2);
    	$('bgimage'+this.currentImage).setStyle('display','block');
    	/*var imageNr = this.backgroundSWF.remote('prevImage');*/
    	this.setImageNr();
    	this.imageRotatorTimer = this.nextImage.periodical(this.rotatorTime, this);
    },
    
    /*setImageNr: function(imageNr) {
    	this.currentImage = imageNr;
    	$$('.currentpicture').set('html',(imageNr+1));
    },*/
    
    setImageNr: function() {
    	$$('.currentpicture').set('html',this.currentImage);
	  },
    
    setEvents: function() {
    	$$('.showref').removeEvents('click');
    	$$('.nextimage').removeEvents('click');
    	$$('.previmage').removeEvents('click');
    	window.removeEvents('resize');
    	$$('a.contactform').removeEvent('click');
    	
  		$$('.showref').addEvent('click', this.toggleContent.bind(this));
  		window.addEvent('resize', this.setSizes);
  		$$('a.contactform').addEvent('click', this.openContact);
  		$$('.nextimage').addEvent('click', this.nextImage.bind(this));
  		$$('.previmage').addEvent('click', this.prevImage.bind(this));
    },
    
    pageResize: function() {
    	
    },
    
    openFilter: function(e) {
    	this.sliderLock = true;
    	buttonPos = e.target.getPosition();
    	$('filterblock').setStyles({'top': (buttonPos.y-52)+'px','left': buttonPos.x+'px','display':'block'});
    	blockSize = $('filterblock').getScrollSize();
    	$('filterblock').setStyles({'top': (buttonPos.y-(16+blockSize.y))+'px','height':(blockSize.y-16)+'px'});
    	this.filterButton.set('html', '+ filter toepassen');
    	this.filterButton.removeEvents('click');
    	this.filterButton.addEvent('click', this.closeFilter.bind(this));
    },
    
    closeFilter: function(e) {
    	this.sliderLock = false;
    	this.setFilter();
    	buttonPos = e.target.getPosition();
    	$('filterblock').setStyle('display','none');
    	this.filterButton.set('html', '+ filteren');
    	this.filterButton.removeEvents('click');
    	this.filterButton.addEvent('click', this.openFilter.bind(this));
    },
    
    setFilter: function() {
    	var setFilters = [];
    	$$('#filterblock input[type=checkbox]').each(function(input) {
    		inputFilter = input.value.toLowerCase().replace(" ","-");
    		if(input.checked) setFilters.include(inputFilter);
    	});
    	if(setFilters.length == 0) {
    		$$('#refslider ul li').setStyle('display','block');
    		refsNr = this.maxRefs;
    		this.filteredRefs = [];
    	} else {
    		this.filteredRefs = [];
	    	$$('#refslider ul li').each(function(item){
	    		classes = item.className.split(' ');
	    		show = false;
	    		classes.each(function(itemName){
	    			if(setFilters.contains(itemName)) {
	    				show = true;
	    			}
	    		});
	    		if(show) {
	    			item.setStyle('display','block');
	    			item.addClass('dodisplay');
	    			this.filteredRefs.include(item.get('id'));
	    		} else {
	    			item.setStyle('display','none');
	    			item.addClass('nondisplay');
	    		}
	    	}.bind(this));
	    	refsNr = this.filteredRefs.length;
    	}
    	$$('span.refcount').set('html', refsNr);
    	firstRef = $('refslider').getElement('ul').getFirst('li.dodisplay');
    	this.currentRef = firstRef.get('rel').toInt();
    	this.setRef();
    },
    
    changeFilter: function(e) {
    	if(e != null) e.preventDefault();
    	filterValue = e.target.value;
    	filterId = e.target.id;
    	if(e.target.checked) {
    		filterLink = new Element('a', {
    			href: '#',
    			'class': 'activefilter',
    			id: 'filter'+filterId,
    			html: '<span class="tagcross">x</span> '+filterValue.capitalize(),
    			events: {
    				'click': this.deleteFilter.bind(this)
    			}
    		});
    		filterLink.inject($('filtertags'), 'bottom');
    		if($('filtertags').getStyle('display') == 'none') $('filtertags').setStyle('display','inline');
    	} else {
    		$('filter'+filterId).destroy();
    		var elms = $('filtertags').getElements('a');
    		if(elms.length == 0) $('filtertags').setStyle('display','none');
    	}
    	
    },
    
    deleteFilter: function(e) {
    	if(e != null) e.preventDefault();
    	filterId = $(e.target).id;
    	$(e.target).destroy();
    	filterId = filterId.replace('filter','');
    	$(''+filterId).checked = false;
    	this.setFilter();
		var elms = $('filtertags').getElements('a');
		if(elms.length == 0) $('filtertags').setStyle('display','none');
    },
    
    openContact: function(e) {
    	if(e != null) e.preventDefault();
    	type='offerte';
    	if(this.hasClass('directcontact')) {
    		type='directcontact';
    	} else if(this.hasClass('service')) {
    		type='service';
    	} else if(this.hasClass('advies')) {
    		type='advies';
    	}
    	SqueezeBox.open('/include/templates/includes/contact.php?type='+type,{
    		size: {x: 570, y: 500},
    		handler:'ajax'
    	});
    }
});
