postpostmodern = {

  globalAjaxCursorChange: function() 
  {
    $("body").bind("ajaxSend", function(){
       $(this).addClass('busy');
     }).bind("ajaxComplete", function(){
       $(this).removeClass('busy');
     });
  }, 
  
  archiveHighlight: function()
  {
    $(".archive dt").hover(
      function() {
        $(this).next().find(".post-info").addClass('highlighted');
      },
      function() {
        $(this).next().find(".post-info").removeClass('highlighted');
      }
    );
    $(".archive dd").hover(
      function() {
        $(this).find(".post-info").addClass('highlighted');
      },
      function() {
        $(this).find(".post-info").removeClass('highlighted');
      }
    );
  },
  
  navLabels: function() 
  {
    $("#nav").hover(
      function() {
        $('#nav-labels').slideDown('fast');
      },
      function() {
        $('#nav-labels').slideUp('fast');
      }
    );
  },
  
  autoGravatar: function()
  {
    $defaultGravatar = $('#comment-form .avatar img').attr('src');
    $('#comment-form #email').bind(
      'keyup',
      function() {
        email = $(this).val();
        if(email.match(/@.*\.\w\w\w?/)) {
          avatar = 'http://www.gravatar.com/avatar/' + MD5(email) + '?s=32&d=' + $defaultGravatar;
        } else {
          avatar = $defaultGravatar;
        }
        $('#comment-form .avatar img').attr('src', avatar);
      }
    );
  },
  
  autoName: function()
  {
    $('#comment-form #author').bind(
      'keyup', 
      function() {
        author = $(this).val();
        author = author.match(/\w/) ? author : 'You';
        $('#comment-form h3 cite').text(author);
      }
    );
  },
  
  bouncyLoaders: function()
  {
    bouncing = '';
    $('#nav li a').click(
      function() {
        if(bouncing == $(this).attr('id')) {
          bouncing = '';
          return false;
        }
        bouncing = $(this).attr('id');
        $(this).find('img').bounce();
        return false;
      }
    );
  },
  
  sidebarSwitch: function()
  {
    if($.cookie('active_sidebar')) {
      active_sidebar = $.cookie('active_sidebar');
    } else {
      active_sidebar = '#about';
    }
    $(active_sidebar).show();
    $('#nav li a').click(
      function() {
        var sidebar_id = '#' + $(this).attr('id').split('-')[0];
        if(sidebar_id != active_sidebar) {
          $(active_sidebar).fadeOut(100, 
            function() {
              $(sidebar_id).fadeIn(100);
            }
          );
          active_sidebar = sidebar_id;
          $.cookie('active_sidebar', active_sidebar, { expires: 10, path: '/' });
        }
        return false;
      }
    );
  },
  
  chatPopup: function()
  {
    $('a[rel="chat"]').click( 
      function() {
        window.open( $(this).attr('href'), 'chat', 'height=450,width=300' );
        return false;
      }
    );
  },
  
  syntaxHighlight: function()
  {
    dp.SyntaxHighlighter.ClipboardSwf = template_directory + '/flash/clipboard.swf';
    dp.SyntaxHighlighter.HighlightAll('code');
  },
  
  redoSIFR: function() {  
      // Ensure sIFR is defined  
      if (sIFR != "undefined" && sIFR.replace && typeof sIFR.replace == "function") {  
          // Has this tab already been rendered using sIFR?  
          if (!rendered[active_sidebar]) {  
              // No, not yet, so do the sIFR replacement  
              sifrSidebar();
              // Record the fact that this tab has now been rendered with sIFR  
              rendered[active_sidebar] = true;  
          } 
      }  
  },
  
  fetchDelicious: function()
  {
    if($('#delicious-badge').length) {
      $('#delicious-badge').load(template_directory + '/delicious.php');
    }
  },

	fancyGallery: function()
	{
		var galleryLinks = $('ul.gallery a');
		if(galleryLinks.length) {
			galleryLinks.fancybox({ overlayColor:'#000', overlayOpacity:0.8 });
		}
	}, 
	
	doCufon: function()
	{
		Cufon.replace('#primary h1', { hover: true });
	}
  
}

jQuery.fn.bounce = function()
{
  if(bouncing == $(this).parent().attr('id'))
    return $(this).animate({"top": "-=5px"}, 500, 'easeOutSine', $(this).bounceBack);
}

jQuery.fn.bounceBack = function()
{
  return $(this).animate({"top": "+=5px"}, 500, 'easeInSine', $(this).bounce);
}


jQuery(postpostmodern.globalAjaxCursorChange);
jQuery(postpostmodern.archiveHighlight);
jQuery(postpostmodern.navLabels);
jQuery(postpostmodern.autoName);
jQuery(postpostmodern.autoGravatar);
jQuery(postpostmodern.sidebarSwitch);
jQuery(postpostmodern.syntaxHighlight);
jQuery(postpostmodern.chatPopup);
jQuery(postpostmodern.fetchDelicious);
jQuery(fetchTweets);
jQuery(postpostmodern.fancyGallery);
//jQuery(postpostmodern.bouncyLoaders);
jQuery(
  function() { 
    $.localScroll({hash:true});
  }
);

var rendered = [];
