jQuery(function(){
	jQuery('ul.sf-menu').superfish({
		delay:       500,
		animation:   {opacity:'show',height:'show'}
	});
	
	$("a[rel=fotos]").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Afbeelding ' + (currentIndex + 1) + ' van de ' + currentArray.length + (title.length ? ' &nbsp;-&nbsp; ' + title : '') + '</span>';
		}
	});
	
	var extra = 262-($(window).width()-980)/2;
	$("#banner-bg").width($(window).width()+extra);
	
	$(window).resize(function() {
		var extra = 262-($(window).width()-980)/2;
		$("#banner-bg").width($(window).width()+extra);
	});
	
	jQuery.fn.startAnimation = function(  params, duration, easing, callback ) {
		jQuery(this).animate( params, duration, easing, callback );
		var data = { target:this.get(0), params: params, duration: duration, easing: easing, callback: callback,
					startTime: new Date().getTime(), timePlayed: 0, timeRemaining: 0 };
		if( !jQuery.pauseableAnimations ) {
			jQuery.extend({ pauseableAnimations: new Array( data ) });
		} else {
			for( var i in jQuery.pauseableAnimations ) {
				if( jQuery.pauseableAnimations[i].target == this.get(0) ) {
					jQuery.pauseableAnimations[i] = data;
				} else {
					jQuery.pauseableAnimations.push( data );
				};
			};
		};
	};
	jQuery.fn.pauseAnimation = function() {
		if( jQuery.pauseableAnimations ) {
			for(var i in jQuery.pauseableAnimations ) {
				if( jQuery.pauseableAnimations[i].target == this.get(0) ) {
					jQuery(this).stop();
					var now = new Date().getTime();
					var data = jQuery.pauseableAnimations[i];
					data.timePlayed += ( now - data.startTime );
					data.timeRemaining = data.duration - data.timePlayed;
					if( data.timePlayed > data.duration ) {
						var newArray = new Array();
						for( var p in jQuery.pauseableAnimations ) {
							if( jQuery.pauseableAnimations[p] != data ) newArray.push( jQuery.pauseableAnimations[p] );
						};
						jQuery.pauseableAnimations = newArray.length > 0 ? newArray : null;
						delete newArray;
						return this;
					};
					break;
				};
			};
		};
		return this;
	};
	jQuery.fn.resumeAnimation = function() {
		if( jQuery.pauseableAnimations ) {
			for(var i in jQuery.pauseableAnimations ) {
				var data = jQuery.pauseableAnimations[i];
				if( data.target == this.get(0) ) {
					this.animate( data.params, data.timeRemaining, data.easing, data.callback );
					data.startTime = new Date().getTime();
					return this;
				};
			};
		};
	};
	
	var scrollerWidth = 0;		
	var aantal = 0;
	var scrollerContent = $("#sponsors-inner").html();
	$( "#sponsors-inner img" ).each(function( intIndex ){
		scrollerWidth = scrollerWidth + $(this).width()+12;
		aantal++;
	});
	
	function vulSponsors(i){
		if(aantal !== 0){
			$("#sponsors-inner").html($("#sponsors-inner").html()+scrollerContent);
			i = i+1;
			if((980/scrollerWidth) > i){
				vulSponsors(i);
			} else {
			//alert(i);
			
			}
		}
	}
	vulSponsors(0);
	var snelheid = scrollerWidth*30;
	//$("#sponsors-inner").html(scrollerContent+scrollerContent+scrollerContent+scrollerContent);
	function scrollHorizontalLeft(){
		$('#sponsors-inner').startAnimation({marginLeft:'-'+scrollerWidth},
			snelheid,
			'linear',
			function() {
				$('#sponsors-inner').animate({marginLeft:'0'}, 0);
				scrollHorizontalLeft();
			});
	}
	scrollHorizontalLeft();
	$('#sponsors-inner').mouseenter(function() {
		$("#sponsors-inner").pauseAnimation();
		//alert('nu');
	});
	
	$('#sponsors-inner').mouseleave(function() {
		$('#sponsors-inner').resumeAnimation();
		//alert('nu');
	});
});

function slideSwitch() {
    var $active = $('#slideshow IMG.active');
    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


$(function() {
	slideSwitch();
    setInterval( "slideSwitch()", 4000 );
    setInterval( "$('#slideshow').css('visibility', 'visible')", 2000 );
	
	
});
