// Listed menu script.  
/*
 * Sets the toggle and cookies for the toggle state
 */
 var t;
var upText = '[<]';
var downText = '[>]';
var hoverIntentConfig = {    
     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     interval: 200, // number = milliseconds for onMouseOver polling interval    
     over: showChildren, // function = onMouseOver callback (REQUIRED)    
     timeout: 700, // number = milliseconds delay before onMouseOut    
     out: hideChildren // function = onMouseOut callback (REQUIRED)    
};




/* Scroll Pane */
function loadScrollPane(item) {
	$(item).jScrollPane({scrollbarWidth:10,dragMaxHeight:2, showArrows:true, reinitialiseOnImageLoad: true});
};

$(function() {
	loadScrollPane('div.ml_children ul.top');
});
 
$(document).ready(function() {
	toggleChildren();
	//$('div.ml_parent a').hoverIntent(hoverIntentConfig);
	//$('div.ml_children a').hoverIntent(hoverIntentConfig);
	$('div.ml_parent a').hover(function() {
	  clearTimeout(t);
    showChildren();
	},
	function() {
    t = setTimeout(function() {
      hideChildren();
    },700);
  });
	
	$('div.ml_children').hover(function() {
	  clearTimeout(t);
    showChildren();
	},
	function() {
    t = setTimeout(function() {
      hideChildren();
    },700);
  });
	
});



function showChildren() {
	
	$('div.ml_children').show("slow");
	$('#ml_padder').hide("slow");
	$('#ml_toggle').text(downText);
};

function hideChildren() {
		if($.cookie('ml_toggle_state') == 'up') {
			$('div.ml_children').hide("slow");
			$('#ml_padder').show("slow");
			$('#ml_toggle').text(upText);
		};
};
	
function toggleChildren() {
	
	if($.cookie('ml_toggle_state') == 'up') {
		$('div.ml_children').hide();
		$('#ml_padder').show();
		$('#ml_toggle').text(upText);
	}
	else {
		$('#ml_toggle').text(downText);
	}
													 
	$('#ml_toggle').click(function() {
		$('div.ml_children').toggle("slow");
		$('#ml_padder').toggle("slow");
		if($('#ml_toggle').text() == upText) {
			$('#ml_toggle').text(downText);
			$('#ml_toggle').removeClass('up');
			$('#ml_toggle').addClass('down');
		}
		else {
			$('#ml_toggle').text(upText);
			$('#ml_toggle').removeClass('down');
			$('#ml_toggle').addClass('up');
		}
		// Read cookie, and change every toggle
		if($.cookie('ml_toggle_state') == 'up') {
			$.cookie('ml_toggle_state', 'down');
		}
		else {
			$.cookie('ml_toggle_state', 'up');
		}
		loadScrollPane('div.ml_children ul');
	});
};