//topnav($('#top-nav'));

function topnav(ele) {
	
	
	activeWidth = ele.find('li.active').width() +8;
	
	 ele.find('li.active > ul').css({
		"background-position" : activeWidth+"px top"					 
	});
	
	ele.find('> li').hover(
		function(){ 
			$(this).addClass('active');
			items = $(this).find('ul:first').find('> li').not('.footer').length;		
			itemW = $(this).find('ul:first').find('li:first').width();			
			totalWidth = items * itemW;			
			itemss = $(this);
			itemP = itemss.position();
			newPos = 950 - itemP.left;			
			if (newPos < totalWidth) {
				newPos = totalWidth - newPos;				
				newer = itemP.left - newPos;				
				$(this).find('ul:first').css('left', newer+'px');					
			}
			
			if (items < 5) {				
				$(this).find('ul:first').css('width', totalWidth+'px');				
			} else {
				$(this).find('ul:first').css('left', '2px').css('width', '950px');
			}
			
			tTotal = itemP.left + totalWidth;			
			$(this).find('ul:first').stop().fadeIn(500);		
		}, 
		function(){ 
			$(this).removeClass('active');		
			$(this).stop(); $(this).find('ul:first').hide();
		}
	)
}
