
function onBefore() { 
    $('#output').html("Lire la suite..." + this.src); 
} 
function onAfter() { 
    $('#output').html("linux" + this.src) 
        .append('<h3>' + this.alt + '</h3>'); 
}

function unes() {

    $(function(){
        $('#une-body-container').cycle({ 
          fx:     'scrollLeft', 
          timeout: 25000,
          speed:   500,
          //delay: -2000,
          //before:  onBefore, 
          //after:   onAfter 
       });
    });
}

function unes_club() {

    $(function(){
        $('#body-news-blog ul').cycle({
            timeout: 10000,
            speedIn:  2000,
            speedOut: 500, 
            //easeIn:  'easeInCirc', 
            //easeOut: 'easeOutBounce', 
            delay:   -2000, 
        });
    });
}

function datas_rub() {

    $(function(){
        $('#bloc-articles-content').cycle({ 
          fx:     'scrollDown',
          easing: 'easeOutBounce', 
          delay:  -2000,  
          timeout: 30000,
          speed:   500,
          
          //delay: -2000,
          //before:  onBefore, 
          //after:   onAfter 
       });
    });
}
   
function tetieres() {

    $(function(){
    	$('#bloc-articles').delegate("h3", "click", function(e) {
              	
          		if(e.type == 'click')
          		{
                if( $('#bloc-articles-content').hasClass('hidden') )  {
                    $('div#bloc-articles-content').removeClass('hidden');
                } else {
                    $('div#bloc-articles-content').addClass('hidden');
                }
              }
        });
    });
}

function comments() {

    $(function(){
      $('div.comments-mod-button').delegate("span a", "click", function(e) {
               	
           		if(e.type == 'click')
           		{
                 //console.log( $(this).parent().parent().parent().children() );
                 if( $(this).parent().parent().parent().children('.form').hasClass('hidden') )  {
                     $(this).parent().parent().parent().children('.form').removeClass('hidden');
                 } else {
                     $(this).parent().parent().parent().children('.form').addClass('hidden');
                 }
               }
         });
    });
}


///////////////////////////////////////////////
// GLOBALE

function sleep(millis) {
    /*
    var notifier = new EventNotifier();
    setTimeout(notifier, millis);
    notifier.wait->();
    */
    d=new Date();
    diff=0;
    while(diff < millis)
    {
      n=new Date();
      diff=n-d;
    } 
    //setTimeout(function(){$('form tr.retour').fadeOut('slow');}, millis);
}

// GLOBALE
///////////////////////////////////////////////

///////////////////////////////////////////////
// FRESH PUB
function freshpub() {                  
	 var t = document.getElementById('pub-t-iframe');
	 var b = document.getElementById('pub-b-iframe');
	 var l0 = document.getElementById('pub-l0-iframe');

	 //t.refresh();
   	 
   if( document.getElementById('pub-t-iframe') ) 
     t.contentWindow.location.reload(true);
   if( document.getElementById('pub-b-iframe') )
     b.contentWindow.location.reload(true);
   if( document.getElementById('pub-l0-iframe') )
    l0.contentWindow.location.reload(true);
}
// FRESH PUB
///////////////////////////////////////////////

///////////////////////////////////////////////
// CACHE NUM LIGNE CODE
function hidenumbers(div) {
    if (!document.getElementsByTagName) return;
    var pre = document.getElementById(div);
    var spans = pre.getElementsByTagName('span');
    var i = 0;
    while (i < spans.length) {
       if (spans[i].className == 'numero-de-ligne') {
          spans[i].parentNode.removeChild(spans[i])
		  // pre.removeChild(spans[i]);
       } else {
          i++;
       }
    }
}
// CACHE NUM LIGNE CODE
///////////////////////////////////////////////


///////////////////////////////////////////////
// LOG : script > deconnexion
function dlog() { 
    var uri = window.location.href.split('/');
        
    $.ajax({   
          type: "POST",
          dataType: 'html',
          async: false,
          url: "/action.php",
          data: "module=usr&script=dlog",
          success: function() {
                        boxesRefresh();
                        if(uri[3] == 'club') {
                            $('#body-content-nav').load('/_tpl/zonarisk-v3/blocs/usr-onglets.tpl.php');
                            $('#body-content-corps').load('/_tpl/zonarisk-v3/main/usr.tpl.php');
                            $('#bloc-nav-club').addClass('hidden');
                        }
                  },
          error: function() {
                        console.log('Error DLogg');
                  }
         
      });

         
    return false;
}
// LOG : script > deconnexion
///////////////////////////////////////////////
///////////////////////////////////////////////   
// LOG : script > connexion

