$(function() {
  $('#people').cycle({ prev: '#prev', next: '#next', timeout: 11000 });
  
  // Remote forms.
  // IE8 specific issue: live('submit') does not work properly, so we should use dirty hack.
  // Submit links/images should have class submit-to-remote.
  // So you can't submit remote form by submit() call.
  $("form.remote input[type=image]").live('click', function(e){
    var form = $(this).parents('form');  
    e.preventDefault();
    var data = {};
    if (this.tagName == 'INPUT') {
      // Simulate sending input name
      var name = $(this).attr('name');
      var value = $(this).attr('value');
      data[name] = value; // ?
    };
    
    // Rails method iframe for iframed remote forms.
    var files = form.find('input:file');
    if (files.length > 0) {
      var format = $(this).find('input[name=format]');
      if (format.length > 0) {
        $(format).val('iframe');
      } else {
        $(form).append('<input type="hidden" name="format" value="iframe"/>');
      }
    };

    $(form).find('.jsloader').show();
    
    $(form).ajaxSubmit({
      dataType: 'script',
      data: data
    });              
    return false;
  });

  // Submit links
  $('form .submit-form').live('click', function(e) {
    var form = $(this).parents('form');
    $(form).submit();
    return false;
  });
  
  $('.-switch').click(function(e) {
    e.preventDefault();
    var id = $(this).attr('rel');
    $('.price').hide();
    $('#price'+id).show();    
    $('.-switch').removeClass('active');
    $(this).addClass('active');
  });
  
  $('.-open-popup').click(function(e) {
    e.preventDefault();
    var id = $(this).attr('rel');
    $('#card'+id).fadeIn();
    return false;
  });
  
  $('.-close-popup').click(function(e) {
    e.preventDefault();
    $(this).parents('.card').fadeOut();
    return false;
  });
  
  $('#festival_nom').live('change', function(e) {
    var val = $(this).val();
    if (val == 6) {
      $('#team').show();
    } else {
      $('#team').hide();
    }
  });
});

