$(document).ready(function() {

$(".popupVideo").hover(function(){
	divid = $(".popupVideo").index(this);
	lien = $(".popupVideo").eq(divid).attr("href");
});
$(".popupVideo").fancybox({
		'hideOnContentClick':false,
		'overlayOpacity':.6,
		'overlayColor':	'#3d5a77',
		'zoomSpeedIn':400,
		'zoomSpeedOut':400,
		'easingIn': 'easeOutBack',
		'easingOut': 'easeInBack',
		'callbackOnShow': function(){
			player = $f("fancy_content",{src: swfplayer, wmode: 'opaque'},{							
				play:{opacity:0},
				plugins: {					
					controls:  {
						backgroundColor: 'transparent',
						progressColor: 'transparent',
						bufferColor: 'transparent',
						all:false,
						scrubber:true,
						volume:true,
						mute:true,
						play:true,
						height:30,
						autoHide: 'false'
					}
				},
				clip:{
					autoPlay:true,
					autoBuffering:true,
					url:videopath+lien+'',
					onStart:function(clip){
						var wrap=jQuery(this.getParent());
						var coeff = 2;
						//if (screen.height < 2000) coeff= 1.5; else coeff = 1;
						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('left', ((clipwidth + 80) > pos[0] ? pos[2] : pos[2] + Math.round((pos[0] - clipwidth	- 80)	/ 2)));
						//$("#fancy_outer").css('top',  ((clipheight + 50) > pos[1] ? pos[3] : pos[3] + Math.round((pos[1] - clipheight - 50)	/ 2)));
						$("#fancy_outer").css('top',  ((clipheight + 100) > pos[1] ? pos[3] : pos[3] + Math.round((pos[1] - clipheight - 100)	/ 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(){
				divid++;
				lien = $(".popupVideo").eq(divid).attr("href");
			});			
			$('#fancy_left, #fancy_left_ico').click(function(){
				divid--;
				lien = $(".popupVideo").eq(divid).attr("href");
			});
			*/
		},
		'callbackOnClose':function(){
			$("#fancy_div_api").remove();
		}		
	});
	
	$("a.popupImage").fancybox({
		'overlayOpacity':.6,
		'overlayColor': '#3d5a77',
		'zoomSpeedIn':400,
		'zoomSpeedOut':400,
		'easingIn': 'easeOutBack',
		'easingOut': 'easeInBack',
		'overlayShow': true,
		'titlePosition': 'inside'
	});
	
	$("a.popupPage").fancybox({
		'overlayOpacity':.6,
		'overlayColor': '#3d5a77',
		'zoomSpeedIn':400,
		'zoomSpeedOut':400,
		'easingIn': 'easeOutBack',
		'easingOut': 'easeInBack',
		'width':650,
		'height':600,
		'autoDimensions': true,
		'overlayShow': true,
		'type': 'iframe'
	});
	
		$("a.popupBiblio").fancybox({
		'overlayOpacity':.6,
		'overlayColor': '#3d5a77',
		'zoomSpeedIn':400,
		'zoomSpeedOut':400,
		'easingIn': 'easeOutBack',
		'easingOut': 'easeInBack',
		'width':650,
		'height':600,
		'autoDimensions': true,
		'overlayShow': true,
		'type': 'iframe'
	});

	
	$("a.lienpopup").fancybox({
		'overlayOpacity':	0.8,
		'overlayColor':		'#3d5a77',
		//'zoomSpeedIn':		500,
		//'zoomSpeedOut':		500,
		'frameHeight':700,
		'frameWidth':700,	
		'overlayShow':		true
	});
	
	if (screen.height <= 770) { setheight =  415; setwidth= 620; }
	else { setheight = 610; setwidth= 920; }

	$("a.lienpopup_video").fancybox({
		'hideOnContentClick':false,
		'overlayOpacity':	0.8,
		'overlayColor':		'#3d5a77',
		//'zoomSpeedIn':		500,
		//'zoomSpeedOut':		500,
		
		'frameHeight': setheight,
		'frameWidth': setwidth,	
		'overlayShow':		true
	});


	
});