window.addEvent('domready', init);
window.addEvent('resize', handleResize);
var initFunctions = new Array();

function initCufon() {
	try {
		Cufon.now();
		//if (!testFont('Myriad Pro Light')) {
			Cufon.replace('.home-titel');
			Cufon.replace('h1');
			Cufon.replace('h2');
			Cufon.replace('h3');
			Cufon.replace('#ul-menu-right', {'hover': true});
			Cufon.replace('#ul-menu-left', {'hover': true});
		//}
	}
	catch (ex) {}
}

function init() {
	//initCufon();
	externalLinks();
	
	$$('p.__button').each( function(item, index) {
		item.set('class', 'button_normal');
		item.setStyle('cursor', 'pointer');
		item.addEvents({
			'mouseenter': function() {
				item.set('class', 'button_active');
			},
			'mouseleave': function() {
				item.set('class', 'button_normal');
			}
		});
		item.getElement('a').set('class', 'button_link');
	});
	
	for( var i=0; i<initFunctions.length; i++) {
		initFunctions[i]();
	}
	
	handleResize();
	
}

(function ($) {
	$(function() {
		setInterval( "slideSwitch()", 5000 );
	});
	
	slideSwitch = function() {
		var $active = $('#div_fotoloop img.active');;
		if ( $active.length == 0 ) $active = $('#div_fotoloop img:last');
		
		var $next =  $active.next().length ? $active.next()
		        : $('#div_fotoloop img:first');
		
		$active.addClass('last-active');
		
		$next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
		    
	}
})(jQuery);

function handleResize() { }

