/*
	Thraw-doon nav
	Copyright © 26th August 2011 Jake Nicholson (www.eskdale.net)
*/
(function($){
	$.fn.navs = function(){
		var els = $(this).children('ul').children('li');
		var len = els.length;
		var half = parseInt(Math.floor(len/2));
		
		if(half === parseFloat(len/2)){
			var mid = 0;
		} else {
			var mid = half + 1;
		};
		
		$(els[i]).children('ul').css('left','-1px');
		
		var i = 0;
		
		var a = 0;
		var b = 980;
		
		do{
			a = $(els[i]).width();
			b = b - a;
			i++;
		}
		while(els[i]!==undefined);
		
		$(els).each(function(){
			$(this).children('a').css({'padding-left':b/(parseFloat(len*2))+'px','padding-right':b/(parseFloat(len*2))+'px'});
		});
		
		do{
			a = $(els[i]).width();
				
				if(i < half){
					$(els[i]).children('ul').css('left','-1px');
				} else {
					$(els[i]).children('ul').css({'left':a-221+'px','border-radius':'5px','border-top-right-radius':'0px'});
				};
			
			i++;
		}
		while(els[i]!==undefined);
		
		i = 0;
		
		if(mid!==0){
			var width = $(els[mid-1]).width();
			var childwidth = $(els[mid-1]).children('ul').width();
			var offset = (width - childwidth)/2;
			$(els[mid-1]).children('ul').css({'left': offset+'px','right':offset+'px','border-radius':'5px'});
		};
		
		$(this).find('li > ul').hide();
		$(this).find('li').hover(function(){
			$(this).find('ul').hide().slideDown(800);
		},function(){
			$(this).find('ul').stop(true,true).fadeOut(800);
		});
	};
})(jQuery);
