
$(document).ready(function() {

  $('ul#portfolio').innerfade({
    speed:1000,
	timeout:5000,
	type:'random_start',
	containerheight:'180px'
  });

  $('a.top').click(function(){
    $.scrollTo('body',800);
    return false;
  });

  $('#menu_categories a').click(function() {
    if ($(this).filter('.collapsed').length) {
      $(this).addClass('expanded').removeClass('collapsed').find('+ ul').slideToggle('medium');
    } else if ($(this).filter('.expanded').length) {
      $(this).addClass('collapsed').removeClass('expanded').find('+ ul').slideToggle('medium');
    }
  });

  $('.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();
  });

  $("a[rel='colorbox']").colorbox({});
  $("a[rel='colorbox-gal']").colorbox({});
  $("a[rel='colorbox-html']").colorbox({fixedWidth:"650",fixedHeight:"550", iframe:true});

  $("#slider").easySlider({
    controlsBefore: "<p id='controls'>",
    controlsAfter: "<\/p>",
    auto: false,
    continuous: true
  });

  $('a.tooltip').qtip({
    position: {
      corner: {
        target: 'topMiddle',
        tooltip: 'bottomMiddle'
      },
      adjust: {
        y:7
      }
    },

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

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

      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:7
          }
        },

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

  $("ul#menu_header li").hover(function(){
    $(this).addClass("hover");
    $('ul:first',this).css('visibility', 'visible');
  }, function(){
    $(this).removeClass("hover");
    $('ul:first',this).css('visibility', 'hidden');
  });

  $("a.info_membre").click(function () {
      var mostra = $(this).attr('id');
      $('#info_'+mostra).toggle();
  });

  $("a.history").click(function () {
      var mostra = $(this).attr('rel');
      $('#'+mostra).toggle();
  });

});