/* Javascript popup window */
$(document).ready(function() {
  $('a.popup').click( function() {
    var newwin = window.open($(this).attr('href'), 'popup', 'scrollbars=1,location=0,statusbar=0,menubar=0,width=500,height=500');
    newwin.focus();
    return false;
  });
});


/* Auto-hiding of error and confirm messages */
$(document).ready(function() {
  $('.error,.confirmation')
    .animate({'opacity': 1}, 7000)
    .animate({'opacity': 0}, 'slow')
    .slideUp('slow')
    ;
});


/* Input fields with a title - the title gets put into the field automatically */
$(document).ready(function() {
  $('input[title]').each(function() {
    // on focus - make text empty if it is set to emptytext
    $(this).focus(function() {
      if ($(this).attr('value') == $(this).attr('title')) {
        $(this).attr('value', '');
        $(this).removeClass('title');
      }
    });
    
    // on blur - make text emptytext if it is empty
    $(this).blur(function() {
      if ($(this).attr('value') == '') {
        $(this).attr('value', $(this).attr('title'));
        $(this).addClass('title');
      }
    });
    
    // run the blur event
    $(this).blur();
  });
});


// Login box popup
$(document).ready(function() {
  if (location.hash == '#login') {
    jQuery.facebox(function() {
      jQuery.get('ajax/login.php', function(data) {
        jQuery.facebox(data);
      })
    });
  }
});
