var $ = jQuery.noConflict();

$(document).ready(function(){
	
	$('table.seepra tr:even').css("background-color", "#f1f1f1");
	
	
	var current;
		
	current = $('.current-menu-item').attr('id');
	
	if ($('.current-menu-ancestor').size() == 0) {
			
		// If ancestor count is 0, we must currently be at top level menu
		$('#'+current+' .sub-menu').show();
		
		$('#menu-paavalikko .menu-item').mouseover(
			function() {
				// Remove selected.png from .current-menu-item
				$('#'+current).removeClass('current-menu-item');
				// If .current-menu-item has sub-menu, hide it.
				$('.sub-menu').hide();
				// Show this's sub-menu 
				$(this).children('.sub-menu').show();
				$(this).addClass('hover');
			}
		);
		
		$('#menu-paavalikko .menu-item').mouseleave(
			function() {
				// When mouse leaves, put selected.png back to .current-menu-item
				$('#'+current).addClass('current-menu-item');
				// Hide any other .sub-menus
				$(this).children('.sub-menu').hide();
				// Show again .sub-menu from current menu item.
				$('#'+current).children('.sub-menu').show();
				$(this).removeClass('hover');
			}
		);
	} else {
		
		// ... else we are at sub-menu level
		$('#'+current).parent().show();
		
		$('#menu-paavalikko .menu-item').mouseover(
			function() {
				$('#'+current).parent().parent().removeClass('current-menu-ancestor');
				$('.sub-menu').hide();
				$(this).children('.sub-menu').show();
			}
		);
		
		$('#menu-paavalikko .menu-item').mouseleave(
			function() {
				$('#'+current).parent().parent().addClass('current-menu-ancestor');
				$(this).children('.sub-menu').hide();
				$('#'+current).parent().show();
			}
		);
		
	}

});
