jQuery(function($) {

$('#quickFind select').change(function() {
  if($(this).val() != '')
    document.location = $(this).val();
});

$('#slideshow').cycle({
  fx: 'fade',
  speed: 1200,
  timeout: 5500,
  pause: 1,
  pager: '#slideshow .pagination',
  pagerEvent: 'mouseover',
  slideExpr: 'a'
});

$('#slideshow .pagination a').click(function(event) {
  event.preventDefault();
});

$('form a.formSubmit').click(function(event) {
  event.preventDefault();
  if($(this).is(".disabled")) return;
  $(this).closest('form').submit();
});

$('input[title]').blur(function() {
  if($(this).val() == '') {
    $(this).addClass('hinting').val($(this).attr('title'));
    $(this).one('focus', function() {
      $(this).removeClass('hinting').val('');
    });
  }
}).trigger('blur');


$('#share a.toggleshare').click(function(event){event.preventDefault();});
$('#share a.toggleshare').mouseenter(function() {
  $('#shareoptions').show().stop(true, false).animate({width: 240});
});
$('#share').mouseleave(function() {
  $('#shareoptions').fadeTo(3000, 1, function() {
    $(this).animate({width: 0}, function() {
      $(this).hide();
    });
  });
});


$('#newsletter, #announcements').submit(function(event) {
  form = $(this);
  event.preventDefault();

  form.find('input, select').each(function() {
    if($(this).val() == '' || $(this).hasClass('hinting')) {
      $(this).addClass('invalid');
    } else {
      $(this).removeClass('invalid');
    }
  });

  invalids = form.find('.invalid');
  if(invalids.length > 0) {
    invalids.effect('shake', {distance: 10, duration: 100, times: 2});
    invalids.eq(0).select().focus();
    return;
  }

  form.find('input, select').css('background-color', '#eee').attr('disabled', 'disabled');
  form.find('a.formSubmit').hide();
  form.append('<p class="status">Enviando...</p>');

  $.ajax({
    type: "POST",
    url: form.attr('action'),
    data: form.find(':input'),
    dataType: 'json',
    success: function() {
      form.find(".status").text("Inscrito com sucesso.");
    },
    error: function() {
      form.find(".status").text("Erro: verifique os dados digitados");
    }
  });
});

}); /* End DOM loaded */

function a() {
  $('ul:hidden').show();
}
