function slide(){
  var $active = $('#slide img.active');
  if($active.length == 0)
    $active = $('#slides img:last');
  var $next=$active.next().length ? $active.next() : $('#slide img:first');
  $active.addClass('last-active');
  $next.css({opacity:0}).addClass('active').animate({opacity:1}, 1000, function() {
    $active.removeClass('active last-active');
  })
}
function openOverlay() {
  if ($.browser.msie)
    $('#overlay').show();
  else
    $('#overlay').fadeIn();
  return false;
}
function closeOverlay() {
  if ($.browser.msie)
    $('#overlay').hide();
  else
    $('#overlay').fadeOut();
  $('#message').hide();
  $('p.submit input').show();
}
function send() {
  $('p.submit input').hide();
  $('#loader').show();
  var error = '';
  
  if (error != '') {
    alert("== Erreur de saisie ==\n" + error);
  }
  else {
    var data = {
      "date":         $('#date').val(),
      "event":        $('#event').val(),
      "profile":      $('#profile').val(),
      "participants": $('#participants').val(),
      "remarks":      $('#remarks').val(),
      "comments":     $('#comments').val(),
      "gender":       $('#gender').val(),
      "lastname":     $('#lastname').val(),
      "firstname":    $('#firstname').val(),
      "company":      $('#company').val(),
      "address":      $('#address').val(),
      "postcode":     $('#postcode').val(),
      "city":         $('#city').val(),
      "country":      $('#country').val(),
      "phone":        $('#phone').val(),
      "email":        $('#email').val(),
      "submit":       true
    };
    $.post('remote.php?mode=form&node=contact', data, procid, 'json');
    return false;
  }
}
function procid(json) {
  if (json.success) {
    $('#loader').hide();
    $('#message').html('Votre message vient d\'être envoyé<br />Merci').fadeIn();
    setTimeout('closeOverlay()', 2000);
  }
  else {
    $('#loader').hide();
    $('#message').html(json.error).fadeIn();
    setTimeout(function() {
      $('#message').fadeOut().html('');
      $('p.submit input').show();
    }, 2000);
  }
}
$(function(){
  Cufon.replace('h2');
  if (typeof datepicker=='function') {
    $('.date-pick').datePicker();
  }
  setInterval('slide()', 3000);
  $('.close').click(closeOverlay);
  $('#footer a.button').click(openOverlay);
  $('#contact').submit(send);
});
