var video_scale = 15/9;
$(document).ready(function() {
    
    $('.quick-nav').localScroll({target:'#slider-wrapper', hash:false, lazy: true});

    var width = $(window).width();
    var height = $(window).height();
    
    var width_target = Math.round(width * 2/3);
    var height_target = Math.round(width * 2/3 * video_scale);
    
    $('div.overlay').css('width', width_target);
    $('div.overlay').css('height', height_target); 
    var swf_id = 'overlay-video';
    var player = $f(swf_id,
            {
                src: '/swf/flowplayer.commercial-3.1.5.swf',
                wmode: 'opaque'
                
            },
            {            
                                key: '#$b590d4fd98ccd60ccab',
                                logo: { 
                    url: '/img/logo.png',
                    width: 176,
                    height: 104,
                    top: 20, 
                    right: 20, 
                    opacity: 1,                     
                    fullscreenOnly: false, 
                    displayTime: 45 
                },
                play: {                                    
                    url: '/img/play_64.png',                  
                    opacity: 1,
                    width: 214,
                    height: 64,
                    label: null,                 
                    replayLabel: 'Play again',                  
                    fadeSpeed: 500, 
                    rotateSpeed: 50 
 
                }, 
                clip: {   
                    url: '/files/videos/03167.mp4',   
                    autoPlay: true,
                    scaling : 'fit'
                },  
                plugins: {  
                    controls: {                  
                        url: '/swf/flowplayer.controls-3.1.5.swf',                                   
                        // styling properties (will be applied to all plugins) 
                        background: '#000000', 
                        backgroundGradient: 'low',                  
                        // controlbar specific settings 
                        timeColor: '#1f374f', 
                        tooltips: { 
                            buttons: true, 
                            fullscreen: 'Enter fullscreen mode'
                        } 
                    } 
                } 
            });
    
	// setup button action. it will fire our overlay 
	$("a#videocall[rel]").overlay({		
		expose: {
		color: '#333',
		loadSpeed: 200,
		opacity: 0.9
        },

        // when overlay is opened, load our player
        onLoad: function() {
        
        
            // verifie que le div n'a pas ete retire
            var c = document.getElementById("overlay-video");
            if (!c) {
                var d = document.createElement("div");
                d.setAttribute("id", "overlay-video");
                document.getElementById("overlay-wrapper").appendChild(d);
            }
                
            width = $(window).width();
            height = $(window).height();
            
            width_target = Math.round(width * 2/3);
            height_target = Math.round(width * 2/3 * video_scale);
            
            $('div.overlay').css('width', width_target);
            $('div.overlay').css('height', height_target);
            $('#overlay-video').css('width', width_target);
            $('#overlay-video').css('height', height_target);            
            
            if(height_target > height){
                height_target = Math.round( height * 2/3);
                width_target = Math.round(height * 2/3 * video_scale);
                $('div.overlay').css('width', width_target);
                $('div.overlay').css('height', height_target);
                $('#overlay-video').css('width', width_target);
                $('#overlay-video').css('height', height_target);
            }                
            // Run the javascript when the page is ready
            
                        
            player.load(); 

	},
		
        // when overlay is closed, unload our player
        onClose: function() {
            player.unload(); 
        }
	});

});

		





