jQuery(function($){
  // Increase usability for form fields by adding a placeholder:
  $("input:text").each(function(){
		if ($(this).attr('title')) {
	    var placeholder_text = $(this).attr('title'); $(this).attr('title','');
	    $(this).focus(function(){
	      if ($(this).attr('value')==placeholder_text) {
	        $(this).attr('value', '').removeClass('blurred');
	      }
	    }).blur(function(){
	      if ($.trim($(this).attr('value'))=='') {
	        $(this).attr('value', placeholder_text).addClass('blurred');
	      }
	    }).blur();
		}
  });
  
  // add Comments RSS link
  var comments = $('<a/>').attr({ href: '/comments/feed/', className: 'frss', type: 'application/rss+xml', rel: 'alternate', title: 'Subscribe to comments made on this blog via RSS' }).html('RSS');
  var posts = comments.clone().attr({ href: '/feed/', title: 'Subscribe to this blog\'s posts via RSS' });
  // -> prepend :
  var nodes = { '#bottombar .bar-one:first h2': posts,
                '#bottombar .bar-one:last h2': comments };
  $.each(nodes, function(i, val){ $(i).prepend(val); });
  
  // mailing list signup form
  $("#text-2 form").livequery('submit', function(){
		$("img#spinner").ajaxStart(function(){ $(this).show(); }).ajaxStop(function(){ $(this).hide(); });
		if (!jQuery.fn.signupform) {
		  jQuery.fn.signupform = $("#text-2 .textwidget").html();
		}
		
		$("#text-2 .textwidget").load("/mailinglist.php .loginHeader strong",
			{'cm-272900-272900' : $("input#l272900-272900").val())},
			function(response){
				if (response.indexOf('Invalid Email Address')==-1 && response.indexOf("Thank You")>-1) {
					$("#text-2 .textwidget").removeClass('error').addClass('submitted');
				} else {
					$("#text-2 .textwidget").addClass('error').prepend(jQuery.fn.signupform)
					  .find('input:text').focus();
				}
		}).addClass('signedup');
    //  .text('Congratulations! ' +$("input#272900-272900").val()+ 'is now signed up to the APN mailing list!')
    return false;
  });
});