(function() {

  if (window.dM == null) window.dM = {};

  window.dM.logoParpadea = function() {
    $("#over-logo").show();
    setTimeout("$('#over-logo').hide()", 50);
    setTimeout("$('#over-logo').show()", 150);
    return setTimeout("$('#over-logo').hide()", 200);
  };

  window.dM.iluminaDalePlay = function() {
    return $("#cable-izquierda").css("background-position", "0 -251px");
  };

  window.dM.apagaDalePlay = function() {
    return $("#cable-izquierda").css("background-position", "0 0");
  };

  window.dM.iluminaPowa = function() {
    $("#powaover").stop();
    $("#powaover").animate({
      opacity: 1
    }, 300);
    return false;
  };

  window.dM.apagaPowa = function() {
    $("#powaover").stop();
    return $("#powaover").animate({
      opacity: 0.01
    }, 600);
  };

  window.dM.scrolleameA = function() {
    var destino;
    destino = dM.calcularPosicionDeDestino(this);
    $("html, body").stop();
    $("html, body").animate({
      scrollTop: destino
    }, 900, "easeOutQuart");
    return false;
  };

  window.dM.calcularPosicionDeDestino = function(deQue) {
    if ($($(deQue).attr("href") + " h2").size() > 0) {
      return $($(deQue).attr("href") + " h2").offset().top;
    } else {
      return $($(deQue).attr("href")).offset().top;
    }
  };

  window.dM.mostrarIntro = function() {
    $("html, body").animate({
      scrollTop: 0
    }, 100, "easeOutQuart");
    return $("#intro").show();
  };

  window.dM.ocultarIntro = function() {
    $("#intro").hide();
    if (navigator.userAgent.match(/MSIE/)) return window.location = "/";
  };

  window.resize = function() {
    $("#intro .flash").width($(window).width());
    return $("#intro .flash").height($(window).height());
  };

  $(function() {
    dM.logoParpadea();
    $("a#link-home").bind("mouseenter", dM.logoParpadea);
    $("#dale-play").mouseover(dM.iluminaDalePlay);
    $("#dale-play").mouseout(dM.apagaDalePlay);
    $("#dale-play").click(dM.mostrarIntro);
    dM.apagaPowa();
    $("#powaover").bind("mouseenter", dM.iluminaPowa);
    $("#powaover").mouseout(dM.apagaPowa);
    $("#powaover").click(dM.mostrarIntro);
    $("#trabajos h2 a").mouseover(function() {
      $(this).stop();
      return $(this).animate({
        color: "#FFF000"
      }, 300);
    });
    $("#trabajos h2 a").mouseout(function() {
      $(this).stop();
      return $(this).animate({
        color: "#ffd100"
      }, 600);
    });
    $("#staff h2 a").mouseover(function() {
      $(this).stop();
      return $(this).animate({
        color: "#FFF000"
      }, 300);
    });
    $("#staff h2 a").mouseout(function() {
      $(this).stop();
      return $(this).animate({
        color: "#ffd100"
      }, 600);
    });
    $("#trabajos .footer a > img, #staff .footer a > img, #dmo-power .footer a > img,  #portfolio .footer a > img").animate({
      opacity: 0
    }, 300);
    $("#trabajos .footer a, #staff .footer a, #dmo-power .footer a, #contacto .footer a, #trabajos h2 a, #staff h2 a, #contacto h2 a, #header .nav a.local, #portfolio .footer a").click(dM.scrolleameA);
    $("#trabajos .footer a, #staff .footer a, #dmo-power .footer a, #portfolio .footer a").mouseover(function() {
      $("> img", this).stop();
      return $("> img", this).animate({
        opacity: 0.8
      }, 300);
    });
    $("#trabajos .footer a, #staff .footer a, #dmo-power .footer a, #portfolio .footer a").mouseout(function() {
      $("> img", this).stop();
      return $("> img", this).animate({
        opacity: 0.01
      }, 600);
    });
    $("h2 a").parent().click(function() {
      return $("a", this).click();
    });
    $("#contacto input, #contacto textarea").each(function() {
      if ($.trim($(this).val()) !== "") {
        return $(this).prev().css({
          visibility: "hidden"
        });
      }
    });
    $("#contacto legend").click(function() {
      return $(this).next().focus();
    });
    $("#contacto input, #contacto textarea").focus(function() {
      return $(this).prev().css({
        visibility: "hidden"
      });
    });
    $("#contacto input, #contacto textarea").blur(function() {
      if ($.trim($(this).val()) === "") {
        return $(this).prev().css({
          visibility: "visible"
        });
      }
    });
    $("#contacto button").bind("mouseenter", function() {
      $("img", this).stop();
      return $("img", this).animate({
        width: 111,
        marginLeft: -20,
        marginTop: -20
      }, 300, "easeOutBounce");
    });
    $("#contacto button").bind("mouseleave", function() {
      $("img", this).stop();
      return $("img", this).animate({
        width: 80,
        marginLeft: 0,
        marginTop: 0
      }, 300, "easeOutBounce");
    });
    $("#contacto .footer a").bind("mouseenter", function() {
      $("span", this).stop();
      $("span", this).animate({
        color: "#FFFF00"
      }, 300);
      $("img.rollover", this).stop();
      return $("img.rollover", this).animate({
        opacity: 1
      }, 300);
    });
    $("#contacto .footer a").bind("mouseleave", function() {
      $("span", this).stop();
      $("span", this).animate({
        color: "#FFD100"
      }, 600);
      $("img.rollover", this).stop();
      return $("img.rollover", this).animate({
        opacity: 0
      }, 600);
    });
    $("#staff ul li img.rollover").animate({
      opacity: 0.01
    }, 300);
    $("#staff ul li").mouseover(function() {
      $("img.rollover", this).stop();
      return $("img.rollover", this).animate({
        opacity: 1
      }, 300);
    });
    $("#staff ul li").mouseout(function() {
      $("img.rollover", this).stop();
      return $("img.rollover", this).animate({
        opacity: 0.01
      }, 600);
    });
    resize();
    return $(window).bind("resize", resize);
  });

}).call(this);

