
$(document).ready(function() {

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

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

	$('#menu_categories a').click(
		function() {
			var checkElement = $(this).next();

			/* Quan és visible... tancar-lo */
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				$(this).addClass('collapsed').removeClass('expanded');
				checkElement.slideUp('normal');
				return true;
			}

			/* Quan no és visible...obrir-lo, i abans tancar els del mateix nivell */
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$(this).parent().parent().find('a.expanded').eq(0).addClass('collapsed').removeClass('expanded');
				checkElement.parent().parent().find('ul').slideUp('normal');
				$(this).addClass('expanded').removeClass('collapsed');
				checkElement.slideDown('normal');
				return true;
			}
		}
	);

  $('.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:"672",fixedHeight:"445", iframe:true});

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

});