function sendLogin() {
    var uri = window.location.href.split('/');
    
    //alert(uri[3]);
    //alert('IN');
            
    $.ajax({   
          type: "POST",
          dataType: 'html',
          async: false,
          url: "/action.php",
          data: "module=usr&script=log&id3nt1f1ant="+$('#id3nt1f1ant').val()+"&m0t2pa553="+$('#m0t2pa553').val(),
          success: function() {
                        boxesRefresh();
                        if(uri[3] == 'club') {
                            $('#body-content-nav').load('/_tpl/zonarisk-v3/blocs/usr-onglets.tpl.php');
                            $('#body-content-corps').load('/_tpl/zonarisk-v3/main/usr.tpl.php');
                        }
                        unes();
                        
                  },
          error: function() {
                        console.log('Error Logg');
                  }
         
      });

    
    return false;
}

// LOG : script > connexion
///////////////////////////////////////////////

///////////////////////////////////////////////
// LOG : Template > blocks data user

function boxesRefresh() {
  
      $('#master-usr-infos').load('/_tpl/zonarisk-v3/blocs/master-usr-infos.tpl.php');
      $('#body-nav-content').load('/_tpl/zonarisk-v3/blocs/body-nav-content.tpl.php');
      $('#zonarisk-passwd-content').load('/_tpl/zonarisk-v3/blocs/zonarisk-passwd.content.tpl.php');

}

// LOG  : Template > blocks data user
///////////////////////////////////////////////

///////////////////////////////////////////////
// FORM : Scripts

function validation() {
    var query = document.location.search;
    query = query.substring(1);
    if(query) {
    
        //alert(query);
        div = '#content-body';
        script = 'module=usr&script=confirm';
         
        jQuery.ajax({   
              type: "POST",
              dataType: 'html',
              async: false,
              //url: "/_tpl/zonarisk-v3/main/usr.tpl.php",
              url: "/action.php",
              data: script+'&'+query,
              success: function(msg) {
                            $(div).show().html(msg);
                            //boxesRefresh();
                            //navig('usr'); smenu_active();
                            window.location.href='/club/';
                            //sleep(2000); jQuery('form tr.retour').fadeOut('slow');
                            //setTimeout(function(){ jQuery('form tr.retour').fadeOut('slow'); }, 1000);
    
                      },
              error: function() {
                            console.log('Error Logg');
                      }
             
          });
      
        
      }
}
function sendSondage(form) {

    type = jQuery('input[name$="form"]').val();
    //if(type == '') type = 'insc';
    dat = "module=sondages&script=vote";
    //tpl = "tpl="+type;
    
    div = 'div#sondage-content';
    //alert(type);        
    jQuery.ajax({   
          type: "POST",
          dataType: 'html',
          async: false,
          url: "/action.php",
          data: dat+'&'+jQuery(form).serialize(),
          success: function(msg) {
                        
                        $(div).show().html(msg);
                  },
          error: function() {
                        console.log('Error Logg');
                  }
         
      });

    
    return false;    
}
function sendFormForgot(form) {

    //type = jQuery('input[name$="form"]').val();
    //if(type == '') type = 'insc';
    dat = "module=usr&script=forgot";
    //tpl = "tpl="+type;
    
    div = 'div#body-content-corps';
    //alert(type);        
    jQuery.ajax({   
          type: "POST",
          dataType: 'html',
          async: false,
          //url: "/_tpl/zonarisk-v3/main/usr.tpl.php",
          url: "/action.php",
          data: dat+'&'+jQuery(form).serialize(),
          success: function(msg) {
                        
                        $(div).show().html(msg);
                  },
          error: function() {
                        console.log('Error Logg');
                  }
         
      });

    
    return false;    
}
function sendFormInsc(form) {

    //type = jQuery('input[name$="form"]').val();
    //if(type == '') type = 'insc';
    dat = "module=usr&script=insc";
    //tpl = "tpl="+type;
    
    div = 'div#body-content-corps';
    //alert(type);        
    jQuery.ajax({   
          type: "POST",
          dataType: 'html',
          async: false,
          //url: "/_tpl/zonarisk-v3/main/usr.tpl.php",
          url: "/action.php",
          data: dat+'&'+jQuery(form).serialize(),
          success: function(msg) {
                        
                        $(div).show().html(msg);
                  },
          error: function() {
                        console.log('Error Logg');
                  }
         
      });

    
    return false;    
}

