(function($) {
	
	// jQuery fixCheckBoxes 1.1
	$.fn.fixCheckBoxes=function(){return this.each(function(){var a=$(this);var b=$('<input type="hidden" />');b.attr({'id':a.attr('id')+'_hidden','name':a.attr('name')});if(a.attr('checked'))b.val('Ja');else b.val('Nee');a.after(b);a.removeAttr('name');a.click(function(){if(b.val()=='Nee')b.val('Ja');else b.val('Nee')})})};

	// jQuery classHandler 1.0
	$.fn.classHandler=function(a,b){var c={'mouseover':'mouseout','mouseenter':'mouseleave','focus':'blur'};var d=$(this);d.bind(a,function(){$(this).addClass(b)});d.bind(c[a],function(){$(this).removeClass(b)});return this};

})(jQuery);

$(window).load(function() {

	$('.movie').each(function(i) {
							  
		// Set up variables
		var fpContainer = $(this),
			fpMovie = fpContainer.children('.movie-player');
			
		if(fpMovie.attr('href') == '/') {
			fpContainer.remove();
			return false;
		};
		
		var fpMovieId = fpMovie.attr('class') + '-' + i,
			fpControls = fpContainer.children('.movie-controls'),
			fpControlsId = fpControls.attr('class') + '-' + i;
			
		// Assign attributes
		fpMovie.attr('id', fpMovieId);
		fpControls.attr('id', fpControlsId);
		
		// Set up flowplayer
		flowplayer(fpMovieId, {
			src : 'style/fentener/flowplayer/flash/flowplayer.swf',
			wmode : 'opaque'
		}, {
			canvas : {
				backgroundColor : '#ffffff'
			},
			clip: {
				autoPlay: true,
				autoBuffering: true
			},
			plugins: {
				controls : null
			}
		}).controls(fpControlsId);

		// Set up initial state
		var movieBackground = $('.movie-background');
		var oBottom = fpControls.css('bottom'),
			initStyle = {
			opacity : 0
		};
		fpControls.css(initStyle);
		movieBackground.css(initStyle);
			
		// Set up events
		fpContainer.hover(function() {
			fpControls.stop().animate({
				opacity : 1
			}, 250);
		}, function() {
			fpControls.stop().animate(initStyle, 500);
		});
		
		fpContainer.hover(function() {
			movieBackground.stop().animate({
				opacity : .65
			}, 250);
		}, function() {
			movieBackground.stop().animate(initStyle, 500);
		});
		
		if(fpContainer.is(':hidden'))
			fpContainter.show();

	});
		
});

$(function() {

	// Assign classHandler to form fields
	$('.form input[type=text], .form textarea').classHandler('focus', 'focus');
	$('.form input[type=submit]').classHandler('mouseover', 'hover');
	
});
