/**
 * jquery.profil_pro.js
 * http://www.annecy.org
 * Copyright (c) 2009 CITIA
 * dependance : - jquery.timer.js
  
 */

( function( $ )
{
  $.fn.profil_pro = function( params )
  {
    // Paramètres
    var options = $.extend({
                    id_div_res: "result_rech",
                    type : "pro"
                  },params);

    var _this = this;      
    /**
     * build : initialisation
     */ 
    function build() 
    {
      init_affichage();
    }
    /**
     * init_affichage : survol
     *
     */ 
    function init_affichage()
    {
      $( _this ).each( function()
      {
        var obj_lien = this;
        //var id_blc = $(obj_lien).next(".blc_aff_pro").attr("id");
        var id_blc = "blc_pro";
        if( $( "#" + id_blc ).length == 0 )
        {
          $( 'body #content' ).append( '<div id="blc_pro" class="blc_aff_pro"></div>' );
        }
        var href = $( this ).attr( "href" );
        var reg  = new RegExp( "[:]+", "g" );
        tab_href = href.split( reg );
        if( tab_href.length == 2 )
          var pers_id = tab_href[1];
        else
          var pers_id = tab_href[2];
        $( "#" + id_blc ).data( "id_blc", id_blc );
        $( "#" + id_blc ).data( "hover_actif", false );
        $( "#" + id_blc ).data( "survol_lien", false );
        $( "#" + id_blc ).data( "survol_blc", false );
        $( this ).parent().hover( function( e )
        {
          $( "#" + id_blc ).oneTime( 250, "aff", function() {
            $( "#" + id_blc ).data( "survol_lien", true );
            montrer( id_blc, pers_id, obj_lien );
          } );
        },
        function()
        {
          if( $( "#" + id_blc ).data( "survol_lien" ) )
          {
            $( "#" + id_blc ).data( "survol_lien", false );
            $( "#" + id_blc ).oneTime( 400, "msk", function() {
              masquer( id_blc );
            } );
          }
          else
            $( "#" + id_blc ).stopTime( "aff" );
        /*
          $( "#" + id_blc ).data( "survol_lien", false );
          $( "#" + id_blc ).oneTime( 500, "msk", function() {
            masquer( id_blc );
          } );
        */
        } );
      } );
    }
    /**
     * montrer : le bloc profil
     *
     */ 
    function montrer( id_blc, pers_id, obj_lien )
    {
      /*
      var href = $( "#" + id_blc ).prev().attr( "href" );
      var reg  = new RegExp( "[:]+", "g" );
      tab_href = href.split( reg );
      if( tab_href.length == 2 )
        var ordre = tab_href[1];
      else
        var ordre = tab_href[2];
      */
      //$( "#sortie_log" ).prepend( "<br><br>" + tab_href.length + " || tab_href[0] > " + tab_href[0] + " > tab_href[1]> " + tab_href[1] );
      var param = 'param={ "fct": "participants_info_personne", "param" : ["' + pers_id + '"] }';
      $.ajax( {
        type: "GET",
        url: "/ctrl_network.php",
        dataType: 'json',
        data: param,
        error: function( a, b, c ) {
        },
        success: function( data_json )
        {
          switch( data_json.etat )
          {
            case true:
              $( "#" + id_blc ).html( data_json.code_html )
              .fadeIn( "fast" )
              .css( { top: ( $( obj_lien ).position().top )- 150 , left: ( $( obj_lien ).position().left ) } );
              jQuery( "#" + id_blc ).contacts({
                action: "ajout",
                class_affichage: "tags_contacts",
                btn_ajout: "a.ajout_contact:first"
              });
            break;
            case false:
              if( data_json.type == "session" )
              {
                $.nyroModalManual( { modal: true, content: data_json.code_html } );
                init_form_connexion_ajx();
              }
            break;
          }
        }
      } );
      // Survol du bloc
      if( $( "#" + id_blc ).data( "hover_actif" ) == false )
      {
        $( "#" + id_blc ).hover( function( e )
        {
          $( "#" + id_blc ).data( "survol_blc", true );
        },
        function()
        {
          $( "#" + id_blc ).data( "survol_blc", false );
          $( "#" + id_blc ).oneTime( 400, "msk", function() {
            masquer( id_blc );
          } );
        } );
        $( "#" + id_blc ).data( "hover_actif", true );
      }
    }
    /**
     * masquer : le bloc profil
     *
     */ 
    function masquer( id_blc )
    {
      if( $( "#" + id_blc ).data( "survol_blc" ) == false && $( "#" + id_blc ).data( "survol_lien" ) == false )
        $( "#" + id_blc ).fadeOut( "fast" );
    }
    build();
  };
} ) ( jQuery )

