(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
	
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			
			fx.start = [start[0],start[2]];
			
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);



$(document).ready(function($){

	$('.pers-link').click(function() {
		$(".pers-description, .pers-image").hide();
		id = $(this).attr("id").replace('pers-link-','');
		$("#pers-description-"+id).show().addClass('.active');
		$("#pers-link-"+id+" img").show();
		$("#tekst_mensen").hide();
	});
	
	$(".pers-image").hide();
	
	$(".reflected").reflect();

	jQuery("a.photobox").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0,
		'overlayShow': true
	});    
	
	jQuery("a.youtube").fancybox({
		'zoomSpeedIn':	100, 
		'zoomSpeedOut':	100,
		'frameWidth': 425,
		'frameHeight': 344,
		'overlayShow': true
	});   
		
	
	$('#sfeer').cycle({ 
    	fx			: 'fade', 
    	speed		: 1800,
    	pager:  '#nav' ,
    	pauze: 0,
    	pauseOnPagerHover: 1,
    	cleartype: true,
    	cleartypeNoBg: true,
    	pagerEvent: 'mouseover',
   	 	allowPagerClickBubble: true,
		pagerAnchorBuilder: function(idx, slide) { 
    		// return selector string for existing anchor 
    		return '#nav li:eq(' + idx + ') '; 
		}
	});
	/*$('#sfeer-content').cycle({ 
    	fx			: 'fade', 
    	speed		: 900,
   	});*/
   	
   	$('#sfeer-content').nivoSlider({
	        effect:'fold,sliceDownLeft', // Specify sets like: 'fold,fade,sliceDown'
	        slices:8, // For slice animations
	        boxCols: 2, // For box animations
	        boxRows: 4, // For box animations
	        animSpeed:1000, // Slide transition speed
	        pauseTime:4000, // How long each slide will show
	        startSlide:0, // Set starting Slide (0 index)
	        directionNav:false, // Next & Prev navigation
	        directionNavHide:false, // Only show on hover
	        controlNav:true, // 1,2,3... navigation
	        controlNavThumbs:false, // Use thumbnails for Control Nav
	        controlNavThumbsFromRel:false, // Use image rel for thumbs
	        keyboardNav:false, // Use left & right arrows
	        pauseOnHover:false, // Stop animation while hovering
	        manualAdvance:false, // Force manual transitions
	
	        prevText: 'Vorige', // Prev directionNav text
	        nextText: 'Volgende' // Next directionNav text
	    });
	
	
	
	$('.pagenav li:not(.active)')
		.css( {backgroundPosition: "-470px 0px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px 0px)"}, 250);
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(-470px 0px)"}, 80)
	});
	
	$('#nav li a').mouseover(function() {
		//$('#nav li a').removeClass('active');
		$('.page').hide();
		$('#sfeer').cycle('resume');
		$(this).addClass('active');
	});
	 
	$('#topmenu #nav li a').mouseover(function(){
	 		var position = $('#nav li #'+this.id).position();
	 
	 		$(".arrow").css({
	 			top: position.top+16
	 		});
	 	
	 		var pos ; 
	 		pos = this.id;
			//alert(pos);
	 		//$('#sfeer').cycle('pauze');
	 		$('#sfeer').cycle('toggle');
	 		$('.page').hide();
	 		$('.pagebox'+pos).fadeIn(400);
	});
	
	
	/*$('#topmenu #nav li a').click(function(){
	 	
	 	if ($(this).hasClass('clicked') === false){
	 		var position = $('#nav li #'+this.id).position();
	 
	 		$(".arrow").css({
	 		top: position.top+16
	 		});
	 	
	 		var pos ; 
	 		pos = this.id;
			//alert(pos);
	 		//$('#sfeer').cycle('pauze');
	 		$('#sfeer').cycle('toggle');
	 		$('.page').hide();
	 		$('.pagebox'+pos).fadeIn(400);
	 		$(this).addClass('clicked');
	 		return false;
	 	}
	});*/
	
	$('#topmenu #nav li a').hover(function(){
	 	
	 	if ($(this).hasClass('clicked') === false){
	 		var position = $('#nav li #'+this.id).position();
	 
	 		$(".arrow").css({
	 			top: position.top+16
	 		});
	 	
	 		var pos ; 
	 		pos = this.id;
			//alert(pos);
	 		//$('#sfeer').cycle('pauze');
	 		//$('#sfeer').cycle('stop');
	 		$('#sfeer').cycle('toggle');
	 		$('.page').hide();
	 		$('.pagebox'+pos).fadeIn(400);
	 		$(this).addClass('clicked');
	 		return false;
	 	}
	});
	 
	if($(".merklogo img[title]").length>0){
		$(".merklogo img[title]").tooltip({})
	}
	 
});




// create custom animation algorithm for jQuery called "bouncy"
$.easing.bouncy = function (x, t, b, c, d) {
    var s = 1.70158;
    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
}

// create custom tooltip effect for jQuery Tooltip
$.tools.tooltip.addEffect("bouncy",

	// opening animation
	function(done) {
		this.getTip().animate({top: '+=15'}, 500, 'bouncy', done).show();
	},

	// closing animation
	function(done) {
		this.getTip().animate({top: '-=15'}, 500, 'bouncy', function()  {
			$(this).hide();
			done.call();
		});
	}
);
