﻿// FancyPlayer.js - A spicy mix of FancyBox and Flowplayer

$(document).ready(function() {
	var videoclip;
	var player;
	var vidid;
	
	$(".video_link").hover(function(){
		vidid = $(".video_link").index(this);
		videoclip = $(".video_link").eq(vidid).attr("name");
	});
	

	try{
		$(".video_link").fancybox({
	
			'hideOnContentClick':false,
			'overlayOpacity' :.6,
			'zoomSpeedIn'    :400,
			'zoomSpeedOut'   :400,
			'easingIn'		 : 'easeOutBack',
			'easingOut'		 : 'easeInBack',
			
			'callbackOnShow' :function(){

				if (videoclip == 'image') {				
					$("#fancy_right, #fancy_left").css({height:$("#fancy_div").height(), bottom: '0'});
					
					} else {
				
					player = $f("fancy_content",{src: swfplayer, 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:videopath+videoclip+'',
						onStart:function(clip){
							var wrap=jQuery(this.getParent());
							var clipwidth = 560;
							var clipheight= 340;
							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_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_content_api").remove();
			}
		});
	}
	catch(err){
	}
	
}); 
