Shadowbox.init({
	skipSetup: false,
	adapter: 'base',
	language: 'nl',
	overlayColor: '#000000',
	overlayOpacity: '0.75',
	handleOversize: 'resize',
	players: ["img", "swf", "html", "iframe", "flv", "qt", "wmp"]
});

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');
	}
}

/* AJAX */
	
function init_ajaxlinks(){
	//	(aja)x a links
	var xs = $$('.xlink');
	for(i=0;i<xs.length;i++){
		xs[i].removeEvents('click');
		xs[i].addEvent('focus', function(e) { $(this).blur(); });	
		xs[i].addEvent('click', function(e) {
			if (e) new Event(e).stop();
			eval($(this).getProperty('xhref'));
		});		
	}
	//	(aja)x js links
	var xs = $$('.jslink');
	for(i=0;i<xs.length;i++){
		xs[i].removeEvents('click');
		xs[i].addEvent('focus', function(e) { $(this).blur(); });	
		xs[i].addEvent('click', function(e) {
			if (e) new Event(e).stop();
			eval($(this).getProperty('xhref'));
		});		
	}
}

function loadDiv(in_url, in_div){
    if(in_url && in_div){
	    //  get grid
	    new Request.HTML({   
	        method: 'get',   
	        url: SITE_ROOT+'page='+in_url, 
	        evalScripts: true, 
	        headers: {'X-REQUEST': 'AJAX'},
	        update: in_div,
	        onComplete: function(){
	        	window.fireEvent('ajaxload');
	            window.removeEvents('ajaxload');
	        }
		}).send();
    }
}


/* SCROLLER */
	
var slider;

function make_scrollarea(content, scrollbar, handle){
	var steps = ($(content).getScrollSize().y - $(content).getSize().y);
	if(steps > 0){
		$(scrollbar).removeClass('scrollcover');
		$$($(scrollbar), $(handle)).removeEvents();
		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);					
		});
		
		$('up').addEvent('mousedown', function(){ scroll(1); this.interval = setInterval('scroll(1);', 20); });
		$('up').addEvent('mouseup', function(){ clearInterval(this.interval); });
		$('up').addEvent('mouseleave', function(){ clearInterval(this.interval); });
		$('down').addEvent('mousedown', function(){ scroll(-1); this.interval = setInterval('scroll(-1);', 20); });
		$('down').addEvent('mouseup', function(){ clearInterval(this.interval); });
		$('down').addEvent('mouseleave', function(){ clearInterval(this.interval); });
		
		$(scrollbar).setStyle('visibility', 'visible');
		$(handle).setStyle('visibility', 'visible');
		$('up').setStyle('visibility', 'visible');
		$('down').setStyle('visibility', 'visible');
	} else {
		$(scrollbar).addClass('scrollcover');
		$(handle).setStyle('display', 'none');
	}
}

function scroll(in_direction){
	var step = slider.step - 10 * in_direction;	
	if(step > -10){
		slider.set(step);	
	}
}

/* INIT */
	
function preinit(){
	
	//	init
	init_ajaxlinks();
	
	//	player focus
	$$('#player a, .foldout .label a').addEvent('focus', function(){ this.blur(); });
	
	//	foldouts
	$$('.foldout .label').each(function(el, i){
		var img = el.getFirst('a').getFirst('img');
		img.set('src_original', img.getAttribute('src'));
		var preloadimg = new Image();
		preloadimg.src = img.getAttribute('src_on');
		var fo = el.getParent('.foldout');
		fo.fx = new Fx();
		el.addEvent('click', function(){
			fo.addClass('busy');
			if(fo.hasClass('open')){
				img.src = img.getAttribute('src_original');
				fo.fx.cancel();
				fo.getFirst('.content').setStyle('display', 'none');
				fo.fx = new Fx.Tween(fo, {duration: 1000, transition: Fx.Transitions.Elastic.easeOut, onComplete: function(){ fo.removeClass('busy'); fo.removeClass('open'); }}).start('margin-left', fo.getStyle('margin-left').toInt(), 303);
			} else {
				img.src = img.getAttribute('src_on');
				fo.fx.cancel();
				fo.getFirst('.content').setStyle('display', 'block');
				fo.fx = new Fx.Tween(fo, {duration: 1000, transition: Fx.Transitions.Elastic.easeOut, onComplete: function(){ fo.removeClass('busy'); fo.addClass('open'); }}).start('margin-left', fo.getStyle('margin-left').toInt(), 527);
			}
		});
		
		fo.addEvent('mouseenter', function(){
			if(!fo.hasClass('open') && !fo.hasClass('busy')){
				fo.fx.cancel();
				fo.fx = new Fx.Tween(fo, {duration: 500, transition: Fx.Transitions.Elastic.easeOut}).start('margin-left', fo.getStyle('margin-left').toInt(), 313);
			}
		});
		fo.addEvent('mouseleave', function(){
			if(!fo.hasClass('open') && !fo.hasClass('busy')){
				fo.fx.cancel();
				fo.fx = new Fx.Tween(fo, {duration: 1500, transition: Fx.Transitions.Elastic.easeOut}).start('margin-left', fo.getStyle('margin-left').toInt(), 303);
			}
		});
	});
	
	//	flash content images to indicate shadowbox
	$$('#container .image').addEvent('mouseenter', function(){ new Fx.Tween(this, {duration: 250}).start('opacity', 0.5, 1); });
	
	//	flash player buttons images to indicate interactivity
	$$('#player .playerbutton').addEvent('mouseenter', function(){ new Fx.Tween(this, {duration: 500}).start('opacity', 0.8, 1); });
	
	
	//	animate circle buttons on mouseover
	$$('.circlebutton').each(function(el, i){
		
		el.start = el.getStyle('margin-left').toInt();
		
		el.fx = new Fx();
		el.addEvent('mouseenter', function(){
			el.fx.cancel();
			el.fx = new Fx.Tween(el, {duration: 500, transition: Fx.Transitions.Elastic.easeOut}).start('margin-left', el.getStyle('margin-left').toInt(), el.start-10);	
		});	
		el.addEvent('mouseleave', function(){
				el.fx.cancel();
				el.fx = new Fx.Tween(el, {duration: 1500, transition: Fx.Transitions.Elastic.easeOut}).start('margin-left', el.getStyle('margin-left').toInt(), el.start+10);
		});	
	});
	
}

