window.addEvent('domready', function() 
{

var dropdown = null;

  $$('.navBar').each(function(li)
   {

	 li.getChildren().each(function(ul)
	   {
		 if( ul.getTag() == "ul" )
		 {
		   li.addEvent('mouseenter', function(e)
			 {
                           li.addClass('over');

                           if(ul.getChildren().length > 0)
			   {
			     dropdown = new Element('div', {'styles' : { 'top' : li.getStyle('height').toInt() } } ).addClass('test');
			     ul.clone().setStyle('display', 'block').injectInside(dropdown);
			     dropdown.inject(li);
			   }
			 });

		   li.addEvent('mouseleave', function(e)
			 {
                           $$('.over').each(function(l)
				{
                           	  l.removeClass('over');
				});

                           $$('.test').each(function(div)
				{
				  div.remove();
				});

			   //if(ul.getChildren().length > 0 && dropdown)
			//	 dropdown.remove();
			 });

		 }
	   });
   } );
});
