// JavaScript Document
$(document).ready(function(){
	
	
	function home_tabs(){
		$("div.tab").children("a.tab_arrow").addClass("down").click(function(){
									
				if($(this).attr("class").search("down") == -1){
					$(this).addClass("down").css("backgroundPosition", "left top").parent().css("backgroundPosition", "left -52px").animate({ top : "0px"}, 300);
				}
				else{
					$(this).removeClass("down").css("backgroundPosition", "left -56px").parent().animate({ top : "-130px"}, 300, function(){$(this).css("backgroundPosition", "left 130px");});
				}
		})
		.hover(function(){
				if($(this).attr("class").search("down") == -1){
					$(this).css("backgroundPosition", "left -28px")
				}
				else{
					$(this).css("backgroundPosition", "left top")
				}
			},
			function(){
				if($(this).attr("class").search("down") == -1){
					$(this).css("backgroundPosition", "left bottom")
				}
				else{
					$(this).css("backgroundPosition", "left -56px")
				}
			}
		);
	}
	
	
	function accordion_menu(){
		
		$("#left_nav ul.lev1").accordion({ 
			active: false,
			collapsible: true,
			autoHeight: false,
			clearStyle: true,
			navigation: true,
			navigationFilter: function(){
				if(($("a.selected").attr("class").search("lev3") != -1) && ($(this).attr("class").search("lev2") != -1) && ($(this).attr("class").search("haschildren") != -1)){
					var is_match = false;
					$(this).parent().children("ul").children("li").children("a").each(function(){
						if(location.href.toLowerCase().search($(this).attr("href").toLowerCase()) != -1){
							is_match = true;
							return false;//breaks out of .each function
						}
					});
					return is_match;
				}
				else{
					return this.href.toLowerCase() == location.href.toLowerCase(); 	
				}
			}
		});
		
		if($("a.selected").attr("class").search("lev3") != -1){
			$("li.lev3 a.selected").parent().parent().parent().addClass("selected").children("a").addClass("selected");
		}
		
		$("#left_nav a").click(function(){ $(this).blur(); } );
	}
	
	function sub_nav(){
		$('table.sub_nav tr td a[href$="' + location.pathname + '"]').addClass('selected');	
		$('div#footer_right a[href$="' + location.pathname + '"]').addClass('selected');
		$('div#header_tabs a[href$="' + location.pathname + '"]').addClass('selected');
		if(
			   (location.pathname.search('state_locations.cfm') > 0) ||
			   (location.pathname.search('illinois.cfm') > 0) || 
			   (location.pathname.search('indiana.cfm') > 0) || 
			   (location.pathname.search('iowa.cfm') > 0) || 
			   (location.pathname.search('michigan.cfm') > 0) || 
			   (location.pathname.search('missouri.cfm') > 0) || 
			  // (location.pathname.search('arizona.cfm') > 0) ||
			   (location.pathname.search('location_details.cfm') = 0)
		   )
		{
			$('div#header_tabs a[href=/find_a_location.cfm]').addClass('selected');	
		}
	}
		function sub_nav(){
		$('table.sub_nav tr td a[href$="' + location.pathname + '"]').addClass('selected');	
		$('div#footer_right a[href$="' + location.pathname + '"]').addClass('selected');
		$('div#header_tabs a[href$="' + location.pathname + '"]').addClass('selected');
			if(
			   (location.pathname.search('state_locations.cfm') > 0) || 
			   (location.pathname.search('illinois.cfm') > 0) || 
			   (location.pathname.search('indiana.cfm') > 0) || 
			   (location.pathname.search('iowa.cfm') > 0) || 
			   (location.pathname.search('michigan.cfm') > 0) || 
			   (location.pathname.search('missouri.cfm') > 0) || 
			   (location.pathname.search('location_details.cfm') > 0))
			{
			$('div#header_tabs a[href=/find_a_location.cfm]').addClass('selected');	
		}
	}

	
	function compact_faqs(){
		$('div.faq div.answer').hide();
		$('div.faq p.question a').click(function(){
											$(this).parent().parent().parent().find('div.answer').slideToggle('slow');	
											if($(this).css("backgroundImage").search("minus") != -1){
												$(this).css("backgroundImage", "url(../images/design/faq_plus.png)");	
											}
											else{
												$(this).css("backgroundImage", "url(../images/design/faq_minus.png)");
											}
									  }
		);
	}
	
	function classify_inputs(){
		$("form input").each(function(){
			$(this).addClass($(this).attr("type"));
		});	
	}
	
	function toggle_subnav(){
		$("#center_header a.nav_close").click(function(){
			if($(this).attr('class').search('open') != -1){
				$(this).removeClass('open').addClass('closed').blur().html('x OPEN').closest('#center_header').animate({'height' : '54px'}, 400).find('table.sub_nav').hide();
			}
			else{
				$(this).removeClass('closed').addClass('open').blur().html('x CLOSE').closest('#center_header').animate({'height' : '129px'}, 400).find('table.sub_nav').show();
			}
		});
	}
	
	function stripe_tables(){
		$('table.striped tr:even').addClass('striped_alt');	
	}
	
	
	
	
	home_tabs();
	sub_nav();
	accordion_menu();
	compact_faqs();
	classify_inputs();
	toggle_subnav();
	stripe_tables();
	
});