ViGiSITE.videoPlayer =
 function( params )
 {
  params = $.extend( {}, ViGiSITE.videoPlayer.defaultParameters, params );
  
  ViGiSITE.core.lightbox( {
   'defaultContent': ' <div id="lightbox_video_container"><div id="lightbox_video"></div></div>',
   'resizeEvent': function( lightbox, newSize )
    {
     var playerContainer = lightbox.children( "div#lightbox_video_container" );
     var player = playerContainer.children( "object#lightbox_video" );

     var naturalWidth = parseInt( player.attr( "naturalWidth" ) );
     var naturalHeight = parseInt( player.attr( "naturalHeight" ) );
     
     var tmpNewSize = ViGiSITE.core.calculSizeOfImage( newSize.width, newSize.height, naturalWidth, naturalHeight );
     
     if( tmpNewSize.width > naturalWidth || tmpNewSize.height > naturalHeight )
     {
      tmpNewSize.width = naturalWidth;
      tmpNewSize.height = naturalHeight;
     }

     
     newSize.width = tmpNewSize.width + ( lightbox.outerWidth() -  player.outerWidth() );
     newSize.height = tmpNewSize.height + ( lightbox.outerHeight() -  player.outerHeight() );
     
     // newSize.width = tmpNewSize.width + ( lightbox.outerWidth() -  params.width );
     // newSize.height = tmpNewSize.height + ( lightbox.outerHeight() -  params.height );
     
     player.css( "visibility", "hidden" );

     // Mozilla hack, jQuery animate reload the flash object.
     // Issue last checked on 2010-01-11, Firefox 3.5.1
     if( $.browser.mozilla == true && player.data( "videoPlayer.initialized" ) == true )
     {
      playerContainer.css(
      {
       "width": tmpNewSize.width,
       "height": tmpNewSize.height
      } );
      
      player.attr(
      {
       "width": tmpNewSize.width,
       "height": tmpNewSize.height
      } );
      
      player.css( "visibility", "visible" );
     }
     else
     {
      playerContainer.animate(
       {
        "width": tmpNewSize.width,
        "height": tmpNewSize.height
       }, function()
       {
        player.css( "visibility", "visible" );
        player.attr(
        {
         "width": tmpNewSize.width,
         "height": tmpNewSize.height
        } );
       } );
      }
      
     if( player.data( "videoPlayer.initialized" ) == false )
      player.data( "videoPlayer.initialized", true );
    },
   'loadEvent': function( lightbox )
    {
      swfobject.embedSWF( "/system/packages/flash-jw-flv-player/player-viral.swf", 
                        "lightbox_video", 
                        "100%", 
                        "100%",
                        "9.0.0", 
                        "/flashs/expressInstall.swf", 
                        {
                         "file": params.file,
                         "image": params.preview,
                         "playlist": params.playlist,
                         "backcolor": params.backcolor,
                         "frontcolor": params.frontcolor,
                         "lightcolor": params.lightcolor,
                         "autostart": params.autostart,
                         "playerready": params.playerready,
                         "repeat": params.repeat
                        },
                        {
                         "allowscriptaccess": "always",
                         "allowfullscreen": "true",
                         "wmode": "transparent",
                         "menu": "false"
                        },
                        {
                         "id": "lightbox_video",
                         "name": "lightbox_video",
                         "naturalWidth": params.width,
                         "naturalHeight": params.height
                        } );
      // $("#lightbox_video").addEventListener(MediaEvent.JWPLAYER_MEDIA_VOLUME, test);
      $("#lightbox_video").css( "visibility", "hidden" ).data( "videoPlayer.initialized", false );
      $(window).trigger( 'resize.lightbox' );
    }
  } );
 };
 
ViGiSITE.videoPlayer.defaultParameters =
 {
  "config": undefined,
  "preview": undefined,
  "file": undefined,
  "autostart": "false",
  "repeat": "false",
  "playlist": 'none',
  "backcolor": 'black',
  "frontcolor": 'white',
  "lightcolor": '#c0c0c0',
  "playerready": undefined,
  "width": 400,
  "height": 280
 };
