 jQuery( function()
         {
           $("a#lightbox_close").hide();
           
           $("ul#menu.navTop li")
           .mouseover( function()
                       {
                        if( $.browser.msie )
                        {
                         clearTimeout( $(this).data( "timeout" ) );
                         $(this).children( ".sub-nav, .sub-sub-nav" )
                                .stop()
                                .show();
                        }
                        else
                        {
                         $(this).children( ".sub-nav, .sub-sub-nav" )
                                .stop()
                                .show()
                                .animate( { opacity: 1 }, "fast" );
                        }
                       } )
           .mouseout( function()
                      {
                       if( $.browser.msie )
                       {
                        var _this = $(this);
                                
                        $(this).data( "timeout", 
                                      setTimeout( function()
                                                  {
                                                   _this.children( ".sub-nav, .sub-sub-nav" )
                                                        .stop()
                                                        .hide();
                                                  }, 200 ) );
                       }
                       else
                       {
                        $(this).children( ".sub-nav, .sub-sub-nav" )
                                .stop()
                                .animate( { opacity: 0 },
                                          "fast",
                                          function()
                                          {
                                           $(this).hide();
                                          } );
                       }
                      } );
           
            // Resize background             
            var heightLastElem;
            var offsetTopLastElem;
            var heightBackground;
           
            
            $(window).bind( 'resize', function()
            {
             heightLastElem = parseInt( $( "#mainContainer" ).children( ":last" ).outerHeight() );
             offsetTopLastElem = parseInt( $( "#mainContainer" ).children( ":last" ).offset().top );
             heightBackground = heightLastElem + offsetTopLastElem;
            
             if( heightBackground < $(window).height() )
             {
              $("#mainContainer").css( "height", $(window).height() );
             }
             else
              $("#mainContainer").css( "height", heightBackground );
            } );
           
            $(window).trigger( 'resize' );
          
            var version = getFlashVersion().split(',').shift();
            if(version < 9)
            {
             $('#swf').height('197px');
             $('#swf').html("<center><a href='http://get.adobe.com/fr/flashplayer/' target='_blank'><img src='/templates/abalone-interim/imgs/readability/get_flash_player.jpg' style='border:0;height:197px' alt='Installer la nouvelle version de Flash Player'/></href></center>");
             $('#myUpload').height('250px');
             $('#fileListSpan').html('<br/>Après installation du plugin veuillez actualiser la page pour appliquer les modifications.');
             $('#fileList_global').html('');
             $('a.upload').remove();
             $('#fileInputUploader').html("<center><a href='http://get.adobe.com/fr/flashplayer/' target='_blank'><img src='/templates/abalone-interim/imgs/readability/get_flash_player.jpg' style='border:0;height:197px' alt='Installer la nouvelle version de Flash Player'/></href></center>");
            }
            
            // Active link menu
            if( $("ul#menu").length > 0 )
            {
             $.each( $( "ul#menu li a:first-child" ), function( i, elem )
                                                      {
                                                       if( !$(this).parent( "li" ).parent( "ul" ).hasClass( "sub-nav" )
                                                        && !$(this).parent( "li" ).parent( "ul" ).hasClass( "sub-sub-nav" )
                                                        && $(this).attr( "href" ) == undefined )
                                                        { 
                                                         if( $(this).parent( "li" ).children( "ul.sub-nav" ).children( "li:first" ).children( "a").attr( "href" ) != undefined )
                                                          $( this ).attr( "href", $(this).parent( "li" )
                                                                                         .children( "ul.sub-nav" )
                                                                                         .children( "li:first" )
                                                                                         .children( "a" ).attr( "href" ) );
                                                        }
                                                      } );
            }
            
            // Active first link path
            if( $( "div#mainContent table#path td.firstCell a:first" ).length > 0 )
            {
             if( $( "ul#menu li.selected" ).length > 0 )
              $( "div#mainContent table#path td.firstCell a:first" ).attr( "href", $( "ul#menu li.selected a:first" ).attr( "href" ) );
             else // Annexes
               $( "div#mainContent table#path td.firstCell a:first" ).attr( "href", $( "div#leftMenu div#mainSpaceMenu a:first" ).attr( "href" ) );
            }
            
         } );



 /* Display help for better readability */
 function readability()
 {
  var version = 0;
  
  var isFound =  true;
  
  if( navigator.userAgent.indexOf("Firefox") != -1 )
  {
   var versionindex=navigator.userAgent.indexOf( "Firefox" )+8;
   if( parseInt( navigator.userAgent.charAt( versionindex ) ) >= 1 )
    ViGiSITE.core.prompt( "<center>Le navigateur Mozilla Firefox dispose d'un menu permettant de modifier la taille du contenu des sites visit&eacute;s.<br/> Pour cela, il vous suffit d'aller dans le menu  \"Affichage\" de votre navigateur, puis dans \"Zoom\" et s&eacute;lectionnez l'option d&eacute;sir&eacute;e. <br/><br/><img src='/templates/abalone-interim/imgs/readability/readabilityFirefox.jpg' alt='Illustration de l\'amélioration de la lisibilité' /></center>", { "": { className: "little", default_button: true } }, null, 'promptReadability' );
  }
  else if( navigator.appVersion.indexOf( "MSIE" ) != -1 )
  {
   var temp = navigator.appVersion.split( "MSIE" );
   version = parseFloat(temp[1]);
   if( version == 7 )
   {
     ViGiSITE.core.prompt( "<center>Le navigateur Internet Explorer 7 dispose d'un menu permettant de modifier la taille du contenu des sites visit&eacute;s.<br/> Pour cela, il vous suffit d'aller dans le menu  \"Affichage\" de votre navigateur, puis dans \"zoom\" ou \"Taille du texte\" et s&eacute;lectionnez l'option d&eacute;sir&eacute;e. <br/><br/><img src='/templates/abalone-interim/imgs/readability/readabilityIE7.jpg' alt='Illustration de l\'amélioration de la lisibilité' /></center>", { "": { className: "little", default_button: true } }, null, 'promptReadability' );
   }
   else if( version == 8 )
   {
    ViGiSITE.core.prompt( "<center>Le navigateur Internet Explorer 8 dispose d'un menu permettant de modifier la taille du contenu des sites visit&eacute;s.<br/> Pour cela, il vous suffit d'aller dans le menu  \"Affichage\" de votre navigateur (F10 si celui si n\'est pas affiché), puis dans \"Zoom\" ou \"Taille du texte\" et s&eacute;lectionnez l'option d&eacute;sir&eacute;e. <br/><br/><img src='/templates/abalone-interim/imgs/readability/readabilityIE8.jpg' style='width:522px' alt='Illustration de l\'amélioration de la lisibilité' /></center>", { "": { className: "little", default_button: true } }, null, 'promptReadability' );
   }
   else
   {
    ViGiSITE.core.prompt( "Aucune aide sur la lisibilité n'est disponible pour votre version de navigateur", { "": { className: "little", default_button: true } } );
    isFound=false;
   }
  }
  else
  {
   ViGiSITE.core.prompt( "Aucune aide sur la lisibilité n'est disponible pour votre version de navigateur", { "": { className: "little", default_button: true } } );
   isFound=false;
  }
  
  if( isFound )
  {
   $('div.promptReadability p.content').width('690px');
   $('div.promptReadability p.content').height('440px');
   // $('div.promptReadability div.buttons').css( 'position', 'absolute' );
   // $('div.promptReadability div.buttons').css( 'right', '50%' );
  }
 }
 
 
 function getFlashVersion()
 {
   // ie
   try {
     try 
     {
       // avoid fp6 minor version lookup issues
       // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
       var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
       try { axo.AllowScriptAccess = 'always'; }
       catch(e) { return '6,0,0'; }
     } 
     catch(e) 
     {}
     return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
   // other browsers
   } 
   catch(e)
   {
     try 
     {
       if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)
       {
         return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
       }
     } 
     catch(e) 
     {}
   }
   return '0,0,0';
 }
 
 
 function init_music( autostart )
 {
  var flashvars = { 
   mp3:"/music/piste1.mp3|/music/piste2.mp3|/music/piste6.mp3", 
   fading:3, 
   javascript:'on', 
   autostart: autostart, 
   autoreplay:1 
  };
   
  var params = { wmode: "transparent" };
  swfobject.embedSWF( "/system/packages/flash-dewplayer/dewplayer.swf", "musicPlayer", "240", "20", "9.0.0", {visibility:"visible"}, flashvars, params);
 
   if( autostart === true )
   {
    $("#musicPlayerStart").removeClass("enabled");
    $("#musicPlayerPause").addClass("enabled");
    $("#musicPlayerStop").addClass("enabled");
   }
   
   $("#musicPlayerStart").click(function(){
    if( $(this).hasClass("enabled") )
    {
     $(this).removeClass("enabled");
     $("#musicPlayerPause").addClass("enabled");
     $("#musicPlayerStop").addClass("enabled");
     $("#musicPlayer").get(0).dewplay();
     $.cookie("autostart", "true");
    }
   });
   
   $("#musicPlayerPause").click(function(){
    if( $(this).hasClass("enabled") )
    {
     $("#musicPlayerStart").addClass("enabled");
     $("#musicPlayerPause").removeClass("enabled");
     $("#musicPlayer").get(0).dewpause();
    }
   });
   
   $("#musicPlayerStop").click(function(){
    if( $(this).hasClass("enabled") )
    {
     $("#musicPlayerStart").addClass("enabled");
     $("#musicPlayerPause").removeClass("enabled");
     $("#musicPlayerStop").removeClass("enabled");
     $("#musicPlayer").get(0).dewstop();
     $.cookie("autostart", "false");
    }
   });
   
   $("#musicPlayerPrevious").click(function(){
     $("#musicPlayerStart").removeClass("enabled");
     $("#musicPlayerPause").addClass("enabled");
     $("#musicPlayerStop").addClass("enabled");
     $("#musicPlayer").get(0).dewprev();
     $.cookie("autostart", "true");
   });
   
   $("#musicPlayerNext").click(function(){
     $("#musicPlayerStart").removeClass("enabled");
     $("#musicPlayerPause").addClass("enabled");
     $("#musicPlayerStop").addClass("enabled");
     $("#musicPlayer").get(0).dewnext();
     $.cookie("autostart", "true");
   });
 }
