
$(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();
  });
  
   // Lava menu: x hover, mostrar submenus, moure box
  var style = 'easeOutExpo';

  // Definim posició inicial box
  if ($('#lava li.selected').length) {
    var default_left = Math.round($('#lava li.selected').offset().left - $('#lava').offset().left)+ 9;
    var default_width = $('#lava li.selected').width() - 21;
  } else {
    var default_left = '-200px';
    var default_width = '50px';   // Més petit dona errors en IE :(
  }
  $('#box').css({left: default_left});
  $('#box .head').css({width: default_width});
  // Sombra
  $('#box2').css({left: default_left});
  $('#box2 .head2').css({width: default_width});

  $("#menu_header li.level_top").hover(function(){
    // Submenus
    if(this.className.indexOf("selected") == -1)  {
      var 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();

    // Box
    var left = Math.round($(this).offset().left - $('#lava').offset().left) + 9;
    var width = $(this).width() - 21;
    $('#box .head').stop(false, false).animate({width:width},{duration:500, easing: style});
    $('#box').stop(false, false).animate({left: left},{duration:500, easing: style});

  },function(){
    // Submenus
    if(this.className.indexOf("selected") == -1)  {
      $(this).children("ul:eq(0)").hide();
    }
  });

  // Si sortim del menú posicions inicials
  $('#lava > ul').mouseleave(function () {
    // Definim posicions per box
    $('#box .head').stop(false, false).animate({width: default_width},{duration:500, easing: style});
    $('#box').stop(false, false).animate({left: default_left},{duration:500, easing: style});
    // Mostrem submenu x defecte
    $('#lava li.selected').children("ul:eq(0)").show();
  });

  /*ColorBox*/
//$(".a_porc_fina").colorbox({width:"30%", inline:true, href:"#porc_fina"});
/*$(".a_porc_fina").colorbox({ width:"500px",height:"200px",inline:true, href:"#porc_fina_pop"});
$(".a_porc_gruixuda").colorbox({width:"500px",height:"200px",inline:true, href:"#porc_gruixuda_pop"});
$(".a_porc_laminada").colorbox({width:"500px",height:"200px",inline:true, href:"#porc_laminada_pop"});
$(".a_bovi_fina").colorbox({ width:"500px",height:"200px",inline:true, href:"#bovi_fina_pop"});
$(".a_bovi_gruixuda").colorbox({width:"500px",height:"200px",inline:true, href:"#bovi_gruixuda_pop"});
$(".a_xai").colorbox({width:"500px",height:"200px",inline:true, href:"#xai_pop"});
*/

  /*ShadowBox*/
Shadowbox.init({
continuous: true,
overlayColor: "#fff",
overlayOpacity: 0.9
});

/* JQuery Cycle plugin*/
$('#fotos_capcalera').cycle({
    fx:      'scrollRight',
    speed:    500,
    timeout:  5000
});

});

