/***********************************************************************************************************************
DOCUMENT: javascripts/accordion-menu.js
DESCRIPTION: This is the JavaScript required to create the accordion style menu.  Requires jQuery library
************************************************************************************************************************/

$(document).ready(function() {
	
	/********************************************************************************************************************
	SIMPLE ACCORDION STYLE MENU FUNCTION
	********************************************************************************************************************/	
	$('div.accordionButton').click(function() {
	
		// check if 'opened' class already exists
		if($(this.children).is('.opened')){ // it exists, so we want to close everything and reset
			$('div.accordionContent').slideUp(250); // close all content
			$('div.accordionButton > a').removeClass('selected opened'); // remove 'selected' class to reset arrow image
		}else{ // it doesn't exist
			$('div.accordionButton > a').removeClass('selected'); // remove 'selected' class to reset arrow image			
			$('div.accordionContent').slideUp(250); // close all content		
			$(this).next().slideToggle(250); // expose the content next to the clicked item				
			$(this.children).addClass('selected opened'); // add 'selected' and 'opened' class to update arrow image			
		}
			
	});
		
	/********************************************************************************************************************
	CLOSES ALL OPEN PANELS
	********************************************************************************************************************/
	$('a.accordionCloserAll').click(function() {
	
		$('div.accordionContent').slideUp(250); // close all content
		$('div.accordionButton > a').removeClass('selected'); // remove 'selected' class to reset arrow image
		$('div.accordionButton > a').removeClass('opened'); // remove 'opened' class
		
	});
	
	/********************************************************************************************************************
	CLOSES INDIVIDUAL PANEL
	********************************************************************************************************************/
	$('a.accordionCloserSolo').click(function() {
	
		var myParentNode = this.parentNode; // remember the parent accordion content
		$(myParentNode).slideUp(250); // close the parent accordion content
		
	});
	
	/********************************************************************************************************************
	REVEAL "WHAT EXACTLY IS DRIVERS EDUCATION AND DRIVERS TRAINING?"
	********************************************************************************************************************/
	$('a.education-training-trigger').click(function() {
		$('div.accordionContent.education-training').slideToggle(250);
	});
	
	/********************************************************************************************************************
	CLOSES ALL DIVS ON PAGE LOAD
	********************************************************************************************************************/	
	$('div.accordionContent').hide();
	
	/********************************************************************************************************************
	OPEN FIRST ACCORDION ITEM
	********************************************************************************************************************/
	//$('div.accordionButton:first > a').addClass('selected opened');
	//$('div.accordionContent:first').show();
	
	/********************************************************************************************************************
	ADD/Remove focus-field for input fields
	********************************************************************************************************************/	
	$('form input').blur(function() {
		$(this).removeClass("focus-field");
	})
		.focus(function() {                
		$(this).addClass("focus-field")
	});		
	
});

//Function used to scroll smoothly to an id passed as a parameter
function scrollWin(e){ 
	$('html, body').animate({ scrollTop: $(e).offset().top	}, 750);
}

//Function used to focus on the first input of a form id passed as a parameter
function focusFirstInput(e){
	var target = e + ' input:first';

	$(target).focus().addClass('focus-field');
		
	scrollWin("#signup");
}

//Function used to simulate a click on any given target. 
//You can specify the dom id for window to scroll to as an optional parameter
function simulateClick(e, id){
	var target = e;
	var scrollID = id;
	
	if(scrollID != undefined){
		scrollWin(scrollID);
	}
	
	$(target).click();
}

//Function used to expose an element passed as a parameter - NOTE: jQuery Tool javascript file must be loaded
//Hard - can't close on click
function exposeElementHard(e){
	var target = e;
	
	$(target).expose({
	
		api:					true,
		closeOnClick:	false,
		lazy:					true, 
		maskId:				'mask',
		
		onBeforeLoad: function() {
			this.fit(); // this re-sizes the expose overlay to fit the screen width and height
		}
	
	}).load();
	
	scrollWin("#signup");
	
}
//Soft - can close on click
function exposeElementSoft(e){
	var target = e;
	
	$(target).expose({
	
		api:					true,
		closeOnClick:	true,
		lazy:					true, 
		maskId:				'mask',
		
		onBeforeLoad: function() {
			this.fit(); // this re-sizes the expose overlay to fit the screen width and height
		}
	
	}).load();
	
	scrollWin("#signup");
	
}
