﻿        $(document).ready(function(){
            
            var IFALoaded = false;
            var CLoaded = false;
            
	        // When the collapse button is clicked:
            $('#consumerWidget').click(function() {
      	        
	            if ( $(this).hasClass("header4Close") ) {
	                $(this).removeClass("header4Close");
		            $(this).addClass("header4Open");
                    $.cookie("consumerWidget", ""); 
                    $(this).next().toggle();
	            }
	            else {
	                $(this).removeClass("header4Open");
                    $(this).addClass("header4Close");
                    $.cookie("consumerWidget", "expanded"); 
                    $(this).next().toggle();
                    if (CLoaded == false) {
                        if (window.LoadTestimonialsConsumer) {
                            LoadTestimonialsConsumer();
                        }
                        if (window.LoadVideosC) {
                            LoadVideosC();
                            //alert ("loadingC on click");
                        }
                        CLoaded = true;
                    }
	            }
         });
         
         $('#adviserWidget').click(function() {
      	        
	            if ( $(this).hasClass("header4Close") ) {
	                $(this).removeClass("header4Close");
		            $(this).addClass("header4Open");
		            $.cookie("adviserWidget", "closed");                   
                    $(this).next().toggle();
	            }
	            else {
	                
	                $(this).removeClass("header4Open");
                    $(this).addClass("header4Close");
                    $.cookie("adviserWidget", ""); 
                    $(this).next().toggle();
                     if (IFALoaded == false) {
                        if (window.LoadTestimonialsIFA) {
                            LoadTestimonialsIFA();
                        }
                        if (window.LoadVideosIFA) {
                            LoadVideosIFA();
                            //alert ("loadingIFA on click");
                        }
                        IFALoaded = true;
                    }
	            }
         });
  

        // COOKIES
        var adviserCookie = $.cookie('adviserWidget');
        var consumerCookie = $.cookie('consumerWidget');

        // Set the user's selection for the left column
        //alert(adviserCookie);
        if (adviserCookie == 'closed') {
             $('#adviserWidget').removeClass("header4Close");
		     $('#adviserWidget').addClass("header4Open");
		     $('#adviserWidget').next().hide();
        }
        else {
            if (window.LoadTestimonialsIFA) {
                LoadTestimonialsIFA();
            }
            if (window.LoadVideosIFA) {
                LoadVideosIFA();                       
            }
            IFALoaded = true;
        };
        if (consumerCookie != 'expanded') {
             $('#consumerWidget').removeClass("header4Close");
		     $('#consumerWidget').addClass("header4Open");
		     $('#consumerWidget').next().hide();
        }
        else {
            if (window.LoadTestimonialsConsumer) {
                LoadTestimonialsConsumer();
            }
            if (window.LoadVideosC) {
                LoadVideosC();
            }
            CLoaded = true;
        };
	           	  	
    });
