// JavaScript Document

// FancyPlayer.js - A spicy mix of FancyBox and Flowplayer

// step one - preloading background image

$(document).ready(function() {

	function preloadImages()
	{
	  for(var i = 0; i<arguments.length; i++)
	  {
		$("<img>").attr("src", arguments[i]);
	  }
	}

	preloadImages("../videos/images/video_bg.png");
	
// step two - declaring variables for playing video
	
	var videoclip='';
	var player='';
	
	$(".video_link").hover(function(){
		videoclip=$(this).attr('href');
		$(this).attr({"href":"#video_box"});
	},
	
	function(){
		$(this).attr({"href":""+videoclip+""});
	});
	
// step three - FancyBox Controls
	
	$(".video_link").fancybox({
		'hideOnContentClick':false,
		'overlayOpacity' :.6,
		'zoomSpeedIn'    :400,
		'zoomSpeedOut'   :400,
		'easingIn'		 : 'swing',
		'easingOut'		 : 'swing',
		'easingchange' : 'swing',
		'zoomOpacity' : true,
		'padding' : 1,
		'overlayShow': true,
		'allowFullscreen': true,
		
		
		
//FancyBox & swf player integration
		
		'callbackOnShow' :function(){
				
				
				player = $f("fancy_div",swfplayer,{ 



				key: '#$bae7956f967f9d23616', 




play:{opacity:0},
				clip:{
					autoPlay: true,
                    scaling: 'orig',
					autoBuffering:true,
					url:videopath+videoclip+'',
					onStart:function(clip){
						var wrap=jQuery(this.getParent());
						//numbers added here
						var clipwidth = clip.metaData.width;595
						var clipheight= clip.metaData.height;595
						var pos = $.fn.fancybox.getViewport();
						$("#fancy_outer").css({width:clipwidth,height:clipheight});
						$("#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)));
					},
					onFinish:function(){
						$('#fancy_close').trigger('click');
					}
				}
			});
			player.load();
			$('#fancy_close').click(function(){
				$("#fancy_div_api").remove();
			});
		},
		'callbackOnClose':function(){
			$("#fancy_div_api").remove();
		}
	});
	
}); 