function fixpng(){
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if ((version >= 5.5) && (document.body.filters) && (version < 7)){
		var png_images = $$('.pngfix');	
		png_images.each(function(element) {
			if(!$(element).hasClass('pngfixed')){
				$(element).addClass('pngfixed');
				var img = $(element);
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.getProperty('width') + "px; height:" + img.getProperty('height') + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML					
			}
		});
	} else {
		$$('.pngfix').addClass('pngfixed');
	}
}

function make_scrollarea(content, scrollbar, handle){
	var steps = (content.getScrollSize().y - content.getSize().y);
	if(steps > 0){
		$$(scrollbar, handle).removeEvents();
		var slider = new Slider(scrollbar, handle, {	
			steps: steps,
			mode: 'vertical',
			onChange: function(step){
				content.scrollTo(0,step);
			}
		}).set(0);
		$$(content, scrollbar).removeEvents('mousewheel');
		$$(content, scrollbar).addEvent('mousewheel', function(e){	
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;	
			slider.set(step);					
		});
		scrollbar.setStyle('visibility', 'visible');
		handle.setStyle('visibility', 'visible');
	} else {
		scrollbar.setStyle('visibility', 'hidden');
		handle.setStyle('visibility', 'hidden');
	}
}

function init(){
	
	//	menu behaviour
	$$('#menu ul.main li a').addEvent('click', function(e){
		if(sub = this.getParent('li').getFirst('ul')){
			//	stop current click event
			if (e) new Event(e).stop();
			//	close current
			$$('#menu ul.main li.open ul').each(function(el,i){
				if(el.fx) el.fx.cancel();
				el.fx = new Fx.Tween(el, {duration: 500}).start('height', el.getSize().y, 0);
			});
			//	open menu
			sub.setStyles({'height': '0px', 'display': 'block'});
			if(sub.fx) sub.fx.cancel();
			sub.fx = new Fx.Tween(sub, {duration: 500, onComplete: function(){ sub.getParent('li').addClass('open'); fix(); }}).start('height', sub.getSize().y, sub.getScrollSize().y);
		}	
	});
	
	//	remove focus dots
	$$('#menu a, a img').addEvent('focus', function(){ this.blur(); });
	
	//	intake ol's
	$$('#container.intake .content ol li, #container.voorwaarden .content ol li').each(function(el,i){
		var span = new Element('span', {'class': 'text', 'html': el.get('html')});
		el.set('html', '');
		span.inject(el);
		el.setStyle('visibility', 'visible');	
	});

	//	show caviar
	$$('.caviar').setStyle('visibility', 'visible');
	
  	//  input styles
  	$$('input.default').addEvent('focus', function(){ this.removeClass('default'); });
  
	//	fixes
	fix();
	fixpng();

	//	scrollbar
	if($$('#container.scrollable').length){
		$('scrollbar').setStyle('height', Math.max(0, $('container').getSize().y-64)+'px');
		make_scrollarea($('container'), $('scrollbar'), $('scrollhandle'));	
	}
	
}

function fix(){
	//	fix site
	if($('body').getSize().x < $('site').getSize().x){ $('site').setStyles({'marginLeft': '0px', 'left': '0px'}); } else { $('site').setStyles({'marginLeft': (-1 * Math.round($('site').getSize().x/2)) + 'px', 'left': '50%'}); }
	if($('body').getSize().y < $('site').getSize().y){ $('site').setStyles({'marginTop': '0px', 'top': '0px'}); } else { $('site').setStyles({'marginTop': (-1 * Math.round($('site').getSize().y/2)) + 'px', 'top': '50%'}); }
	
	//	fix menu
	if($$('#extra').length){
		
		var height = Math.max($('menu').getSize().y + $('extra').getSize().y + 70 , $('content').getSize().y );
		$('content').setStyle('height', height+'px');
	} 
	
}

window.addEvent('load', init);
window.addEvent('resize', fix);
