$(function() {
	// Auto-select short urls
	$('input.short-url, .focus-selects').live('click', function()
	{
		this.focus();
		this.select();
	});
	
	//Hide things JS users shouldn't see
	$('.jsHide').hide();
	
	// Wire up site search 
	$('.site-search').live('submit.ah', function(){
	  var $me = $(this);
	  if ($me.hasClass('404-search')) {
		document.location.hash = 'q='+encodeURIComponent($me.val());
	  } else {
		document.location = '/search#q='+encodeURIComponent($me.val());
	  }
	}).live('keydown', function(e){
	  if(e.keyCode == 13) {
	    $(this).trigger('submit.ah');
  	  return false;
	  }
	});

  // Not nice when one word straggles
  $('#content').find('h1,h2,h3,h4').each(function(i,elem){
    var $me=$(this);
    $me.html($me.html().replace(/ ([^ <>]{1,15})$/,'&nbsp;$1'));
  });
  
  // Make things clickable 
  $('.sitemap_page').addClass('clickable').live('click', function(event){
    window.console&&console.log("Clicked a .sitemap_page.");
    var $a = $(this).find('a').first();
    if ($a[0] != event.target){
      document.location = $a.attr('href');
    }
  });

});