function sendFormUsr(form) {

    type = jQuery('input[name$="form"]').val();
    if(type == '') type = 'insc';
    dat = "module=usr&script=mod&op="+type;
    tpl = "tpl="+type;
    
    div = 'div#body-content-corps';
    //alert(type);        
    jQuery.ajax({   
          type: "POST",
          dataType: 'html',
          async: false,
          //url: "/_tpl/zonarisk-v3/main/usr.tpl.php",
          url: "/action.php",
          data: dat+'&'+jQuery(form).serialize(),
          success: function(msg) {
                        
                        $(div).show().html(msg);
                  },
          error: function() {
                        console.log('Error Logg');
                  }
         
      });

    
    return false;    
}

function replaceN(string)
{
  return string = string.replace(/\n/g, "<br />" );  
}

 
function addFormComment(form) {

    //sc = jQuery('input[name$="sc"]').val();
    //dat = "sc="+sc;
    //id  = $('form input[name*="comment_id"]').val();
    div = '#bloc-comments-lst-content';
    
    jQuery.ajax({   
          type: "POST",
          dataType: 'html',
          async: false,
          //url: "/_tpl/zonarisk-v3/scripts/comment.script.php",
          url: "/action.php",
          data: "module=usr&script=comment&op=add&"+jQuery(form).serialize(),
          
          success: function(msg) {
                        //jQuery("div#bloc-comments-add-content form textarea").val('')
                        //jQuery( div ).append( msg );
                        //$('div#comment-form').html("Retour: "+msg);
                        window.location.reload(true);
                  },
          error: function() {
                        console.log('Error Logg');
                  }
         
      });


    return false;    
}

function delFormComment(cid) {

    id  = $('form input[name*="comment_id"]').val();
    div = '#comment-'+cid+'';
    //alert( jQuery(form) );
    jQuery.ajax({   
          type: "POST",
          dataType: 'html',
          async: false,
          url: "/action.php",
          data: "module=usr&script=comment&op=del&cid="+cid+"&"+jQuery('#comment-'+cid+' form').serialize(),
          
          success: function(msg) {
                        //jQuery( div ).html( msg );
                        jQuery( div ).remove();
                  },
          error: function() {
                        console.log('Error Logg');
                  }
         
      });


    return false;    
}
function modFormComment(form) {

    id  = form.comment_id.value;
    div = '#comment-'+id+' div.here';
    close = '#bloc-comments-mod-content-'+id;

    jQuery.ajax({   
          type: "POST",
          dataType: 'html',
          async: false,
          url: "/action.php",
          data: "module=usr&script=comment&op=mod&"+jQuery(form).serialize(),
          
          success: function(msg) {
                        jQuery(div).html( msg );
                        jQuery(close).addClass('hidden');
                        
                  },
          error: function() {
                        console.log('Error Logg');
                  }
         
      });


    return false;    
}
// FORM : Scripts
///////////////////////////////////////////////

///////////////////////////////////////////////
// Pour les like

