// JavaScript Document
// Code runs after DOM has loaded

$(document).ready(function() {
						   
	function hoverOver(){    
            	$('.sub').slideDown('fast','easeInOutCubic');
			}			
			
			function hoverOut(){
				$('#mainMenu a.heading').removeClass('highlight');	    
            	$('.sub').slideUp('fast');
			}
			
			function getFilename() {
				// returns the filename of the current page
				var path = String(location);	
				var pos1 = path.indexOf(".ca/") + 3;
				var pos2 = path.lastIndexOf("#");
				if (pos2 >= 0) {
					var filename = path.substring(pos1, pos2);
				} else {
					var filename = path.substring(pos1);
				}
				
				if (filename=="") filename="index.php";
								
				return filename;
			}
            			
			var config = {    
		 		sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)    
		 		interval: 20, // number = milliseconds for onMouseOver polling interval    
		 		over: hoverOver, // function = onMouseOver callback (REQUIRED)    
		 		timeout: 300, // number = milliseconds delay before onMouseOut    
		 		out: hoverOut // function = onMouseOut callback (REQUIRED)    
			};
			
			// hide all subs on load
			$('.sub').hide();
			
			$("#mainMenu").hoverIntent(config);
            
			$('li.groupWrap').mouseover(function() {
				$('#mainMenu a.heading').removeClass('highlight');				
				$(this).find('a.heading').addClass('highlight');														
			});
			
			$('#mainMenu').mouseout(function() { $('#mainMenu a.heading').removeClass('highlight'); });
				
			
			$('.sub li a').each(function() {    // find the selected link and add the class "selected" to it
										 										 
				if ($(this).attr("href")==getFilename()) {
					$(this).addClass("selected");
					return false;
				}
			});
			
			
	
});
