$(document).ready( function () {
    
    $("a").click(function() {
         var id = $(this).parents("div:first").attr("id"); 
         var module= $(this).attr('name');
         var page= $(this).attr('href'); 

         if(id=='searchForm') {
             var page = page+'?type=videosList&search='+($("input[name='search']").val());
         }

                                                                                                                     
         if(id =='headnav' || id=='headmenu' || id=='footer-left' || id=='footer-right' || id=='param' || id=='searchForm' || page.indexOf("type=videosDetail") != -1 || page.indexOf("goto=1") != -1 ) {
             
                 /* on active la class de l'item sur lequel on clic dans le menu */    
                 if(id =='headnav') {
                    $('#headnav a').removeClass("active");
                    $(this).addClass("active"); 
                 } else {
                     if(id != 'param' && page.indexOf("goto=1") == -1) {
                        $('#headnav a').removeClass("active");
                        if(page=='home.html') {
                             $('#headnav a:first').addClass("active");
                        }} 
                 }
         
         
            
             goTo(module, page); // On charge le contenu
             return false; // on emepeche le navvigateur de suivre le lien
         }
         
         return false;
         
    });
    
        
    
$('a').live('click', function() {
         var id = $(this).parents("div:first").attr("id"); 
         var module= $(this).attr('name');
         var page= $(this).attr('href');
 
     if(page == 'drapeau.html' || page == 'download.html' || page == 'galerie.html') {
         
     }   else {
        goTo(module, page); // On charge le contenu         
     }
   
      return false; // on emepeche le navvigateur de suivre le lien
});
    
   
function goTo(module, page) {
                         
        var patt1=/\?/gi;
        if(page.match(patt1)== null) {
            var interog='?';
        } else {
            var interog = '';
        }
        
        
        var uri = page+interog+'&module='+module;         
            
        $('#ajax').fadeOut('slow', function() {
        
        var html = $.ajax({
                url: uri,
                async: false
                }).responseText;
                
                
     
                
        if(page.indexOf("goto=1&") == -1 || page.indexOf("tp=1&") != -1) {
            $('#sidebar').fadeOut('slow'); 
            
            if(page.indexOf("type=photosList") == -1) {
               var tp='videos'; 
            } else {
               var tp='photos';  
            }
            var menuUri = 'menu.html?type=menuContent&module='+module+'&tp='+tp;

            var menu = $.ajax({
                    url: menuUri,
                    async: false
                    }).responseText;
                            
            $("#sidebar").html(menu); 
            $('#sidebar').fadeIn('slow');
        }                 
                
                
                        
        $("#ajax").html(html);
        $('#ajax').fadeIn('slow');       
         

        });            
    } 
      
});
