$(document).ready(function() {

	// recruitment services dropdown
	
    var config = {    
         sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
         interval: 1,  // number = milliseconds for onMouseOver polling interval    
         over: doOpen,   // function = onMouseOver callback (REQUIRED)    
         timeout: 200,   // number = milliseconds delay before onMouseOut    
         out: doClose    // function = onMouseOut callback (REQUIRED)    
    };

	function doOpen() {
	    $(this).addClass("hover");
	    $("ul:first",this).addClass("hover").hide().fadeIn("fast");
	}

	function doClose() {
	    $(this).removeClass("hover");
	    $("ul:first",this).removeClass("hover").hide();
	}

	// Move to below (Recruitment sub nav section) - Chris Lugg
	//$("li#nav-main-recruitment-services").hoverIntent(config);
	

	// client-accordion

	$("#client-accordion dt a").hover(function(event) {
		$(this).parent().children(".icon").css("display","block");
		}, function() {
		$(this).parent().children(".icon").css("display","none");			
	});
	




		$("#client-accordion dd").hide();
        $("#client-accordion dt a").click(function() {
          $(this).parent().parent().children("dd").slideToggle("fast").parent().toggleClass("active")
          .siblings().children("dd:visible").slideToggle("fast").parent().toggleClass("active");
			return false;
        });


	// module-tabbed
//	$("#module-tabbed div:not(:first)").hide();
	$("#module-tabbed div").hide();
	$("#module-tabbed div:first").fadeIn(); // Show the first div
	$("#module-tabbed .tabs li:first a").addClass('active'); // Set the class for active state

	$("#module-tabbed .tabs li a").click(function(){
		$("#module-tabbed .tabs li a").removeClass('active');
		$(this).addClass('active');
		var contentID = $(this).attr('href'); // Set contentID to value of href attribute
		$("#module-tabbed div").hide(); 
		$(contentID).fadeIn(); // Show div with id equal to variable contentID
		return false;
		
	});


	/**
	 * JQuery code added by Chris Lugg
	 */
	
	/**
	 * Main navigation
	 */
	jQuery("div#nav-main li").each( function() {
											   
		var link = jQuery(this).find('a');
		
		// If this is the home page
		if (location.pathname == '/' && link.attr('href') == '/') {
			jQuery("div#nav-main li a").removeClass("on");
			link.addClass("on");
			
		// Check to see if this is a top level nav item
		} else if ((location.pathname.indexOf(link.attr('href')) > -1) && link.attr('href') != '/') {
			jQuery("div#nav-main li a").removeClass("on");
			link.addClass("on");
			
		// Is this a sub page (We're using the Breadcrumbs to work this out - is there a better way?)
		} else {
			jQuery("div#breadcrumbs a").each( function() {							
				if ((jQuery(this).attr('href').indexOf(link.attr('href')) > -1) && jQuery(this).attr('href') != '/') {
					jQuery("div#nav-main li a").removeClass("on");
					link.addClass("on");
				}
			});
		}
	});

	/**
	 * Recruitment Services sub menu
	 *
	 * Ok so we are having to hard-code this, which means if someone renames the recruitment services page
	 * this will no longer work.
	 */
	var recruitment_page_url = "/recruitment-services";
	var is_recruitment_page = false;
	var is_recruitment_sub_page = false;
	
	jQuery("div#nav-main li").each( function() {
											   
		var link = jQuery(this).find('a');	

		if ((location.pathname == recruitment_page_url) && (link.attr('href') == recruitment_page_url)) {
			link.prevObject.addClass("hover");
			is_recruitment_page = true;
		// Is this a sub page (We're using the Breadcrumbs to work this out - is there a better way?)
		} else {
			jQuery("div#breadcrumbs a").each( function() {	
				if ((jQuery(this).attr('href').indexOf(link.attr('href')) > -1) && jQuery(this).attr('href') == recruitment_page_url) {
					is_recruitment_sub_page = true;
					link.prevObject.addClass("hover");
				}
			});
		}
		
	});
	
	// If were not a recruitment page or recruitment sub page then active the hover menu
	if (is_recruitment_page === false && is_recruitment_sub_page === false) {
		$("li#nav-main-recruitment-services").hoverIntent(config);	
	}


	/**
	 * Date picker for Register with us form
	 */
	$("#availability_date").datepicker({ 
		dateFormat: 'dd/mm/yy' 
	});
});


