  var hl_edit_block_loop = {
    init: function() {
      this.stepTime = 6000;
      this.blockId = 'hl-edit-blocks';
      this.blocks = YAHOO.util.Selector.query('#' + this.blockId + ' > div');
      this.indicators = YAHOO.util.Selector.query('#hl-edit-indicators > div');
      this.count = this.blocks.length;
      this.currIdx = 0;
      this.oldIdx = 0;
      this.isPaused = false;
      this.isNavPaused = false;
      this.fadeOut = new YAHOO.util.Anim(this.blockId, { opacity: { to: 0 } }, .7, YAHOO.util.Easing.easeOut);
      this.fadeIn = new YAHOO.util.Anim(this.blockId, { opacity: { to: 1 } }, .9, YAHOO.util.Easing.easeIn);
      YAHOO.util.Event.on(this.blockId, 'mouseover', hl_edit_block_loop.setMousePause);
      YAHOO.util.Event.on(this.blockId, 'mouseout', hl_edit_block_loop.setMouseGo);
      setInterval(hl_edit_block_loop.runLoop, this.stepTime);

      this.fadeOut.onComplete.subscribe(hl_edit_block_loop.finishFadeOut);
      this.fadeIn.onComplete.subscribe(hl_edit_block_loop.finishFadeIn);
    },
    runLoop: function() {
      if (!hl_edit_block_loop.isPaused && !hl_edit_block_loop.isNavPaused) {
        hl_edit_block_loop.fadeOut.animate(hl_edit_block_loop.fadeOut);
      }
    },
    finishFadeOut: function() {
      hl_edit_block_loop.blocks[hl_edit_block_loop.oldIdx].style.display = 'none';
      hl_edit_block_loop.indicators[hl_edit_block_loop.oldIdx].className = 'hl-nav-indicator-off';
      var i = hl_edit_block_loop.oldIdx;
      hl_edit_block_loop.indicators[hl_edit_block_loop.oldIdx].onclick =
        function() {
          hl_edit_block_loop.clickJumpTo(i);
        };
      hl_edit_block_loop.currIdx++;
      if (hl_edit_block_loop.currIdx == (hl_edit_block_loop.count)) {
        hl_edit_block_loop.currIdx = 0;
      }
      else if (hl_edit_block_loop.currIdx < 0) {
        hl_edit_block_loop.currIdx = hl_edit_block_loop.count - 1;
      }
      hl_edit_block_loop.blocks[hl_edit_block_loop.currIdx].style.display = "block";
      hl_edit_block_loop.indicators[hl_edit_block_loop.currIdx].className = 'hl-nav-indicator-on';
      hl_edit_block_loop.indicators[hl_edit_block_loop.currIdx].onclick = null;
      hl_edit_block_loop.fadeIn.animate(hl_edit_block_loop.fadeIn);
      hl_edit_block_loop.oldIdx = hl_edit_block_loop.currIdx;
    },
    finishFadeIn: function() {
      //this.fadeIn.animate(this.fadeIn);
    },
    setPause: function(e) {
      hl_edit_block_loop.isNavPaused = true;
    },
    setGo: function(e) {
      hl_edit_block_loop.isNavPaused = false;
    },
    setMousePause: function(e) {
      hl_edit_block_loop.isPaused = true;
    },
    setMouseGo: function(e) {
      hl_edit_block_loop.isPaused = false;
    },
    clickPause: function(obj) {
      hl_edit_block_loop.isPaused = true;
      hl_edit_block_loop.isNavPaused = true;
      document.getElementById("hl-edit-nav-pause").style.display = "none";
      document.getElementById("hl-edit-nav-play").style.display = "block";
    },
    clickGo: function(obj) {
      hl_edit_block_loop.isPaused = false;
      hl_edit_block_loop.isNavPaused = false;
      document.getElementById("hl-edit-nav-play").style.display = "none";
      document.getElementById("hl-edit-nav-pause").style.display = "block";
    },
    clickJumpTo: function(num) {
      hl_edit_block_loop.isPaused = true;
      hl_edit_block_loop.isNavPaused = true;
      document.getElementById("hl-edit-nav-pause").style.display = "none";
      document.getElementById("hl-edit-nav-play").style.display = "block";
      hl_edit_block_loop.currIdx = num - 1;
      hl_edit_block_loop.fadeOut.animate(hl_edit_block_loop.fadeOut);
    },
    clickForward: function() {
      hl_edit_block_loop.clickJumpTo(hl_edit_block_loop.currIdx + 1);
    },
    clickBack: function() {
      hl_edit_block_loop.clickJumpTo(hl_edit_block_loop.currIdx - 1);
    }
  }

  YAHOO.util.Event.onDOMReady(function() {
    loader = new YAHOO.util.YUILoader();
    loader.base = 'http://yui.yahooapis.com/2.7.0/build/';
    loader.allowRollup = true;
    loader.require('selector', 'animation');
    loader.onSuccess = function() {
      hl_edit_block_loop.init();
    }
    loader.insert();
  });