function testFont(name) {
    name = name.replace(/['"<>]/g,'');

    var body  = document.body,
        test  = document.createElement('div'),
        installed = false,
        template =
            '<b style="display:inline !important; width:auto !important; font:normal 10px/1 \'X\',sans-serif !important">ii</b>'+
            '<b style="display:inline !important; width:auto !important; font:normal 10px/1 \'X\',monospace !important">ii</b>',
        ab;

    if (name) {
        test.innerHTML = template.replace(/X/g, name);

        test.style.cssText = 'position: absolute; visibility: hidden; display: block !important';

        body.insertBefore(test, body.firstChild);

        ab = test.getElementsByTagName('b');

        installed = ab[0].offsetWidth === ab[1].offsetWidth;

        body.removeChild(test);
    }

    return installed;
}
 
// Fade functie
var swapArray = new Array();
var swapFade = function(index) {
	if( $defined(swapArray[index]) ) {
		var element = swapArray[index];
		element.set('tween',{
			duration: 1500,
			property: 'opacity'
		});
		element.tween(1,0);
		swapArray[index] = element.getNext('div');
		if( !$defined(swapArray[index]) )
			swapArray[index] = element.getParent().getFirst('div');
		swapArray[index].set('tween',{
			duration: 1000,
			property: 'opacity'
		});
		swapArray[index].tween(0,1);
	}
}

/**
 * Calculates the total height of an element, including margin/padding/border
 * 
 * @param DOMElement element
 * @param bool noHeight If true, only calculates height of margin/padding/border
 * @return int
 */
function getVerticalOffset(element, noHeight) {
	var result = 0;
	if (!noHeight) {
		result += element.offsetHeight;
	}
	result += (element.getStyle('padding-top').toInt() + element.getStyle('padding-bottom').toInt());
	result += (element.getStyle('margin-top').toInt() + element.getStyle('margin-bottom').toInt());
	result += (element.getStyle('border-top').toInt() + element.getStyle('border-bottom').toInt());
	return result;
}


/**
 * Calculates the total width of an element, including margin/padding/border
 * 
 * @param DOMElement element
 * @param bool noHeight If true, only calculates width of margin/padding/border
 * @return int
 */
function getHorizontalOffset(element, noWidth) {
	var result = 0;
	if (!noWidth) {
		result += element.offsetWidth;
	}
	result += (element.getStyle('padding-left').toInt() + element.getStyle('padding-right').toInt());
	result += (element.getStyle('margin-left').toInt() + element.getStyle('margin-right').toInt());
	result += (element.getStyle('border-left').toInt() + element.getStyle('border-right').toInt());
	return result;
}

/**
 * Checks whether the specified e-mail addres has a valid format
 * 
 * @param string email
 * @return bool
 */
function IsValidEmail(email) {
	var emailExp = new RegExp("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4}");
	return emailExp.test(email);
}

/**
 * Creates _blank targets for links in the website. Specify the attribute
 * rel='external' to make it open in a new window.
 * 
 * @return void
 */
function externalLinks() {
 var anchors = $$("a");
 anchors.each( function(anchor) {
   if (anchor.get("href") && 
       anchor.get("rel") == "external") 
     anchor.target = "_blank"; 
 });
 var areas = $$("area"); 
 areas.each( function(area) {
   if (area.get("href") && 
       area.get("rel") == "external") 
     area.target = "_blank"; 
 });
}

/**
 * Returns the width of the scrollbar in pixels
 * 
 * @return int
 */
function getScrollbarWidth () {
	var inner = new Element('p');
	inner.setStyle('width', "100%");
	inner.setStyle('height', "200px");

	var outer = new Element('div');
	outer.setStyle('position', "absolute");
	outer.setStyle('top', "0px");
	outer.setStyle('left', "0px");
	outer.setStyle('visibility', "hidden");
	outer.setStyle('width', "200px");
	outer.setStyle('height', "150px");
	outer.setStyle('overflow', "hidden");
	inner.inject(outer);

	document.body.appendChild (outer);
	var w1 = inner.offsetWidth;
	outer.setStyle('overflow', 'scroll');
	var w2 = inner.offsetWidth;
	if (w1 == w2) w2 = outer.clientWidth;

	outer.destroy();

	return (w1 - w2);
};

/**
 * Returns an encoded version of the specified string
 * 
 * @param clearString
 * @return string
 */
function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

/**
 * Returns the unencoded version of the specified URL encoded string
 * @param encodedString
 * @return string
 */
function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}

/**
 * Custom YouTube player
 */
// Array containing the players
var ytplayers = new Array();

// event handler, gets called when the player is fully loaded
function onYouTubePlayerReady(playerId) {
	var player = document.getElementById("myytplayer" + playerId);
	ytplayers[playerId].player = player;
	if( player.isMuted() )
		player.unMute();
	if( ytplayers[playerId].startwhenloaded )
		ytplayers[playerId].loadNewVideo(ytplayers[playerId].id ,0);
}

// object containing all of the api calls to the youtube player
function YouTubePlayerObject(id, startwhenloaded) {
	this.id = id;
	this.player = 0;
	this.startwhenloaded = startwhenloaded;

	// functions for the api calls
	this.loadNewVideo = function(id, startSeconds) {
		if (this.player) {
			this.player.loadVideoById(id, parseInt(startSeconds));
		}
	}

	this.cueNewVideo = function(id, startSeconds) {
		if (this.player) {
			this.player.cueVideoById(id, startSeconds);
		}
	}
	
	this.tryPlay = function() {
		if(this.getPlayerState() <= 0)
			this.loadNewVideo(this.id, 0);
		else
			this.play();
	}

	this.play = function() {
		if (this.player) {
			this.player.playVideo();
		}
	}

	this.pause = function() {
		if (this.player) {
			this.player.pauseVideo();
		}
	}

	this.stop = function() {
		if (this.player) {
			this.player.stopVideo();
		}
	}

	this.getPlayerState = function() {
		if (this.player) {
			return this.player.getPlayerState();
		}
	}

	this.seekTo = function(seconds) {
		if (this.player) {
			this.player.seekTo(seconds, true);
		}
	}

	this.getBytesLoaded = function() {
		if (this.player) {
			return this.player.getVideoBytesLoaded();
		}
	}

	this.getBytesTotal = function() {
		if (this.player) {
			return this.player.getVideoBytesTotal();
		}
	}

	this.getCurrentTime = function() {
		if (this.player) {
			return this.player.getCurrentTime();
		}
	}

	this.getDuration = function() {
		if (this.player) {
			return this.player.getDuration();
		}
	}

	this.getStartBytes = function() {
		if (this.player) {
			return this.player.getVideoStartBytes();
		}
	}

	this.mute = function() {
		if (this.player && !this.player.isMuted()) {
			this.player.mute();
		}
	}

	this.unMute = function() {
		if (this.player && this.player.isMuted()) {
			this.player.unMute();
		}
	}
	
	this.changeMute = function() {
		if( this.player ) {
			if (this.player.isMuted()) {
				this.player.unMute();
			}
			else {
				this.player.mute();
			}
		}
	}

	this.getEmbedCode = function() {
		alert(this.player.getVideoEmbedCode());
	}

	this.getVideoUrl = function() {
		alert(this.player.getVideoUrl());
	}

	this.setVolume = function(newVolume) {
		if (this.player) {
			this.player.setVolume(newVolume);
		}
	}

	this.getVolume = function() {
		if (this.player) {
			return this.player.getVolume();
		}
	}

	this.clearVideo = function() {
		if (this.player) {
			this.player.clearVideo();
		}
	}
}

/*
	Slimbox v1.7 - The ultimate lightweight Lightbox clone
	(c) 2007-2009 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
*/
var Slimbox=(function(){var F=window,n=Browser.Engine.trident4,u,g,G=-1,o,w,E,v,y,M,s,m={},t=new Image(),K=new Image(),I,a,h,q,J,e,H,c,A,L,x,i,d,C;F.addEvent("domready",function(){$(document.body).adopt($$(I=new Element("div",{id:"lbOverlay",events:{click:D}}),a=new Element("div",{id:"lbCenter"}),H=new Element("div",{id:"lbBottomContainer"})).setStyle("display","none"));h=new Element("div",{id:"lbImage"}).injectInside(a).adopt(q=new Element("div",{styles:{position:"relative"}}).adopt(J=new Element("a",{id:"lbPrevLink",href:"#",events:{click:B}}),e=new Element("a",{id:"lbNextLink",href:"#",events:{click:f}})));c=new Element("div",{id:"lbBottom"}).injectInside(H).adopt(new Element("a",{id:"lbCloseLink",href:"#",events:{click:D}}),A=new Element("div",{id:"lbCaption"}),L=new Element("div",{id:"lbNumber"}),new Element("div",{styles:{clear:"both"}}))});function z(){var N=F.getScroll(),O=F.getSize();$$(a,H).setStyle("left",N.x+(O.x/2));if(v){I.setStyles({left:N.x,top:N.y,width:O.x,height:O.y})}}function l(N){["object",n?"select":"embed"].forEach(function(P){Array.forEach(document.getElementsByTagName(P),function(Q){if(N){Q._slimbox=Q.style.visibility}Q.style.visibility=N?"hidden":Q._slimbox})});I.style.display=N?"":"none";var O=N?"addEvent":"removeEvent";F[O]("scroll",z)[O]("resize",z);document[O]("keydown",p)}function p(O){var N=O.code;return u.closeKeys.contains(N)?D():u.nextKeys.contains(N)?f():u.previousKeys.contains(N)?B():false}function B(){return b(w)}function f(){return b(E)}function b(N){if(N>=0){G=N;o=g[N][0];w=(G||(u.loop?g.length:0))-1;E=((G+1)%g.length)||(u.loop?0:-1);r();a.className="lbLoading";m=new Image();m.onload=k;m.src=o}return false}function k(){a.className="";d.set(0);h.setStyles({backgroundImage:"url('"+o+"')",display:""});q.setStyle("width",m.width);$$(q,J,e).setStyle("height",m.height);A.set("html",g[G][1]||"");L.set("html",(((g.length>1)&&u.counterText)||"").replace(/{x}/,G+1).replace(/{y}/,g.length));if(w>=0){t.src=g[w][0]}if(E>=0){K.src=g[E][0]}M=h.offsetWidth;s=h.offsetHeight;var P=Math.max(0,y-(s/2)),N=0,O;if(a.offsetHeight!=s){N=i.start({height:s,top:P})}if(a.offsetWidth!=M){N=i.start({width:M,marginLeft:-M/2})}O=function(){H.setStyles({width:M,top:P+s,marginLeft:-M/2,visibility:"hidden",display:""});d.start(1)};if(N){i.chain(O)}else{O()}}function j(){if(w>=0){J.style.display=""}if(E>=0){e.style.display=""}C.set(-c.offsetHeight).start(0);H.style.visibility=""}function r(){m.onload=$empty;m.src=t.src=K.src=o;i.cancel();d.cancel();C.cancel();$$(J,e,h,H).setStyle("display","none")}function D(){if(G>=0){r();G=w=E=-1;a.style.display="none";x.cancel().chain(l).start(0)}return false}Element.implement({slimbox:function(N,O){$$(this).slimbox(N,O);return this}});Elements.implement({slimbox:function(N,Q,P){Q=Q||function(R){return[R.href,R.title]};P=P||function(){return true};var O=this;O.removeEvents("click").addEvent("click",function(){var R=O.filter(P,this);return Slimbox.open(R.map(Q),R.indexOf(this),N)});return O}});return{open:function(P,O,N){u=$extend({loop:false,overlayOpacity:0.8,overlayFadeDuration:400,resizeDuration:400,resizeTransition:false,initialWidth:250,initialHeight:250,imageFadeDuration:400,captionAnimationDuration:400,counterText:"Afbeelding {x} van {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78]},N||{});x=new Fx.Tween(I,{property:"opacity",duration:u.overlayFadeDuration});i=new Fx.Morph(a,$extend({duration:u.resizeDuration,link:"chain"},u.resizeTransition?{transition:u.resizeTransition}:{}));d=new Fx.Tween(h,{property:"opacity",duration:u.imageFadeDuration,onComplete:j});C=new Fx.Tween(c,{property:"margin-top",duration:u.captionAnimationDuration});if(typeof P=="string"){P=[[P,O]];O=0}y=F.getScrollTop()+(F.getHeight()/2);M=u.initialWidth;s=u.initialHeight;a.setStyles({top:Math.max(0,y-(s/2)),width:M,height:s,marginLeft:-M/2,display:""});v=n||(I.currentStyle&&(I.currentStyle.position!="fixed"));if(v){I.style.position="absolute"}x.set(0).start(u.overlayOpacity);z();l(1);g=P;u.loop=u.loop&&(g.length>1);return b(O)}}})();

// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
Slimbox.scanPage = function() {
	$$(document.links).filter(function(el) {
		return el.rel && el.rel.test(/^lightbox/i);
	}).slimbox({/* Put custom options here */}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
};
window.addEvent("domready", Slimbox.scanPage);
