// Inline eXpandable Lists
//
// Please set the following variables to initiate.

// DIRECTIONS: step 1 --> Build your navigation using an unordered list (<ul> <li></li> </ul>). 
// All sub-lists will become drop-drop lists. To make sure this works correctly, be sure to 
// nest your lists correctly. (Sub list <ul>'s must go INSIDE the <li> tag!) For correct 
// list html visit http://www.w3schools.com/Html/html_lists.asp and notice the part about 
// nested lists.
//
// step 2 --> Make sure that all of your list items that are parents to a sub list are empty
// links (<a href="#"></a>). The functionality is applied to the empty links. If they are not
// there, users will not be able to expand/collapse the navigation.
//
// step 3 --> Link to the correct javascript files. There are two javascript files that are
// necessary to link to. They are "jq.js" and "jq-foL.js". The first is the jQuery JS library
// the second is THIS FILE. Link the scripts using the <script> tag in the HEAD of your document.
// example: <script language="javascript" type="text/javascript" src="path/to/jq.js"></script>
//
// step 4 --> Configure ixL by customising the following variables. Each has a description:

// Enter a CSS selector for the lists that you want to be expandable. This should select an 
// unordered list tag (<ul>). (example: ul.expandList, ul#navigation).
var cssTarget="ul.foL";

// Appear effect: to turn on, set this value to "slow", "normal", or "fast". To turn off, leave empty (e.g. "")?
var effectSpeed="";

//All done. Don't edit below this line.
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

$(function() {
	$('ul.foL').find('li ul').each(function(){
		$(this).parent().hover(function(){
			$(this).children('ul').show(effectSpeed);
			var winheight=$(window).scrollTop()+$(window).height();
			var menudims=$(this).children('ul').offset();
			var menuheight=$(this).children('ul').height();
			var menubottom=menuheight+(menudims.top);
			if (menubottom>winheight) {
				var newtop=winheight-menuheight-5;
				var calculatedtop=newtop-menudims.top;
				$(this).children('ul').css('top',calculatedtop);
			}
		},function(){
			$(this).children('ul').hide(effectSpeed);
			$(this).children('ul').css('top',0);
		});
	});
});