//  -------------------------------------------------------- ::: - ::: - ::: ---
    $(document).ready( function() {

      var srv               = new rpc.ServiceProxy( "/rpc", { asynchronous: false } );

  //  Proyectos.
      if ( $("#proyectos").length ) {
        $("#proyectos tr.info").live( "click", function( e ) {
          if ( $(this).next().hasClass("oculto") ) {
            $(".detalle").addClass("oculto");
            var idPr        = $(this).next().attr("id").substring(2);
            var proyecto    = srv.detalleProyecto( idPr );
            $("#pr"+idPr).removeClass("oculto").find("td").html( proyecto.fotos );
            if ( $("#pr"+idPr+" .numeros").length ) {
              $("#pr"+idPr+" .numeros").galleriffic({
                imageContainerSel:    "#pr" + idPr + " .imagenes"
              });
            }
            $("#info").html( proyecto.info ).css( "position", "absolute" ).css( "top", $(this).position().top );
            $(".cerrar").click( function(e) {
              $(this).parent().parent().addClass("oculto");
              $("#info").empty();
              return false;
            });
          }
          else {
            $(this).next().addClass("oculto");
            $("#info").empty();
          }
        });
      }

  //  Contacto.
      $(".facebook").click( function() {
        window.open( this.href );
        return false;
      });
      if ( $("#contacto").length ) {
        var campos          = { 0: "nombre", 1: "telefono", 2: "email", 3: "consulta" };
        $("#contacto").submit( function() {
          var error         = false;
          $.each( campos, function( clave, campo ) {
            if ( !$("#"+campo).val() ) {
              $("#"+campo).focus();
              $(".requerido").css( "display", "block" );
              error         = true;
              return false;
            }
          });
          if ( !error )
            $("#envio").val( srv.enviarConsulta( $("#nombre").val(), $("#telefono").val(), $("#email").val(), $("#consulta").val() ) ).addClass("ok").attr( "disabled", true ).blur();
          return false;
        });
      }

    });


    function abrirProyecto( idPr ) {
      var srv               = new rpc.ServiceProxy( "/rpc", { asynchronous: false } );
      var proyecto    = srv.detalleProyecto( idPr );
      $("#pr"+idPr).removeClass("oculto").find("td").html( proyecto.fotos );
      if ( $("#pr"+idPr+" .numeros").length ) {
        $("#pr"+idPr+" .numeros").galleriffic({
          imageContainerSel:    "#pr" + idPr + " .imagenes"
        });
      }
      $("#info").html( proyecto.info ).css( "position", "absolute" ).css( "top", $("#pr"+idPr).position().top );
      $(".cerrar").click( function(e) {
        $(this).parent().parent().addClass("oculto");
        $("#info").empty();
        return false;
      });
    }

