/***********************************************************************************************************************
DOCUMENT: includes/javascript.js
DEVELOPED BY: Ryan Stemkoski
COMPANY: Zipline Interactive
EMAIL: ryan@gozipline.com
PHONE: 509-321-2849
DATE: 3/26/2009
UPDATED: 3/25/2010
DESCRIPTION: This is the JavaScript required to create the accordion style menu.  Requires jQuery library
NOTE: Because of a bug in jQuery with IE8 we had to add an IE stylesheet hack to get the system to work in all browsers. I hate hacks but had no choice :(.
************************************************************************************************************************/

jQuery(document).ready(function() {
	
	/********************************************************************************************************************
	CLOSES ALL DIVS ON PAGE LOAD
	********************************************************************************************************************/	
	jQuery("div.accordionContent").hide();
	

	/********************************************************************************************************************
	OPENS THE DIV THAT IS WHERE THE USER WANTS TO GO FROM THE RFERERRING INSURANCE PAGE
	********************************************************************************************************************/	
	
	//GET THE URL ACTION PARAMETER
	var getAction = jQuery.url.param("action");
	
	//In the beginning all accordions are not shown
	var showAll = false;
		
	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	jQuery.each(jQuery('.accordionButton'), function(index, element) {	
	
		jQuery(this).css({'background': '#f3fdd6 url("/images/arrow_blue_down_2.gif") no-repeat 98% 50%'});

		jQuery(this).click(function() {		
		
			if(!showAll) {
				//REMOVE THE ON CLASS FROM ALL BUTTONS
				jQuery('.accordionButton').removeClass('on');
				
				jQuery('.accordionButton').css({'background': '#f3fdd6 url("/images/arrow_blue_down_2.gif") no-repeat 98% 50%'});
				  
				//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
				jQuery('.accordionContent').slideUp(1000);
				
			}
		   
			//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
			if(jQuery(this).next().is(':hidden') == true) {
				
				//ADD THE ON CLASS TO THE BUTTON
				jQuery(this).addClass('on');
				jQuery(this).css({'background': '#d1e0a3 url("/images/arrow_blue_up_2.gif") no-repeat 98% 50%'});

				 
				//OPEN THE SLIDE
				jQuery(this).next().slideDown(1000, function(){
					
					if(index!=0 && (getAction=="" || getAction==null) ) {
						jQuery.scrollTo(jQuery(this).prev(),1000,{axis:'y'});	
					}
					getAction = "";
				});
			}
		});
	});
	
	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	jQuery.each(jQuery('.accordionMenuButton'), function(index, element) {	

		jQuery(this).css({'background': '#f3fdd6 url("/images/arrow_blue_down_2.gif") no-repeat 98% 50%'});

		jQuery(this).click(function() {		
		
			jQuery('.accordionMenuButton').css({'background': '#f3fdd6 url("/images/arrow_blue_down_2.gif") no-repeat 98% 50%'});
		
			//REMOVE THE ON CLASS FROM ALL BUTTONS
			jQuery('.accordionMenuButton').removeClass('on');

			//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
			jQuery('.accordionContent').slideUp(1000);
		   
			//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
			if(jQuery(this).next().is(':hidden') == true) {
				
				//ADD THE ON CLASS TO THE BUTTON
				jQuery(this).addClass('on');
				jQuery(this).css({'background': '#d1e0a3 url("/images/arrow_blue_up_2.gif") no-repeat 98% 50%'});
				    
				//OPEN THE SLIDE
				jQuery(this).next().slideDown(1000);
			}
		});
	});
	
	/********************************************************************************************************************
	OPEN ALL DIVS ON BUTTON CLICK SHOW ALL AND HIDE ON HIDE TOGGLE
	********************************************************************************************************************/	
	jQuery(".showButton").click(function() {		
		if(showAll == false) {
			jQuery('.accordionContent').slideDown(1000);
			jQuery('div.accordionButton').removeClass('on');
			jQuery(".showButton").attr('value',"Hide");	
			jQuery(".showButton").css({'background':'transparent url("/images/btn_hide.gif") no-repeat center top'});
			jQuery(".accordionButton, .accordionMenuButton").css({'background': '#f3fdd6'});
			showAll = true;		
		} else {
			jQuery(".showButton").attr('value',"Show All");
			jQuery(".showButton").css({'background':'transparent url("/images/btn_show_all.gif") no-repeat center top'});
			jQuery('.accordionContent').hide();
			jQuery(".accordionButton, .accordionMenuButton").css({'background': '#f3fdd6 url("/images/arrow_blue_down_2.gif") no-repeat 98% 50%'});
			jQuery(".accDefault").trigger('click');
				
			showAll = false;
		}
	});
	
	//IDENTIFY WHICH DIV TO OPEN BASED ON SELECTED ACTION
	switch(getAction) {
		case "occupation" :
			window.location.hash = "";
			jQuery("#accBtn1").trigger('click');
			break;
		case "insurance" :
			window.location.hash = "";
			jQuery("#accBtn2").trigger('click');
			break;
		case "waiting" :
			window.location.hash = "";
			jQuery("#accBtn3").trigger('click');
			break;
		case "fix" :
			window.location.hash = "";
			jQuery("#accBtn4").trigger('click');
			break;
		case "event" :
			window.location.hash = "";
			jQuery("#accBtn5").trigger('click');
			break;
		default:
			jQuery(".accDefault").trigger('click');
			return false;
	}
	
	//NEXT BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	var j = 1;
	jQuery(".btnNext").each(function(i,el){
		
		jQuery(el).click(function() {
			//REMOVE THE ON CLASS FROM ALL BUTTONS
			jQuery('.accordionButton').removeClass('on');
		  
			//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
			jQuery('.accordionContent').slideUp(1000);	
			
			//GET THE NEXT ACCORDION ID
			j = i + 2;
			var k = j - 1;
			//CLICK ON THE NEXT ACCORDION TAB TO OPEN IT
			jQuery('#accBtn'+ j).click();
			
			return false;

		});
	});
	
	
});
