
$(document).ready(function() {           

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

  $('#language').change(function() {
    location.href= $('#language option:selected').attr('title');
  });

  $('.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_header li.level_top").hover(function(){
    // Submenus
    if(this.className.indexOf("selected") == -1)  {
      getCurrent = $(this).parent().children("li.selected:eq(0)");
      if (getCurrent = 1 ) {
        $(this).parent().children("li.selected:eq(0)").children("ul").hide();
      }
    }
    $(this).children("ul:eq(0)").show();

  },function(){
    // Submenus
    if(this.className.indexOf("selected") == -1)  {
      $(this).children("ul:eq(0)").hide();
    }
  });
  // Si sortim del menú posicions inicials
  $('ul#menu_header').mouseleave(function () {
    // Mostrem submenu x defecte
    $('#menu_header li.selected').children("ul:eq(0)").show();
  });

  // Cycle Imatges
  if ($('#image').length){
    $('#image').cycle({
      fx: 'fade',
      timeout: 5000,
      speed: 750,
      random: 0,
      pager: '#links_nav',
      pagerAnchorBuilder: function(idx, slide) {
        // return selector string for existing anchor
        return '#links_nav a:eq(' + idx + ')';
      }
    });
  }

  // Cycle Showroom
  var num_childs = $("#gal_ini").children().length;
  $('ul#gal_ini').cycle({
    fx: 'scrollHorz',
    timeout: 4000,
    speed: 500,
    startingSlide: Math.floor(Math.random()*num_childs)
  });

  $('#noticies').cycle({
    fx:     'fade',
    speed:  'fast',
    timeout: 0,
    next:   '#next',
    prev:   '#prev',
    pager: '#botons_aux'
});

});

