var elements = [
  ['livet'   ,0],
  ['kirken'  ,0],
  ['personer',0],
  ['opgaver' ,0],
  ['andrereligioner' ,0],
  ['bibelen' ,0]
];

function isReady(name)
{
  for(var i=0;i<elements.length;i++)
  {
    if(elements[i][0] == name && elements[i][1] == 1)
      return false;
  }
  return true;
}

function setReady(name)
{
  for(var i=0;i<elements.length;i++)
  {
    if(elements[i][0] == name)
      elements[i][1] = 0;
  }
}

function setBusy(name)
{
  for(var i=0;i<elements.length;i++)
  {
    if(elements[i][0] == name)
      elements[i][1] = 1;
  }
}


function bounce(name){
  $(document).ready(function() {
    $("#" + name + " .header-menu-textimage").mouseover(function()  {
      if(isReady(name)){
        setBusy(name);
        $("#" + name + " .header-menu-icon")
         .animate({bottom:"+=20px"},150)
         .animate({bottom:"-=20px"},150)
         .animate({bottom:"+=20px"},150)
         .animate({bottom:"-=20px"},150)
         .animate({bottom:"+=20px"},150)
         .animate({bottom:"-=20px"},150,null, function(){setReady(name)});
       }
     });
     
    $("#" + name + " .header-menu-icon").mouseover(function()  {
      if(isReady(name)){
        setBusy(name);
        $("#" + name + " .header-menu-icon")
         .animate({bottom:"+=20px"},150)
         .animate({bottom:"-=20px"},150)
         .animate({bottom:"+=20px"},150)
         .animate({bottom:"-=20px"},150)
         .animate({bottom:"+=20px"},150)
         .animate({bottom:"-=20px"},150,null, function(){setReady(name)});
       }
     });    
     
  });
}


bounce('livet');
bounce('kirken');
bounce('personer');
bounce('opgaver');
bounce('andrereligioner');
bounce('bibelen');

