/**
 * @author Vitaly
 */

 var timeoutId = null;
 var currentId = '';

 $(document).ready(
 	function() {
 		$('.all').hover(function(/* Event */ e) {
 			hideMenu();
 			var elem = $(e.target);
 			showMenu(elem.attr('id'), elem.position().top, elem.position().left);
 		}, function(/* Event */ e) {
 			var elem = $(e.target);
 		});
 		$('.criteria-box').hover(function(/* Event */ e) {
 			clearTimeout(timeoutId);
 		}, function(/* Event */ e) {
 			hideMenu();
 		});
 	}
 );

 /**
  * @param {String} id Id of the category
  * @param {Integer} top Top position value of the link
  * @param {Integer} left Left position value of the link
  */
 function showMenu(id, top, left) {
 	var elem = $('#criteria-box-' + id);
 	elem.css('top', top + 15 + 'px').css('left', left + 'px').show();
 	currentId = id;
 	timeoutId = setTimeout(hideMenu, 1000);
 }

 /**
  * @param {String} id Id of the category
  */
 function hideMenu() {
 	if (currentId) {
 		$('#criteria-box-' + currentId).hide();
	 	timeoutId = null;
	 	currentId = '';
 	}
 }