	$(document).ready(function() {

		function preloadImages()
		{
		  for(var i = 0; i<arguments.length; i++)
		  {
			$("<img>").attr("src", arguments[i]);
		  }
		}

		preloadImages("images/video_bg.png");
		
		var videoclip='';
		var player='';
		
		$(".video_link").hover(function(){
			videoclip=$(this).attr('href');
			$(this).attr({"href":"#video_box"});
		},
		
		function(){
			$(this).attr({"href":""+videoclip+""});
		});
		
		$(".video_link").fancybox({
			'hideOnContentClick':false,
			'overlayOpacity' :.95,
			'zoomSpeedIn'    :400,
			'zoomSpeedOut'   :400,
			'easingIn'		 : 'easeOutBack',
			'easingOut'		 : 'easeInBack',
			'callbackOnShow' :function(){
					player = $f("fancy_div",swfplayer,{
					buffering : false,
					play:{opacity:0},
					clip:{
						autoPlay:true,
						autoBuffering:true,
						url:videopath+videoclip+'',
						onStart:function(clip){
							var wrap=jQuery(this.getParent());
							//var clipwidth = clip.metaData.width;
							//var clipheight= clip.metaData.height;
							var clipwidth = 800;
							var clipheight= 450;						
							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');
						}
					},
					playlist: [				
						{	
							// "standard" flowplayer properties
							url: videopath + 'videos/fxi_part1_web.flv',
							autoPlay: true,	
							
							// custom property
							title: 'Experience Innovation Solutions',

							// custom properties can also be objects such as here
							details: {
								date: '03/23/2011',
								creator: 'Youcef',
								subject: ['FXI', 'Experience', 'Innovation', 'Solutions']
							}							
						}						
					],
					plugins: {
						
						sharing: {
							/*
							// load the sharing plugin
							url: videopath + 'flowplayer.sharing-3.2.1.swf',
							
							// Buttons' colors
							buttons: {
								// make the mouse-over state color red
								overColor: '#aaaaaa',
								height: '20px',
								width: '20px'
							},

							// email specific options
							email: {
								// use a non-default subject line in emails
								subject: 'A cool video in megavideos.com'
							},

							// embed code specific options
							embed: {
								// a fallback URL used with a video tag if Flash is not supported
								fallbackUrls: [ "Extremists.mov" ]
							},

							// disable facebook sharing
							facebook: true,

							// don't open twitter in a popup browser window
							twitter: {
								popupOnClick: false
							} */
						}
					}
				});
				player.load();
				$('#fancy_close').click(function(){
					$("#fancy_div_api").remove();
				});
			},
			'callbackOnClose':function(){
				$("#fancy_div_api").remove();
			}
		});
		
	}); 
