jQuery.fn.exists = function() { return (this.length > 0); };

function initMenu() {
$('#menu ul').hide();
$('#menu ul:first').show();
$('#menu li a').click(
function() {
if($(this).next().exists() && $(this).attr("href") == "#")
{
var checkElement = $(this).next();

if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
return false;
}
if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
$('#menu ul:visible').slideUp('normal');
checkElement.slideDown('normal');
return false;
}
}
}
);
}
$(document).ready(function() {initMenu();});
