

function spectrum() {
  var hue = 0.5 + (Math.random());
  var delay = Math.floor(1000 + Math.random()*5000);
  $('#tira_img').animate({opacity:hue},delay,"linear", function() {
    timer = setTimeout(spectrum, 0);
  });
}


$(document).ready(function() {

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

  $("#cat_principal").msDropDown();
  $("#cat_principal_child a").click(function(evento) {
    $rel_aux = $(this).attr('rel');
    if ($rel_aux.substr(0,7)=='subcat_') {
      $("ul[id^='subcat_']").hide({});
      $("#menu_auxiliar").hide({});    
      $("#info_aux").hide({});
      $("#logo_glam").show({});
      $('#'+$rel_aux).show({});

      if ($("#menu_auxiliar").length && $('#'+$rel_aux).hasClass('visible')) {
        $("#menu_auxiliar").show({});
        if ($("#info_aux").length){
          $("#logo_glam").hide({});
          $("#info_aux").show({});
        }
      }
    } else {
      $("ul[id^='subcat_']").hide({});
      $("#menu_auxiliar").hide({});
      location.href = 'http://www.glamcomunicacio.com/' + $rel_aux;
    }
  });

  $('.send_form').click(function() {
    $('#'+$(this).parents("form").attr("id")).submit();
    evento.preventDefault();
  });

  $('.check_form').click(function(evento) {
    if(check_form()) {
      $('#'+$(this).parents("form").attr("id")).submit();
    }
    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:"580", iframe:true});

  $('#menu_main a.collapsed').click(
    function() {
      var nom = $(this).html();
      $('#menu_name').html(nom);
      var actual = $(this).closest('ul').attr('id');
      $('#'+ actual).hide();
      var mostra = $(this).attr('rel');
      $('#'+ mostra).show();
    }
  );

  $('#prev_menu').click(
    function(evento) {
      $('#menu_name').html('');
      $("ul[id^='menu_lateral']").hide({});
      $("#menu_lateral").show({});
      evento.preventDefault();
    }
  );
  
  spectrum();

});

