
// Inicialitzem accions jQuery

$(document).ready(function() {

  $('a.top').click(function(){
    $('html,body').animate({scrollTop:0},'slow');
    return false;
  });

  $('.send_form').click(function() {
    $('#'+$(this).parents("form").attr("id")).submit();
  });

  $('.check_form').click(function(evento) {
    if(check_form()) {
      $('#'+$(this).parents("form").attr("id")).submit();
    } else {
      evento.preventDefault();
    }
  });

  $('.delete_form').click(function(evento) {
    delete_form();
    evento.preventDefault();
  });
  
  // Menu categories
  $('#menu_categories a').click(function() {
    if ($(this).filter('.collapsed').length) {
      // Encongim expanded
      $('#menu_categories a.expanded').addClass('collapsed').removeClass('expanded').find('+ ul').slideToggle('medium');
      // Allarguem collapsed
      $(this).addClass('expanded').removeClass('collapsed').find('+ ul').slideToggle('medium');
    }
  });

  // Shadowbox
  $('a.open_gal').click(function() {
    var gal = document.getElementById('firstInGallery');
    Shadowbox.open(gal);
    return false;
  });

   // Cycle History
  $('#historia').cycle({
    fx: 'scrollUp',
    timeout: 12000,
    speed:  500,
    random:  0,
    pager:  '#nav_historia'
  });

    // Cycle #capsaleres - Fade
  var num_childs = $(".page_slide").children().length;
  $('ul.page_slide').cycle({
    fx: 'fade',
    timeout: 6500,
    speed: 1500,
    startingSlide: Math.floor(Math.random()*num_childs)
  });
});

