/*
---------------------------------------------
* jQuery-Plugin "Equal Width Navigation - DropDown"
* Version: 1.0, 1.1.2011
* by Lazarev Alexsandr, regatagroup@gmail.com
* Daronet Dev Group
---------------------------------------------
*/

Array.prototype.sum = function() {
		 return (! this.length) ? 0 : this.slice(1).sum() +
			((typeof this[0] == 'number') ? this[0] : 0);
};

function menu() {
	 var nav = $('ul.nav'),
		nav_item_height = 0,
		numMenuItems = $('> li', nav).size(),
		totalMenuItemWidth = 0,
		menuWidthRemainder = 0,
		wrapperWidth = 980,
		maxNavItemWidth = 200,
		priNavItems = new Array();
		
		//need for fast calculation render
		nav.css('visibility','visible');
		
	 /* First, determine the total width of each item in the navigation. */
	 $('> li', nav).each(function (i) {
		  totalMenuItemWidth += $(this).width();
		  priNavItems.push(($(this).width() > maxNavItemWidth) ? maxNavItemWidth : $(this).width());
	 });

 	/* Primary navigation items (combined) are less width than the
	 wrapper. */
 	if(totalMenuItemWidth < wrapperWidth) {
		  menuWidthRemainder = wrapperWidth - totalMenuItemWidth;

		  $('> li', nav).each(function() {
			   var tmp_width = $(this).width();
			   $(this).width(tmp_width + parseInt(menuWidthRemainder / numMenuItems));
		  });
    
				//add hover class to li el
				$('> li', nav).hover(function() {
							$(this).addClass('hover');
    }, function() {
      $(this).removeClass('hover');
    });																											
				
		  tmp_width = $('> li:first', nav).width();
	  	$('> li:first', nav).width(tmp_width + (menuWidthRemainder % numMenuItems));
	 }

}

$(document).ready(function(){
			menu();				
});


