var playerSlide;
var player;


function updatePlayerLegend(clip) {
	if ($('movie_title') && $('movie_descr') && $('movie_author')) {
		$('movie_title').innerHTML = clip.title;
		$('movie_descr').innerHTML = clip.description;
		$('movie_author').innerHTML = clip.details.author;
	}
}


function loadPlayer() {
	/*
	/swf/flowplayer-3.0.3/flowplayer.commercial-3.0.3.swf
	/swf/flowplayer/flowplayer.commercial-3.0.7.swf
	*/
	player = flowplayer("wowza", {src:"/swf/flowplayer/flowplayer.commercial-3.0.7.swf",wmode:'transparent',width:760,height:338}, {
		key: '#$40c5fd906d4a7dc90c4',
		playlist: [
			{
				autoPlay: false,
				autoBuffering: false,
				scaling: 'fit',
				url: '/flv/cyclone/vtt.flv',
				//provider:'rtmp',
				// Custom properties
				title: 'Downhill mountain bikers',
				description: 'Impressive. We rush downhill at 70 km/h on rough terrain. Smoovee removes the strong jitters and our videos become much more enjoyable.',
				details: {
					creator: 'The Smoovee team',
					author: 'The Anz&egrave;re Cyclone VTT bikers'
				},
				// Functions
				onBeforeBegin: function(clip) { updatePlayerLegend(clip); }
			},
			{
				autoPlay: false,
				autoBuffering: false,
				scaling: 'fit',
				url: '/flv/bolex/frieden_windsurf.flv',
				//provider:'rtmp',
				// Custom properties
				title: 'Super8 / 16mm films',
				description: 'We have stabilized more than 1300 hours of digitized films using Smoovee on their Xserve version. Our customers are delighted and it gives us a clear edge in our market.',
				details: {
					creator: 'The Smoovee team',
					author: 'The Bolex Digital team'
				},
				// Functions
				onBeforeBegin: function(clip) { updatePlayerLegend(clip); }
			},
			{
				autoPlay: false,
				autoBuffering: false,
				scaling: 'fit',
				url: '/flv/falquet/sequence_6.flv',
				//provider:'rtmp',
				// Custom properties
				title: 'Filming extreme skiers from a helicopter – the Falquet Brothers',
				description: 'Well done and thanks to the Smoovee team. We removed just enough jitter from our videos. Intuitive and fast, just as we like it.',
				details: {
					creator: 'The Smoovee team',
					author: 'Nicolas Falquet'
				},
				// Functions
				onBeforeBegin: function(clip) { updatePlayerLegend(clip); }
			}
		],
		plugins: {
		
			//
			// Plugin configuration
			
			rtmp: {
					url: '/swf/flowplayer/flowplayer.rtmp-3.0.2.swf',
					netConnectionUrl: 'rtmp://www.smoovee.net:1935/smoovee/_definst_/'
			},
			
			//
			// Control bar skinning
			controls: {
				height: 18,
				backgroundColor: 'transparent',
				backgroundGradient: 'none',
				progressColor:   '#a0a0a0',
				bufferColor:     '#808080',
				timeColor:       '#c0c0c0',
				durationColor:   '#f0f0f0',
				buttonColor:     '#8b8b8b',
				buttonOverColor: '#adadad',
				
				sliderColor: '#8b8b8b',
				
				volume:          false,
				mute:            false,
				fullscreen:      false,
				time:            true,
				playlist:        true
			}
		},
		play: {
			url: '/image/logo/play_smoovee-120x51.png',
			opacity: 1.0,
			height: '15%'
		},
		//
		// Player background skinning
		canvas: {
			backgroundColor:'transparent',
			backgroundGradient:'none',
			backgroundImage: 'url(/image/background/player.png)'
		}
	});
	
		return player;
	
}

window.addEvent('domready', function() {
	try {
		
		// Disable slider on Linux/Firefox
		if ( navigator.appVersion.indexOf("X11")!=-1 && navigator.appName=="Netscape" ) {
			throw -1;
		}
		
		// Mootools slider:
		playerSlide = new Fx.Slide('vertical_slide');
		playerSlide.hide();
		// Visibility:
		$('vertical_slide').setStyle('visibility','visible');
	}
	catch(e) {
		// Visibility:
		$('player_box').setStyle('visibility','hidden');
		$('vertical_slide').setStyle('display','none');
	}
});


window.addEvent('load', function() {
	player = loadPlayer();
});


function playMovie(param) {
	
	if (!player) {
		player = loadPlayer();
	}
	if (player) {
		
		$('movie_title').innerHTML = player.getClip(param).title;
		$('movie_descr').innerHTML = player.getClip(param).description;
		$('movie_author').innetHTML = player.getClip(param).details.author;
		
		if (playerSlide && !(playerSlide.open)) {
			playerSlide.slideIn();
		}
		else {
			$('player_box').setStyle('visibility','visible');
			$('vertical_slide').setStyle('display','block');
			$('vertical_slide').setStyle('visibility','visible');
		}
		
		player.play(param);
		player.pause(); // not working (too soon?)
		
	}
	
}
