// FancyPlayer.js - A spicy mix of FancyBox and Flowplayer

$(document).ready(function() {

	var videoclip;
	var player;
	var vidid;
	
	$("#movieThumb a").fancybox({
		'hideOnContentClick':false,
		'overlayOpacity' : 1,
		'overlayColor': '#ffffff',
		'frameWidth': 500,
		'frameHeight': 300,
		'callbackOnShow' :function(){
			
			if (videoclip == 'image') {				
				
				$("#fancy_right, #fancy_left").css({height:$("#fancy_div").height(), bottom: '0'});
				
				} else {
			
				player = $f("fancy_content",{src: '/tl_files/swf/flowplayer-3.1.1.swf', wmode: 'opaque'},{
							
				play:{opacity:0},
			  //key: '#$flowplayerkeycode',

				plugins: {
					
				controls:  {
				backgroundColor: 'transparent',
				progressColor: 'transparent',
				bufferColor: 'transparent',
				all:false,
				scrubber:true,
				volume:true,
				mute:true,
				play:true,
				height:30,
				autoHide: 'always'		

				}

				},
				clip:{

					autoPlay:true,
					autoBuffering:true,
					url: '/tl_files/movie/th3.flv',
					onStart:function(clip){
						var wrap=jQuery(this.getParent());
						var clipwidth = clip.metaData.width;
						var clipheight= clip.metaData.height;
						var pos = $.fn.fancybox.getViewport();
						$("#fancy_outer").css({width:clipwidth+20,height:clipheight+20});
						$("#fancy_outer").css('left', ((clipwidth + 36) > pos[0] ? pos[2] : pos[2] + Math.round((pos[0] - clipwidth	- 36)	/ 2)));
						$("#fancy_outer").css('top',  ((clipheight + 50) > pos[1] ? pos[3] : pos[3] + Math.round((pos[1] - clipheight - 50)	/ 2)));
						$("#fancy_right, #fancy_left").css({height:clipheight-40, bottom: '40px'});
						
					},
					onFinish:function(){
						$('#fancy_close').trigger('click');
					}
				}
			});
			
			
				
			player.load();
			
		}
			
			$('#fancy_close').click(function(){
				$("#fancy_div_api").remove();
			});
			
			$('#fancy_right, #fancy_right_ico').click(function(){
				vidid++;
				videoclip = $(".video_link").eq(vidid).attr("name");
			});
			
			$('#fancy_left, #fancy_left_ico').click(function(){
				vidid--;
				videoclip = $(".video_link").eq(vidid).attr("name");
			});
		},
		'callbackOnClose':function(){
			$("#fancy_div_api").remove();
		}
	});
	
}); 