function like() {
$(function(){
	$('ul.action li.action-like').delegate("a.like", "click hover mousedown mouseup", function(e) {
           	
       		if(e.type == 'mousedown')  //  press
      		{
      			//$(this).removeClass('hover');
      			$(this).removeClass('like');
      			$(this).addClass('unlike');
      		}

      		if(e.type == 'click')
      		{
        	  //rel = $(this).parent().parent().parent().parent().parent().attr('id');
        	  rel = $(this).parent().parent().attr('id');
        	  chaine = rel.split('-');
            //taille = rel.length; 
            //id = rel.substring(5, taille);
            mod_id = chaine[1];
            id = chaine[2];
            div = $(this).parent(); 
          	
        	  //tpl = '/_tpl/zonarisk/main/usr.tpl.php';
        	  //tpl = '/action/usr/unlike/';
            tpl = '/action.php';

                  $.ajax({   
                            type: "POST",
                            dataType: 'html',
                            async: false,
                            url: tpl,
                            data: "module=usr&script=unlike&mod_id="+mod_id+"&id="+id, 
                            success: function(msg){
                                          $(div).show('slow').html(msg);
                                    },
                            error: function(msg){
                                          $(div).slideDown('slow').html("Data Error: "+msg);
                                    }
                        });
                      
            		  //$(div).load(tpl);
      	  //});
      	return false;  
        }
      		
    });
    

});
}
function unlike() {
// Pour les unlike
$(function(){
	$('ul.action li.action-like').delegate("a.unlike", "click hover mousedown mouseup", function(e) {
   
      		if(e.type == 'mouseover') // dessus
      		{
      		  //$(this).addClass('hover');
      		}
      		else if(e.type == 'mouseout')  // quite
      		{
      			//$(this).removeClass('hover');
      		}
      		else if(e.type == 'mousedown')  //  press
      		{
      			//$(this).removeClass('hover');
      			$(this).removeClass('unlike');
      			$(this).addClass('like');
      		}
      		else if(e.type == 'mouseup')  // relache
      		{
      			//$(this).parent().removeClass('like');
      		}
      		if(e.type == 'click')
      		{
        	  //rel = $(this).parent().parent().parent().parent().parent().attr('id');
        	  rel = $(this).parent().parent().attr('id');
        	  chaine = rel.split('-');
            //taille = rel.length; 
            //id = rel.substring(5, taille);
            mod_id = chaine[1];
            id = chaine[2];
            div = $(this).parent(); 
          	
        	  //tpl = '/_tpl/zonarisk/main/usr.tpl.php';
        	  //tpl = '/action/usr/unlike/';
            tpl = '/action.php';
	          
                  $.ajax({   
                            type: "POST",
                            dataType: 'html',
                            async: false,
                            url: tpl,
                            data: "module=usr&script=like&mod_id="+mod_id+"&id="+id, 
                            success: function(msg){
                                          $(div).show('slow').html(msg);
                                    },
                            error: function(msg){
                                          $(div).slideDown('slow').html("Data Error: "+msg);
                                    }
                        });
            		  //$(div).load(tpl);
      	  //});
      	return false;  
        }
      		
    });
    

});
}
// Pour les like/unlike
///////////////////////////////////////////////


function smenu_active() {

    $(function(){
    	$('#smenu ul').delegate("li a", "click hover mousedown mouseup", function(e) {
    
      	   
          		if(e.type == 'mouseover') // dessus
          		{
          		  $(this).addClass('hover');
          		}
          		else if(e.type == 'mouseout')  // quite
          		{
          			$('#smenu ul li a').removeClass('hover');
          		}
          		else if(e.type == 'mousedown')  //  press
          		{
          			$('#smenu ul .hover').removeClass('hover');
          			$('#smenu ul .active').removeClass('active');
          		}
          		else if(e.type == 'mouseup')  // relache
          		{
          			$(this).addClass('active');
          		
          		}
          		if(e.type == 'click')
          		{
    
            	  clas = $(this).attr('class');
            	  clas_array = clas.split(' ');
            	  rel = clas_array[2];
            	  div = '#body-content-corps';
            	  tpl = '/_tpl/zonarisk-v3/main/usr.tpl.php';
                        	
            	  //$(div).slideUp('slow', function() {
    	  
                      $.ajax({   
                                type: "GET",
                                dataType: 'html',
                                async: false,
                                url: tpl,
                                data: "tpl="+rel, 
                                success: function(msg){
                                              //$(div).slideDown('slow').html(msg);
                                              $(div).show('slow').html(msg);
                                              document.location = "#"+rel;
                                              //return false;
                                        },
                                error: function(msg){
                                              $(div).slideDown('slow').html("Data Error: "+msg);
                                        }
                            });
                          
                		  //$(div).load(tpl);
          	  //});
          	   return false;  
            }
          		
        });
        
       
    });

}

function images() {

    $(function(){
        $('#rien-a-voir-content-data').cycle({ 
            fx:     'fade',
            timeout: 12500,
            speed:   3000,
       });
    });
}



