jQuery(document).ready(function() {

 jQuery("a[@href^=http]").attr('target','_blank');
 
  var tooltipTimer = {

    setup: function() {
      var self = this;
      this.processTitles();
      this.elementId = 1;

      jQuery("#navigation a").hover(
        function() {
          self.cancel();
          self.cancelCycle = true;
          jQuery(".tooltip").hide();

          jQuery(this).after("<div class=\"tooltip\" style=\"position: absolute; top: " + (parseInt(jQuery(this).css("top")) + 6) + "px; left: " + (parseInt(jQuery(this).css("left")) + 36) + "px;\">" + self.aTitles[jQuery("#navigation li a").index(this)] + "</div>");
          return false;
        },
        function() {
          self.cancel();

          jQuery(".tooltip").fadeOut("slow", function() {
            jQuery(this).remove(); // tidy up the HTML after we've done with the pseudo tooltip
          });

        }
      );

      this.iTooltipTimeoutId = this.showTooltip();

    },

    showTooltip: function() {
      var self = this;

      if(this.cancelCycle) {
        this.cancelCycle = false;
        this.cancel();
        return;
      }

      jQuery(".tooltip").hide();

      // display tooltip for current item
      jQuery("#navigation li:nth-child(" + this.elementId + ") a")
        .after("<div class=\"tooltip\" style=\"position: absolute; top: " + (parseInt(jQuery("#navigation li:nth-child(" + this.elementId + ") a")
        .css("top")) + 6) + "px; left: " + (parseInt(jQuery("#navigation li:nth-child(" + this.elementId + ") a")
        .css("left")) + 36) + "px;\">" + this.aTitles[this.elementId-1] + "</div>");

      if(this.cancelCycle) {
        this.cancel();
        this.cancelCycle = false;
        return;
      }
      // fade tooltips out

      this.iTooltipTimeout = setTimeout(function() {

        if(self.cancelCycle) {
           self.cancel();

          return;
        }
        jQuery(".tooltip").fadeOut(1000);



      },2000);

      // reset the loop once we get to the end
      if (this.elementId >= this.aTitles.length) { this.elementId = 1; }
      // otherwise iterate the variable to step forward in the loop
      else { this.elementId++; };

      this.iTooltipTimeoutId = window.setTimeout(function(){self.showTooltip()},3000);
    },

    processTitles: function() {
      var aTitles = new Array();
      var sTitle;

      jQuery("#navigation li").each(function() {
        sTitle = jQuery("a",this).attr("title");
        jQuery("a",this).attr("title","");
        aTitles.push(sTitle);
      });

      this.aTitles = aTitles;
    },

    cancel: function() {

      if(typeof this.iTooltipTimeoutId == "number") {
        window.clearTimeout(this.iTooltipTimeoutId);
        delete this.iTooltipTimeoutId;
      }
      return;
  }


  }

  tooltipTimer.setup();

});