$(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/congrescentrum/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();

	});
		
});
