var movedownvar = objheight = moveupvar = 0;
var speed = 4;


function openclose(id, section) {
  //$('.surprise').hide('slow');
  //$('#news_'+id).show('slow', showcontroller());
  $("#news_list_eventi").css('top', 0);
  $("#news_list_patologia").css('top', 0);
  $('.surprise').hide('slow',function() {showcontroller(section)});
  $('#news_'+id).show('slow', function() {showcontroller(section)});
  // Rileva la dimensione massima del box
}

function showcontroller(section) {
  var sections = new Array('patologia', 'eventi');
  div_container = '#news_'+section;

  objheight = $("#news_list_"+section).height();
  for(var i=0; i<sections.length; i++) {
    s = sections[i];
    div_cont = '#news_'+s;
    objh = $("#news_list_"+s).height();
    if(objh < parseInt($(div_cont).height())) {
      $("#down_"+s).hide();
      $("#up_"+s).hide();
    } else {
      $("#down_"+s).show();
      $("#up_"+s).show();
    }
  }
}
$(document).ready(function() {
  $("#down_patologia").hover(function(){       // Caso Over Down
     movedown('patologia')
  },function(){
     clearTimeout(movedownvar);
  });
  $("#up_patologia").hover(function(){        // Caso Over Up
     moveup('patologia')
  },function(){
     clearTimeout(moveupvar);
  });
  $("#down_eventi").hover(function(){       // Caso Over Down
     movedown('eventi')
  },function(){
     clearTimeout(movedownvar);
  });
  $("#up_eventi").hover(function(){        // Caso Over Up
     moveup('eventi')
  },function(){
     clearTimeout(moveupvar);
  });
});

      function movedown(section)
      {
        s_pos = parseInt($("#news_list_"+section).css("top"));

       if (s_pos >=(objheight*(-1)+100))
            $("#news_list_"+section).css('top', s_pos -= speed);

        movedownvar=setTimeout("movedown('"+section+"')",50);
      }

      function moveup(section)
      {
        s_pos = parseInt($("#news_list_"+section).css("top"));

        if (s_pos<=0)
            $("#news_list_"+section).css('top', s_pos += speed);

 moveupvar=setTimeout("moveup('"+section+"')",50);
      }