function pagination() {

    $(function(){
        $('#items-pagination').delegate("div.bulle_corps", "click hover mousedown mouseup mouseout mouseover", function(e) {
      	   
            if(e.type == 'mouseover') // dessus
            {
                $(this).addClass('hover');
            }
            else if(e.type == 'mouseout')  // quite
            {
                $(this).removeClass('hover');
            }
            else if(e.type == 'mousedown')  //  press
            {
                $(this).addClass('hover');
            }
            else if(e.type == 'mouseup')  // relache
            {
                $(this).removeClass('hover');
            }
            else if(e.type == 'click')
            {
                tree_indice = $(this).children('span').attr('class'); 
                //alert(tree_indice);            
                
                tree_array = tree_indice.split('-');
                tree_id = tree_array[1];
                //alert(tree_id);
                num_content = $(this).parent().parent().parent().children('#items-lst');
                num_indice = num_content.children('hr').attr('class');
                //num_autres = num_content.find('hr').end();
                //alert(num_indice);
                num_array = num_indice.split('-');
                num_pag = num_array[2];
                //alert(num_pag);
                num = parseInt(num_pag) + parseInt(1);
                //alert(num);
                //hr  = '#hr-'+num_pag;
                hr  = 'hr.hr-pag';
                div = '#items-lst';
                tpl = '/_tpl/zonarisk-v3/main/items.tmp-lst.tpl.php';
                        	
                //$(div).slideUp('slow', function() {
                
                $.ajax({   
                          type: "POST",
                          dataType: 'html',
                          async: false,
                          url: tpl,
                          data: "tree_id="+tree_id+"&pag="+num,
                          beforeSend: function(){ $('#items-pagination div.bulle div.bulle_corps').addClass('load hover'); },
                          complete : function(){ $('#items-pagination div.bulle div.bulle_corps').removeClass('load hover'); },
                          success: function(msg){
                                        $(div).show('slow').append(msg);
                                        $(hr).removeClass('pag-'+num_pag); $(hr).addClass('pag-'+num);
                                        like(); unlike();
                                  },
                          error: function(msg){
                                        $(div).slideDown('slow').html("Data Error: "+msg);
                                  }
                      });
                  
                	  //$(div).load(tpl);
                //});
                return false;  
            }
          		
        });
       
    });

}


function rien_a_voir() {

    $(function(){
    	$('#rien-a-voir-content-data').delegate("li", "click", function(e) {
              	
          		if(e.type == 'click')
          		{
                  window.open( $(this).children('a').attr('href') );
                  
              }
              return false;
        });
    });
}

function juste_debout_steez() {

    $(function(){
        $('#rien-a-voir-content-data').cycle({ 
            fx:     'fade',
            timeout: 12500,
            speed:   3000,
       });
    });
    $(function(){
    	$('#juste-debout-steez-content-data').delegate("li", "click", function(e) {
              	
          		if(e.type == 'click')
          		{
                  //console.log( $(this).parent().parent().parent().children('h3').children('a').attr('href') );
                  window.open( $(this).parent().parent().parent().children('h3').children('a').attr('href') );

                  
              }
              return false;
        }).cycle({ 
            fx:     'fade',
            timeout: 5000,
            speed:   5000,
       });
    });
}

/*    
function tetiere_onglets() {

    $(function(){
    	$('#body-content-nav').delegate("li a", "click", function(e) {
              
              var ancre = $(this).attr('href');
              ancre = ancre.substring(1);
              //alert(ancre);	
              
              
          		if(e.type == 'click')
          		{
                if( $('#body-content-corps div.'+ancre).hasClass('hidden') )  {
                    $('#body-content-corps div.'+ancre).removeClass('hidden');
                } else {
                    $('#body-content-corps div.'+ancre).addClass('hidden');
                }
              }
        });
    });
}
*/  

function PromptTS() {
    var nick = prompt("Votre pseudonyme :", "Rentrez un pseudonyme ici");
    if (nick!=null) {
        window.open('ts3server://ts.zonarisk.net?port=9987&nickname='+nick);
    }
}


$(document).ready(function(){

      var ancre = window.location.hash
      if(window.location.hash) {
            var ancre = window.location.hash;
            ancre = ancre.substring(1);
            //alert(ancre);
            
            if(ancre == "TSconnect") {
            
                var nick = prompt("Connexion ZoNaRisK TeamSpeak 3\n\nVotre pseudonyme :", "Rentrez un pseudonyme ici");
                if (nick!=null) {
                    document.location.href="ts3server://ts.zonarisk.net?port=9987&nickname="+nick;
                    //window.open('ts3server://ts.zonarisk.net?port=9987&nickname='+nick);
                }
    
            }
      }
      
      
      
    $(function(){
    	$('ul#body-content-nav.nav').delegate("li a", "click", function(e) {
              
              var ancre = $(this).attr('href');
              ancre = ancre.substring(1);
              
          		if(e.type == 'click')
          		{

                //if( $(this).hasClass('active') ) {
                if( $(this).hasClass('active') )  {
                
   
                
                } else {
                    //console.log( $(this).parent().parent().children() );
                    $(this).parent().parent().children().children().removeClass('active');

                    $(this).addClass('active');
                    
                    $('#body-content-corps div.item').addClass('hidden');
                    $('#body-content-corps div.item.'+ancre).removeClass('hidden');                   

                }
                return false;
              }
        });
    });  
    
          

});





