$(function() {
	$('#nav ul').each(function() {
		
		$('>li:last>a', this).addClass('last');
		
	});
	
	$('#nav ul.level2').each(function() {
	
		var listLevel = $(this).attr('class').replace('level', '');
		var listWidth = $(this).width();
		var parentWidth = $(this).parents('li:first').find('img:first').width();
		var listPosition;
		
		switch (level2Postion) {
			case 'left':
				listPosition = 0;
				break;
			case 'center':
				listPosition = (parentWidth -  listWidth) / 2;
				break;
			case '':
				listPosition = $(this).css('left');
				break;
			default:
				listPosition = level2Postion;
				break;
		}
		
		$(this).css('left', listPosition);
	
		if (level2ActiveOn == true) {
			if ($(this).parents('li:first').find('>a').hasClass('active')) $(this).fadeIn(0);
		}
		
	});
	
	$('#nav ul li').mouseenter(function() {
		
		if (!rolloverMenus) { return; };
	
		if ($('a>img', this).length > 0) {
			var imagePathInfo = $('a:first>img', this).attr('src').replace('_over', '').split('.');
			var imagePath = imagePathInfo.slice(0, -1).join('.');
			var imageExtension = imagePathInfo[imagePathInfo.length - 1];
			
			$('a:first>img', this).attr('src', imagePath + '_over' + '.' + imageExtension);
			
			$('a:first', this).addClass('over');
		}
		
		$('>ul', this).fadeIn(0);
		
	}).mouseleave(function() {
		
		if (!rolloverMenus) { return; };
	
		if ($('a>img', this).length > 0) {
			var imagePathInfo = $('a:first>img', this).attr('src').replace('_over', '').split('.');
			var imagePath = imagePathInfo.slice(0, -1).join('.');
			var imageExtension = imagePathInfo[imagePathInfo.length - 1];
		
			if (!$('a', this).hasClass('active')) {
				$('a:first>img', this).attr('src', imagePath + '.' + imageExtension);
			}
			
		}
		
		$('>ul', this).fadeOut(0);
		$('a:first', this).removeClass('over');
		
	});
	
});

var rolloverMenus = false;
var level2Postion = '';
var level2ActiveOn = true;
