(function() {
       function charge_diapo() {  
          onAvailable('diaporama_new_Carrelage', function(){
              getScript('js/jcarousellite.js',function(){
              			if (document.getElementById("actualites")!=null) { $(function() { $(".newsgauche").jCarouselLite({vertical:true,visible:3,auto:5000,speed:1000,hoverPause:true});}); };
                    $(function() { $(".slideshow_Carousel").jCarouselLite({vertical:true,visible:3,auto:10000,speed:500,hoverPause:true});});
              		  });
              		});
          onAvailable('diaporama_new', function(){
              getScript('js/jcarousellite.js',function(){
                    $(function() { $(".slideshow").jCarouselLite({vertical:true,visible:1,auto:6000,speed:0,hoverPause:true});});
              		  });
              		});
          
          };  

      //remplissage du Body apres chargement de la page
          function init() {
              if (document.getElementById("footer_google")!=null) 
                    {document.getElementById("footer_google").innerHTML='<g:plusone size="medium"></g:plusone>';}
                    else
                    {console.log("pas de footer google");};
              if (document.getElementById("plusone_google")!=null) 
                    {document.getElementById("plusone_google").innerHTML='<g:plusone size="medium"></g:plusone>';};      
              if (document.getElementById("footer_facebook_send")!=null) 
                        {document.getElementById("footer_facebook_send").innerHTML='<div id="fb-root"></div><fb:send href='+window.location.hostname+window.location.pathname+' font=""></fb:send>';}
                        else
                        {console.log("pas de footer facebook send");};
              if (document.getElementById("footer_facebook_like")!=null) 
                        {document.getElementById("footer_facebook_like").innerHTML='<fb:like href="http://www.facebook.com/carrelage" send="false" layout="button_count" width="450" show_faces="false" font="tahoma"></fb:like>';};
              if (document.getElementById("facebook-actu")!=null)
                        {document.getElementById("facebook-actu").innerHTML='<p class="facebook-actu"><fb:like-box href="http://www.facebook.com/carrelage" width="292" show_faces="false" stream="false" header="false"></fb:like-box></p>';};
              charge_diapo();          
           };
    //onavailable
                  var stack = [],
                  interval,
                  loaded; // has window.onload fired?
              function doPoll() {
                var notFound = [];
                for (var i=0; i<stack.length; i++) {
                  if ((document.getElementById(stack[i].id))&&(document.readyState === "complete" )) {
                    stack[i].callback();
                  } else {
                    notFound.push(stack[i]);
                  }
                }
                stack = notFound;
                if (notFound.length < 1 || loaded) {
                  stopPolling();
                }
              }
              
              function startPolling() {
                if (interval) {return;}
                interval = setInterval(doPoll, 10);
              }
              
              function stopPolling() {
                if (!interval) {return;}
                clearInterval(interval);
                interval = null;
              }
              
              function onAvailable(id, callback) {
                stack.push({id:id, callback:callback});  
                startPolling();
              }
              
              window.onload = function() {
                loaded = true;
                init(); 
                doPoll();
              };

           //Chargement asynchrone du Javascript
      function getScript(url,success){
        var script=document.createElement('script');
        script.src=url;
        script.async = true;
        script.type = 'text/javascript';
        script.charset="utf-8";
        var head=document.getElementsByTagName('head')[0];
        var done=false;
        if (url=='https://apis.google.com/js/plusone.js') {script.innerHTML = "{lang: 'fr'}";};
        script.onload=script.onreadystatechange = function(){
          if ( !done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete') ) {
            done=true;
            if (success != null) success();
            script.onload = script.onreadystatechange = null;
            head.removeChild(script);
          }; 
        };
        head.appendChild(script);
      };
      
       function chargement_asynchrone(url) {
            function async_load(){
                var s = document.createElement('script');
                s.type = 'text/javascript';
                s.async = true;
                s.src = url;
                if (url=='https://apis.google.com/js/plusone.js') {s.innerHTML = "{lang: 'fr'}";};
                var x = document.getElementsByTagName('script')[0];
                x.parentNode.insertBefore(s, x);
            };
            if(document.readyState === "complete" ) 
              async_load;
            else if (window.attachEvent)
                window.attachEvent('onload', async_load);
            else if (window.addEventListener) 
                window.addEventListener('load', async_load, false);
        };
              
       
       getScript('js/jquery.js',function(){
          // Le code ci-dessous sera execute après que JQuery soit charge
          
          chargement_asynchrone('http://connect.facebook.net/fr_FR/all.js#xfbml=1');
           getScript('http://connect.facebook.net/fr_FR/all.js#xfbml=1',function(){
                FB.Event.subscribe('edge.create', function(targetUrl) {
                  _gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]);
                });
                FB.Event.subscribe('edge.remove', function(targetUrl) {
                  _gaq.push(['_trackSocial', 'facebook', 'unlike', targetUrl]);
                });
                FB.Event.subscribe('message.send', function(targetUrl) {
                  _gaq.push(['_trackSocial', 'facebook', 'send', targetUrl]);
                });
                });          
          chargement_asynchrone('https://apis.google.com/js/plusone.js');
          
            
          if (typeof hoverscroll != 'undefined')
            {
              if ( hoverscroll=="debut" ) { getScript('js/hoverscroll.js'); $(document).ready(function() { $('#sous-menu-a-scroller').hoverscroll({fixedArrows: false,width:536,rtl: false});});}
              else if (hoverscroll=="avance-rapide") {getScript('js/hoverscroll.js'); $(document).ready(function() { $('#sous-menu-a-scroller').hoverscroll({fixedArrows: false,width:536,rtl: false});var direction = 1,speed = 16; $("#sous-menu-a-scroller")[0].startMoving(direction, speed);});};
            };
        
      });          
    })();
