//------------------------------------------------------------------------------------
//---------------Functionality to compliment CSS powered drop down menus--------------
//------------------------------------------------------------------------------------

$(document).ready(function() {
						   
						
    	//$('#tea_submenu ul li ul li a').prepend('&mdash; ');
		$('#tea_submenu ul li ul li a').prepend('&nbsp;&nbsp; ');
		$('#tea_submenu ul').css('display', 'block');
	//$('#tea_submenu  ul li.current_page_ancestor').hide();
	$("#tea_submenu ul").simpletreeview({
	
		open:  "&#9660;&nbsp;",   // HTML string to display for the opened handle
	close: "&#9658;&nbsp;",   // HTML string to display for the closed handle
		slide: true,       // Boolean flag to indicate if node should slide open/close
		speed: 'normal',    // Speed of the slide. Can be a string: 'slow', 'fast', or a number of milliseconds: 1000
	collapsed: true,   // Boolean to indicate if the tree should be collapsed on build
	collapse: null,     // A node to collapse on build. Can be a string with indexes: '0.1.2' or a jQuery ul: $("#tree ul:eq(1)")
	expand: $('#tea_submenu  ul li.current_page_ancestor ul')       // A node to expand on build. Can be a string with indexes: '0.1.2' or a jQuery ul: $("#tree ul:eq(1)")	
		
	});
	$('#tea_submenu .current_page_item span.handle').trigger('click');
	$('span.handle').unbind('click');
	
 
						   
	////Create the decoration for the active member of the submenu
//	var left = $("<span class='left'>[&nbsp;</span>");
//	var right = $("<span class='left'>&nbsp;]</span>");
//	
//	//Put the active decoration on the current page item in the submenu
//	var left_clone = left.clone();
//	left_clone.prependTo('#navigation ul li ul li.current_page_item a');
//	right.clone().appendTo('#navigation ul li ul li.current_page_item a');
//	
//	//Account for the discrepancy in the padding due to addition of new characters
//	var width = left_clone.width();
//	var padding = $('#navigation ul li ul li.current_page_item').css('padding-left');
//	padding = parseInt(padding);
//	var new_padding = padding - width;
//	$('#navigation ul li ul li.current_page_item').css('padding-left', new_padding);
//	$('#navigation ul li ul li.current_page_item').css('padding-right', new_padding);
	
	//Reveal the submenu of the current parent page	
	$('#navigation ul li.current_page_parent ul').css('left', 'auto');
	$('#navigation ul li.current_page_item ul').css('left', 'auto');
		

	//Function to hide the current parent page submenu when another parent menu item is hovered over
	//$('#navigation li:not(ul li ul li)').mouseenter(function() {
	$('#navigation li:not(ul li ul li)').bind('mouseenter', function() {
	
		if($(this).hasClass('current_page_parent')){
		
		}
		else{
			$('#navigation ul li.current_page_parent ul').css('left', '-999em');		
		}
		
		if($(this).hasClass('current_page_item')){
			
		}
		else{
			$('#navigation ul li.current_page_item ul').css('left', '-999em');		
		}
	});
	//Function to restore the current parent page submenu when mouse leaves navigation region
	//$('#navigation li:not(ul li ul li)').mouseleave(function() {
	$('#navigation li:not(ul li ul li)').bind('mouseleave', function() {
	
		if($(this).hasClass('current_page_parent')){
		
		}
	
		else{
			$('#navigation ul li.current_page_parent ul').css('left', 'auto').hide().fadeIn(100);
		}	
		if($(this).hasClass('current_page_item')){
		
		}
	
		else{
			$('#navigation ul li.current_page_item ul').css('left', 'auto').hide().fadeIn(100);
		}	
	});
	
	//Function to add the active decoration to the submenu items
	//$('#navigation ul li ul li').mouseenter(function(new_padding) {
	//$('#navigation ul li ul li').bind('mouseenter', function() {
//													  
//		if($(this).hasClass('current_page_item')){
//			return;
//		}
//		else{
//			var menu_link = $('a', this);
//			left.prependTo(menu_link);
//			right.appendTo(menu_link);
//			//Deal with the padding discrepancy caused by the addition of four new characters [  ]
//			var width = left.width();
//			var new_padding = 20 - width;
//			
//			$(menu_link).css('color', '#cb2566');
//			
//			$(this).css('padding-left', new_padding);
//			$(this).css('padding-right', new_padding);
//		}
//	});	

//	//Function to remove the active decoration from the submenu items	
//	//$('#navigation ul li ul li').mouseleave(function() {
//	$('#navigation ul li ul li').bind('mouseleave', function() {
//		
//		if($(this).hasClass('current_page_item')){
//			return;
//		}
//		else{
//			var menu_link = $('a', this);
//			$(left, menu_link).remove();
//			$(right, menu_link).remove();
//
//			$(menu_link).css('color', '#d7d7d7');
//			
//			$(this).css('padding-left', '20px');
//			$(this).css('padding-right', '20px');
//		}
//
//	});
	
	$('#tea_submenu .current_page_item').parent().show();
	//page_item page-item-383 current_page_parent current_page_item
	var numItems = $('#main-nav .current_page_item').length;
	if(numItems>1){
		
	}
	$('#main-nav .page-item-383').removeClass('current_page_parent');
	
});

