Help finish the script menu

Help finish the script menu

html:
<ul class="menu"> <li><a href="#">My Account</a> <ul class="sub-menu"> <li><a href="#">Главная 2</a></li> <li><a href="#dashboard" >Dashboard</a></li> </ul> </li> <li><a href="#dashboard" >Dashboard</a> <ul class="sub-menu"> <li><a href="#">Главная 2</a></li> <li><a href="#dashboard" >Dashboard</a></li> </ul> </li> <li><a href="#signout">Sign Out</a></li> </ul>
Script:
$(document).ready(function() { $('ul li').has('ul').addClass('include'); $(".include").click(function() { var X = $(this).attr('id'); if(X == 1) { $(".sub-menu").hide(); $(this).attr('id', '0'); } else { $(".sub-menu").show(); $(this).attr('id', '1'); } }); //Mouseup textarea false $(".sub-menu").mouseup(function() { return false }); $(".include").mouseup(function() { return false }); //Textarea without editing. $(document).mouseup(function() { $(".sub-menu").hide(); $(".include").attr('id', ''); }); });
As is now open:
Assigns li element that has a level ul, class styles.
Defines an element to add a class and evaluates the id of the element.
By clicking on an element, it is set id = 1, which means that it is displayed.
Pressing the element (id = 0), the menu disappears.
The same may be gone when you click anywhere on the page.
When you click on any expansion items disclosed everything.

task:
Count the total number of items that have a li a ul level and assign a serial number in the form id.
Make it so that when you click on a particular drop-down list just dropped it, but not all at once, and sometimes in the same place.
Add a feature in which Button is assigned to a class that has a li element to the level ul, acquired an additional class of the clicked item.