(function(){
	var videoURL;
	var showVideo = function() {
		jQuery('#fancy_div').flowplayer('swf/flowplayer-3.1.5.swf', {
			clip : {
				url : videoURL,
				autoPlay : true
			},
			
			plugins : {
				controls : {
					autoHide : 'always',
					backgroundColor : '#000000',
					bufferColor : '#999999',
					volumeSliderColor : '#999999',
					timeBgColor : '#999999',
					progressColor : '#333333',
					durationColor: '#333333',
					timeColor : '#ffffff'
				}
			}
		} );
	}
	
	jQuery(function() {
		
		// no way to call fancybox init directly
		jQuery('body').append('<div id="watch"></div>');
		jQuery('body').append('<a class="hidden" href="#watch"></a>');
		
		jQuery('a.hidden').fancybox({
			frameWidth : 640,
			frameHeight : 480,
			callbackOnShow : showVideo
		})
		
		jQuery('a.watch, h2 a').click(function(e){
			e.preventDefault();
			var $this = jQuery(this);
			var id = $this.attr('href');
			videoURL = $this.parents('li').find('a.download').attr('href');
			jQuery('a.hidden').click();
		});
	});
})();