$.fn.pause = function(duration) {
        $(this).animate({ dummy: 1 }, duration);
        return this;
      };
      
      var navHoverImage = null;
      var openSubNav = null;
      
      $(document).ready(function(){
        // preload nav hover state
        navHoverImage = new Image();
        navHoverImage.src = '/images/cc-header-on.jpg';
        
        $('#header>ul>li>a').each(function () {
          var div = document.createElement('div');
          var p = $(this).position();
          $(div).css({ width: $(this).width()
                     , height: $(this).height()
                     , position: 'absolute'
                     , backgroundImage: 'url(/images/cc-header-on.jpg)'
                     , backgroundPositionX: -1 * p.left
                     , backgroundPositionY: -1 * p.top
                     , top: p.top
                     , left: p.left
                     , display: 'none'
                     , cursor: 'pointer' })
                .click( function () { top.location.href = $('a', this.parentNode)[0].href; });
          div.id = this.id + '-over';
          
          $(this).parent().append(div);
          
          $(this).mouseover(function (e) {
            //console.log ($('#' + this.id + '-over'));
            $('#' + this.id + '-over').fadeIn('slow');
            _this = this;
            if (openSubNav)
            {
              //console.log(0);
              if (typeof(openSubNav[0]) != 'undefined')
              {
                //console.log(1);
                if (openSubNav[0].id != $('ul', $(_this).parent())[0].id)
                {
                  //console.log(2);
                  openSubNav.fadeOut('fast', function() { 
                    //console.log(3);
                    openSubNav = $('ul', $(_this).parent());
                    if (openSubNav && openSubNav[0])
                      openSubNav.fadeIn('slow');
                    else
                      openSubNav = null;
                
                  })
                }
              }
            }
            else
            {
              //console.log(4);
              openSubNav = $('ul', $(this).parent());
              if (openSubNav && openSubNav[0])
                openSubNav.fadeIn('slow');
              else
                openSubNav = null;
            }

          });
          
          $(this).parent().mouseleave( function () {    
            $('div', this).fadeOut('slow');
          });
          
/*          $(this).parent().mouseleave( function () {
            console.log(this);
            $('ul', this).fadeOut('slow');
          });*/
        });
      });
