// FancyPlayer.js - A spicy mix of FancyBox and Flowplayer

//mod: by Dr Phil to force fancybox 1.3.1

$(document).ready(function() {

	var videoclip;
	var player;
	var vidid;
	var captions;
	var capShow;
	var ccbutShow;
	
	$(".video_link").hover(function(){
		vidid = $(".video_link").index(this);
		videoclip = $(".video_link").eq(vidid).attr("name");
		if ($(".video_link").eq(vidid).hasClass('captions')) {
		captions = $(".video_link").eq(vidid).attr("name")+'.srt';
		capShow = true;
		ccbutShow = { width: 20, height: 15, right: 5, bottom: 32, label: 'SUBS' };
		} else { 
		captions = 'videos/empty.srt';
		capShow = false;
		ccbutShow = null;
		}
	});
	
	$(".video_link").fancybox({
		
		'overlayOpacity' :0.6,
		'overlayColor'  : '#000',
		'titleShow'     : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'showCloseButton': true,
		
		'onComplete' :function(){
			
				player = $f("fancybox-inner",{src: swfplayer, wmode: 'opaque'},{
							
				play:{opacity:0},
			
				plugins: {
					
				
				content: { 
					url:swfcontent, 
					bottom: 25, 
					height:40, 
					backgroundColor: 'transparent', 
					backgroundGradient: 'none', 
					border: 0, 
					textDecoration: 'outline', 
					style: {  
						body: {  
							fontSize: 16,  
							fontFamily: 'Arial', 
							textAlign: 'center', 
							color: '#ffffff' 
						}  
					}  
				},
				
				controls:  {
				backgroundColor: 'transparent',
				progressColor: 'transparent',
				bufferColor: 'transparent',
				buttonColor:'#999999',
				buttonOverColor:'#555555',
				all:false,
                                //fullscreen:true,
				scrubber:true,
				volume:true,
				mute:true,
				play:true,
				height:24,
				autoHide: 'always'		

				}

				},
				clip:{
					autoPlay:true,
					autoBuffering:true,
					url:videopath+videoclip+'',
					captionUrl: videopath+captions+'', 
					onStart:function(clip){
					var clipwidth = clip.metaData.width;
					var clipheight= clip.metaData.height;
					$("#fancybox-inner").css({width:clipwidth,height:clipheight});
					$("#fancybox-wrap").css({width:clipwidth+20,height:clipheight+20});
					$.fancybox.center();
						
					},
					onFinish:function(){
						$('#fancybox-close').trigger('click');
					}
				}
			});
			
			
				
			player.load();
			
		
			
			
			$('#fancy_right, #fancy_right_ico').click(function(){
				vidid++;
				videoclip = $(".video_link").eq(vidid).attr("name");
				if ($(".video_link").eq(vidid).hasClass('captions')) {
				captions = $(".video_link").eq(vidid).attr("name")+'.srt';
				capShow = true;
				ccbutShow = { width: 20, height: 15, right: 5, bottom: 32, label: 'CC' };
				} else {
				captions = 'videos/empty.srt';
				capShow = false;
				ccbutShow = null;
				}
			});
			
			$('#fancy_left, #fancy_left_ico').click(function(){
				vidid--;
				videoclip = $(".video_link").eq(vidid).attr("name");
				if ($(".video_link").eq(vidid).hasClass('captions')) {
				captions = $(".video_link").eq(vidid).attr("name")+'.srt';
				capShow = true;
				ccbutShow = { width: 20, height: 15, right: 5, bottom: 32, label: 'SUBS' };
				} else {
				captions = 'videos/empty.srt';
				capShow = false;
				ccbutShow = null;
				}
			});
		},
		'callbackOnClose':function(){
			$("#fancy_content_api").remove();
		}
	});
}); 