function init(){
	fix();
	fixpng();
		
	// IE6 bar
	if((parseFloat(navigator.appVersion.split("MSIE")[1]).toInt() <= 6) && (document.body.filters)){
		createIE6UpdateBanner({img_folder:'<?php echo SITE_ROOT; ?>img/'});
	}
	
	//	fire ajaxload
	window.fireEvent('ajaxload');
	window.removeEvents('ajaxload');
	
	//	init
	init_ajaxlinks();
	
}

function fix(){
	
	if($('body').getSize().x < $('bg').getSize().x){
		$('site').setStyle('marginLeft', "223px"); 
		$('site').setStyle('left', "0px");
	} else {
		$('site').setStyle('marginLeft', "-444px"); 
		$('site').setStyle('left', "50%");
	}
	if($('body').getSize().y < $('site').getSize().y){
		$('site').setStyle('marginTop', "183px"); 
		$('site').setStyle('top', "0px");
	} else {
		$('site').setStyle('marginTop', "-322px"); 
		$('site').setStyle('top', "50%");
	}
	
	if($('body').getSize().x < $('bg').getSize().x){
		$('bg').setStyle('marginLeft', "0px"); 
		$('bg').setStyle('left', "0px");
	} else {
		$('bg').setStyle('marginLeft', "-667px"); 
		$('bg').setStyle('left', "50%");
	}
	if($('body').getSize().y < $('site').getSize().y){
		$('bg').setStyle('marginTop', "0px"); 
		$('bg').setStyle('top', "0px");
	} else {
		$('bg').setStyle('marginTop', "-505px"); 
		$('bg').setStyle('top', "50%");
	}
	

}

window.addEvent('load', init);
window.addEvent('domready', preinit);
window.addEvent('resize', fix);

/* PLAYER */
function createPlayer(in_playlist){
	var params = {};
	var flashvars = {
		allowfullscreen: 'false',
		displayheight: '100',
		width: '200',
		playlist: 'none',
		playlistsize: '100',
		autostart: 'false',
		repeat: 'single',
		shuffle: 'false',
		file: in_playlist,
		playerready: 'player_init'
	};
	var attributes = {
		name: 'mediaplayer'
	};
	swfobject.embedSWF(SITE_ROOT+"swf/player.swf", "mediaplayer", "200", "200", "9.0.0", SITE_ROOT+"js/expressInstall.swf", flashvars, params, attributes);	
}

var current_play = 0;
var playlist;
var plyr;

function player_init(in_obj){
	plyr = new JWPlayer({id: in_obj.id});
	playlist = plyr.get_playlist();
	$('player_display').set('html', (current_play+1)+'. '+playlist[current_play]["title"]);
	//play();
}

function prev(){	
	current_play--;
	if(current_play < 0){ current_play = playlist.length-1; }
	plyr.prev();
	$('player_display').set('html', (current_play+1)+'. '+playlist[current_play]["title"]);
}

function play(){	
	$('player_display').set('html', (current_play+1)+'. '+playlist[current_play]["title"]);
	plyr.play();
}

function stop(){	
	$('player_display').set('html', (current_play+1)+'. '+playlist[current_play]["title"]);
	plyr.pause();
}

function next(){	
	current_play++;
	if(current_play == playlist.length){ current_play = 0; }
	plyr.next();
	$('player_display').set('html', (current_play+1)+'. '+playlist[current_play]["title"]);
}
