/*

	metlife-demo.js:
	A demonstration of some of the expected interactivity that will be added to the MetLife site.

	
*/

$(document).ready(function() {

			
	/*
	
		Accordion functionality for sidebar components.
		
	*/
		//Close all detail items
		$(".accordion .detail").hide();
		
		//Open the first pane for each accordion
		
		$(".accordion").each(function() {
			$("#"+this.id+" .toggler:first").addClass("selected");
			$("#"+this.id+" .detail:first").addClass("active");
			$("#"+this.id+" .detail:first").show();
		});
	
		//Create event handlers for the "toggler" headings so that when one is clicked on, it opens up. 
		$(".accordion .toggler a").bind("click", function() {
		
			var that = this;
			
			
				
				//Get the context of the parent node that contains all of the accordion panes
				var accordionContainer = that.parentNode.parentNode.id;
				
				
				//Hide the currently open accordion
				
				$("#"+accordionContainer+" div.active").slideUp( function(){
					
						/*$("#"+accordionContainer+" .toggler").removeClass("selected");
						$(that.parentNode).addClass("selected").next().slideDown().addClass("active");*/
				
						
					
				}).removeClass("active");
				
				if (!($(that.parentNode).is(".selected"))) {
					$("#"+accordionContainer+" .toggler").removeClass("selected");
					$(that.parentNode).addClass("selected").next().slideDown().addClass("active");
				}else{
					
					$("#"+accordionContainer+" .toggler").removeClass("selected");
				}
				
				
			return false;
		
		});
		
		
	/*
		#accordionstaff2 used in reg policy update
	*/
		
		$("#accordionStaff2 .togglebody").hide();
		
		//Open the first pane for each accordion
		
		//$("#open").trigger('click');
		/*$("#open").each(function() {
			$("#open .toggler").addClass("selected");
			$("#open .togglebody").addClass("active");
			$("#open .togglebody").show();
		});*/
		
		$("#accordionStaff2").each(function() {
			$("#"+this.id+" .toggleropen").addClass("selected");
			$("#"+this.id+" .togglebodyopen").addClass("active");
			$("#"+this.id+" .togglebodyopen").show();
		});
		
	
		//Create event handlers for the "toggler" headings so that when one is clicked on, it opens up. 
		$("#accordionStaff2 .toggler a").bind("click", function() {
		
			var that = this;
			
			//if (!($(that.parentNode).is(".selected"))) {
				
				//Get the context of the parent node that contains all of the accordion panes
				var accordionContainer = that.parentNode.parentNode.id;
				
				//Hide the currently open accordion
				
				$("#"+accordionContainer+" div.active").slideUp(function() {
				
					/*
						Once the slide up has finished, open the selected accordion pane:						
						- First, add the selected class to the header (parentNode)
						- Then, slide the corresponding div.detail (.next()) down, using the slideDown function.
						- Finally, add the active class to the corresponding div.detail item.
					
					*/
					
					//$(that.parentNode).addClass("selected").next().slideDown().addClass("active");
				
				
				}).removeClass("active");
				
				if (!($(that.parentNode).is(".selected"))) {
					$("#"+accordionContainer+" .toggler").removeClass("selected");
					$(that.parentNode).addClass("selected").next().slideDown().addClass("active");
				}else{
					
					$("#"+accordionContainer+" .toggler").removeClass("selected");
				}
	
			//}
			
			return false;
		
		});
		
		/*
			Accordionstaff used im most twisties
		*/
		
		$("#accordionStaff .togglebody").hide();
		
		//Open the first pane for each accordion
		
		/*$("#accordionStaffIn").each(function() {
			$("#"+this.id+" .toggler:first").addClass("selected");
			$("#"+this.id+" .togglebody:first").addClass("active");
			$("#"+this.id+" .togglebody:first").show();
		});*/
	
		//Create event handlers for the "toggler" headings so that when one is clicked on, it opens up. 
		$("#accordionStaff .toggler a").bind("click", function() {
			
			var that = this;
			
			
				
				//Get the context of the parent node that contains all of the accordion panes
				var accordionContainer = that.parentNode.parentNode.id;
				
				
				//Hide the currently open accordion
				
				$("#"+accordionContainer+" div.active").slideUp().removeClass("active");
				
				if (!($(that.parentNode).is(".selected"))) {
					$("#"+accordionContainer+" .toggler").removeClass("selected");
					$(that.parentNode).addClass("selected").next().slideDown().addClass("active");
				}else{
					
					$("#"+accordionContainer+" .toggler").removeClass("selected");
				}
	
			return false;
		
		});
		
		
		
		
		
	
		
	});


/*
	accordion used for our-team page
*/

	

function initMenus() {
		$('.accordiont ul.menu ul').hide();
		/*$.each($('ul.menu'), function(){
			$('#' + this.id + '.expandfirst ul:first').show();
		});*/
		$('.accordiont ul.menu li a').click(
			function() {
				var checkElement = $(this).next();
				var parent = this.parentNode.parentNode.id;
	
				if($('#' + parent).hasClass('noaccordion')) {
					$(this).next().slideToggle('normal');
					return false;
				}
				if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
					if($('#' + parent).hasClass('collapsible')) {
						$('#' + parent + ' ul:visible').slideUp('normal');
					}
					return false;
				}
				if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
					$('#' + parent + ' ul:visible').slideUp('normal');
					checkElement.slideDown('normal');
					return false;
				}
			}
		);
	}