//  -----------------------------------------------------------------------
    window.addEvent( "domready", function () {

  //  showcase de imágenes.
      if ( $("showcase") )
        var showNoob              = makeSlide( "showcase", 7, null, null, 830, null, null, null, null, true );

  //  secciones.
      if ( $("worksContent") ) {  // si están las secciones definidas.
        var sections              = new Array();
        sections[0]               = "works";
        sections[1]               = "what";
        sections[2]               = "profile";
        sections[3]               = "contact";
        for ( var i = 0; i < sections.length; i++ ) {
          if ( $( sections[i]+"Content" ) ) {
        //  inicia la secciones ocultándolas.
            if ( !$( sections[i]+"Content" ).style.height || $( sections[i]+"Content" ).style.height == "0px" ) {
              window[ sections[i]+"Slide" ]    = new Fx.Style( sections[i]+"Content", "height" ).hide();
              $( sections[i]+"Link" ).getElementsByTagName("span")[0].className = "btnOpen";
            }
          }
        }

    //  malditos eventos (método poco feliz).
        $( "worksLink" ).addEvent(   "click", function(worksEvent) {   toggleSection( "works",   worksEvent ); });
        $( "whatLink" ).addEvent(    "click", function(whatEvent) {    toggleSection( "what",    whatEvent ); });
        $( "profileLink" ).addEvent( "click", function(profileEvent) { toggleSection( "profile", profileEvent ); });
        $( "contactLink" ).addEvent( "click", function(contactEvent) { toggleSection( "contact", contactEvent ); });

        if ( $("works") && navigator.appName != "Microsoft Internet Explorer" && navigator.appName != "Opera" ) {   // damn you!!! hahaha
          var projects              = $$("#works a");
          projects.each( function( elem ) {
            elem.addEvent( "click", function(e) {
              new Event(e).stop();
              var project           = elem.href.split("/");
              var ajax              = new Ajax( "/inc/workSlide.php", {
                update:             $("work"),
                method:             "get",
                data:               "project=" + project[project.length-2],
                evalScripts:        true,
                asynchronous:       true,
                onComplete: function() {
                  projects.each( function( elem2 ) {
                    var first       = true;
                    $( elem2.id ).getElements("span").each( function( elem3 ) {
                      if ( elem2.href != elem.href && elem2.parentNode.removeClass ) {
                        elem2.parentNode.removeClass("on").addClass("off");
                        elem3.removeClass("active");
                      }
                      else {
                        if ( elem3.id && first ) {
                          elem3.addClass("active");
                          first     = false;
                        }
                        else
                          elem3.removeClass("active");
                      }
                    });
                  });
                  if ( elem.parentNode.removeClass )
                    elem.parentNode.removeClass("off").addClass("on");
                }
              }).request();
            });
          });
        }

        if ( $("whatContent") )
          var whatNoob              = makeSlide( "whatInfo", 5, "whatPrev", "whatNext", 640, 500, "horizontal", $ES( "li", "whatButtons" ) );

        if ( $("profileContent") ) {
      //  links.
          var definitionSlider      = new Fx.Slide( "profileDefinitionContent" );
          var factsSlider           = new Fx.Slide( "profileFactsContent" ).slideOut();
          $("definitionLink").addEvent( "click", function(dEv) {
            new Event(dEv).stop();
            definitionSlider.slideIn();
            factsSlider.slideOut();
            $("factsLink").removeClass("active");
            this.addClass("active");
          });
          $("factsLink").addEvent( "click", function(fEv) {
            new Event(fEv).stop();
            definitionSlider.slideOut();
            factsSlider.slideIn();
            $("definitionLink").removeClass("active");
            this.addClass("active");
          });
      //  slides.
          var definitionNoob        = makeSlide( "profileDefinitionInfo", 5, "profileDefinitionPrev", "profileDefinitionNext", 640, 500, "horizontal", $ES( "li", "profileDefinitionButtons" ) );
          var factsNoob             = makeSlide( "profileFactsInfo", 4, "profileFactsPrev", "profileFactsNext", 640, 500, "horizontal", $ES( "li", "profileFactsButtons" ) );
        }

        if ( $("contactContent") ) {
          var contactNoob         = makeSlide( "contactInfo", 2, "showMap", null );
          $("showMap").addEvent( "click", function(cc) {
            new Event(cc).stop();
            if ( this.style.backgroundImage == "url(/img/btn-close.gif)" )
              this.style.backgroundImage  = "none";
            else
              this.style.backgroundImage  = "url(/img/btn-close.gif)";
          });
        }
      }

  //  links externos.
      var links         = $$("a[rel=nofollow]");
      for ( var i = 0; i < links.length; i++ )
        links[i].target = "_blank";

  //  scroll suavecito. =)
      new SmoothScroll({duration:500});

  //  tipos de trabajos.
    });

    function toggleSection( name, event ) {
      if ( event )
        new Event(event).stop();
      if ( !$( name+"Content" ).style.height || $( name+"Content" ).style.height == "0px" ) {
        var start                 = 0;
        var finish                = 540;
        var btnClass              = "btnClose";
        var borderBottom          = "1px solid #FEE600";
        var scroll                = new Fx.Scroll(window).toElement(name+"Anchor");
      }
      else {
        var start                 = 540;
        var finish                = 0;
        var btnClass              = "btnOpen";
        var borderBottom          = "0px";
      }
      window[ name+"Style" ]                                      = new Fx.Style( name+"Content", "height" ).start( start, finish );
      $( name+"Link" ).getElementsByTagName("span")[0].className  = btnClass;
      $( name+"Content" ).style.borderBottom                      = borderBottom;
    }

    function makeSlide( element, items, previous, next, size, duration, direction, handles, id, autoPlay ) {
      strItems                    = "";
      for ( var i = 1; i <= items; i++ )
        strItems                 += i + ",";
      size                        = (size) ? size : 640;
      duration                    = (duration) ? duration : 500;
      direction                   = (direction) ? direction : "horizontal";
      handles                     = (handles) ? handles : null;
      id                          = (id) ? id : null;
      autoPlay                    = (autoPlay) ? true : false;
      var noob                    = new noobSlide({
        box: $( element ),
        items: eval("[" + strItems.substring(0,(items*2)-1) + "]"),
        size: size,
        mode: direction,
  			handles: handles,
  			autoPlay: autoPlay,
        onWalk: function( currentItem, currentHandle ) {
          if ( previous == "worksUp" && next == "worksDown" ) {
            if ( currentItem > 1 )
              $( previous ).removeClass("hide");
            else
              $( previous ).addClass("hide");
            if ( currentItem < items )
              $( next ).removeClass("hide");
            else
              $( next ).addClass("hide");
          }
          if ( currentHandle ) {
            if ( handles ) {
              this.handles.removeClass("active");
              currentHandle.addClass("active");
            }
            var thisClass = currentHandle.className.split(" ")[0];
            for ( var i = 0; i < types.length; i++ ) {
              if ( $( types[i] + id ) ) {
                if ( thisClass != types[i] )
                  $( types[i] + id ).removeClass("active");
                else
                  $( types[i] + id ).addClass("active");
              }
            }
          }
        },
        fxOptions: {
          duration: duration,
          transition: Fx.Transitions.Quint.easeOut,
          wait: false
        },
        buttons: {
          previous: ($( previous ) ? $( previous ) : null),
          next: ($( next ) ? $( next ) : null)
        }
      });
      return noob;
    }
