
$(document).ready(function() {      

  // Desactivem botó dret
  $(document).bind("contextmenu",function(e){
    return false;
  });            

  $('a#to_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();
    }
  });

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


  $('.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) + 12;
    var default_width = $('#lava li.selected').width() - 24;
  } else {
    var default_left = '-2000px';
    var default_width = '50px';   // Més petit dona errors en IE :(
  }
  $('#box').css({left: default_left, width: default_width });
  // Sombra
  $('#box2').css({left: default_left, width: default_width });

  $("#menu_header li.level_top").hover(function(){
    // Submenus
    $('ul', this).stop(false, true).slideDown(200);

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

  },function(){
    // Submenus
    $('ul', this).stop(false, true).slideUp(200);
  });

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

  // Tabs menu
  $('a.tab').click(function () {
    $('#menu_fitxa a.current').removeClass('current');
    $(this).addClass('current');

    $('.tab_content').hide();

    var mostra = $(this).attr('rel');
    $('#'+mostra).show();
    return false;
  });

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

  if ($('#calendar').length) {
  $('#calendar').load('calendar.php', function() {
    $('a.prova').qtip({
      position: {
        corner: {
          target: 'topMiddle',
          tooltip: 'bottomMiddle'
        },
        adjust: {
          y:1
        }
      },

      style: {
        name: 'dark',
        background: '#303030',
        padding: '10px 10px',
        width: {
          max: 210,
          min: 0
        },
        tip: true
      }
    })
  });
  }

  $("a.calendar_button").live("click", function(evento){
    $('#calendar').load($(this).attr('rev'), function() {
      // Code here runs once the content has loaded
      // Put all your event handlers etc. here.
      $('a.prova').qtip({
        position: {
          corner: {
            target: 'topMiddle',
            tooltip: 'bottomMiddle'
          },
          adjust: {
            y:1
          }
        },

        style: {
          name: 'dark',
          background: '#303030',
          padding: '10px 10px',
          width: {
            max: 210,
            min: 0
          },
          tip: true
        }
      })
    });
    evento.preventDefault();
  });
  
  //Botons Espectacles
  $('.info_desc').hide();
  $('.link_espectacle,  .link_foto').hover(function(){
    $(this).parent().find('.info_aux  > .info_desc').stop(true, true).slideDown('fast');
  }, function() {
    $('.info_desc').stop(true, true).slideUp('fast');
  });
  
  // Slide Courtain
  $('#slide_ini').aviaSlider({	// Dropping Courtain		
    blockSize: {height: 'full', width:'full'},
	display: 'topleft',
	transition: 'drop',
	betweenBlockDelay:80,
	animationSpeed: 800,
	switchMovement: true
  });
  $('#image_slide').aviaSlider({	// Dropping Courtain		
    blockSize: {height: 'full', width:45 },
	display: 'topleft',
	transition: 'drop',
	betweenBlockDelay:80,
	animationSpeed: 800,
	switchMovement: true
  });	  
  
  // Cycle Banners Inici
  $('ul#banners_ini').cycle({
    fx: 'fade',
    timeout: 7500,
    speed: 500,
    random: 1
  });
  
  // Historial toogle
  $("a.history").click(function () {
      var mostra = $(this).attr('rel');
      $('#'+mostra).toggle();
  });
  

});

