
$(document).ready(function(){

	// Setup collapsible sections
	
    //$(".toggle-section .content").addClass("hidden");
    for(var i=0;i<$(".toggle-section .title").length;i++){
        var currQ = $(".toggle-section .title")[i];
        var currA = $(".toggle-section .content")[i];
        currQ.content = currA;
        if($(currQ).hasClass("closed"))
        {
            $(currA).hide();
        }
        else if($(currQ).hasClass("opened"))
        {
            $(currA).show();
        }
        
        //Rollover
		$(currQ).hover(function(){
			$(this).addClass("rolledover");
			},
			function(){
					$(this).removeClass("rolledover");
		 });
		 
		$(".toggle-section .title")[i].onclick = function()
        {
            if($(this).hasClass("closed"))	
            {
                //title is closed
                $(this).removeClass("closed");
                $(this).addClass("opened");
                $(this.content).show();
				$(".ada-hidden", $(this)).text("Hide "); 
                //$(this).attr("title","Hide additional information");
            }
            else if($(this).hasClass("opened"))
            {
                //title is opened
                $(this).removeClass("opened");
                $(this).addClass("closed");
                $(this.content).hide();
				$(".ada-hidden",$(this)).text("Show ");
                //$(this).attr("title","Show more information");
            }
        };
    }

	// Setup tab structure 
	
	$('.tab-navigation * a').click(function(){
		$(this).parents('li').addClass('selected').siblings().removeClass('selected');
		var url = $(this).attr('href').split('#');
		var id = url[1];
		$('.content-section', $('#content-area')).addClass('hide');
		$('#'+id).removeClass('hide');
		return false;
	});
	
	document.module4CInitialization = true;

    if($('li.show-on-load', $('div.tabs ul')).length > 0) {
        $('div.tabs ul').find('li.show-on-load').find('a').trigger("click");
    } else {
        $('div.tabs ul').find('li:first').find('a').trigger("click");
    }
    
	document.module4CInitialization = false;

	// Check if Tier 4 return button exist to determine where to attach change event

	if( ($('.tier4-return-button').length > 0 )  ) 
	{
		$('.tier4-return-button').click(function(){     
			$('.tier4-main-4c-content').hide();
			$('.main-4c-content').show();

			$('.tier4-side-4c-content').hide();
			$('.side-4c-content').show();
			return false;
		});
	}
	
	// Add Rollover State to FAQs
	if( ($('.main-4c-content li.question').length > 0 )  ) 
	{
		$(".main-4c-content li.question").hover(function(){
					$(this).addClass("rolledover");
			},
			function(){
					$(this).removeClass("rolledover");
		 });
	}
	

	$('a.show-all-answers-link').click(function(){
		$(this).parent().children("div.title").removeClass("closed").addClass("opened");
		$(this).parent().children("div.content").show();
	});	
	
});

