function initializeAppli(area) {
  // All timestamps should be relatized
  $(area + ' span.timestamp').relatizeDate();
  // All external links should open in a new window
  $(area + " a[href^='http']").attr('target','_blank');
  // All links with the 'external' ref attribute open in a new window too
  $(area + " a[rel=external]").attr('target', '_blank');

  // Auto focus fields
  $(area + " input.focused").focus();
  
  // Add/remove focused class
  $(area + " input.text").focus(function() { $(this).addClass('focused'); });
  $(area + " input.text").blur(function() { $(this).removeClass('focused'); });

  
  $(area + " p.submit.spin input[type=submit]").click(function() {
    var container = $(this).parent();
    container.addClass('spinning');
    container.text('');
    container.html("<span><img src='/images/spin.gif' alt='Loading...' /></span> " + $(this).attr('spin_text'))
    container.parent().submit();
  });
	
	// Clicking on a table row will automatically go to the URL of the link with the class 'default-link' from
	// inside the row.
	$(area + " table.data tbody tr td").click(function() {
		var link = $(this).parent().find('a.default-link').attr('href');
		if(link && !$(this).hasClass('options')) {
			window.location = link;
		};
	});
  
}

$(document).ready(function() {
  initializeAppli('');

  $("#domain_redirect").click(function(){
    if ($("#domain_redirect").is(":checked"))
    {
      $("#redirect-destination").show('fast');
    } else {
      $("#redirect-destination").hide('fast');

    }
  });
});


$(document).bind('reveal.facybox', function() { 
  // Initialize Wombat for the facybox
  initializeAppli('#facybox');
});

