$(document).ready(function() {
    
    /* Services */
        
    /* Expand / Collapse All */
    $("p.instructions").css({"display": "block"});
    $("p.instructions a").css({"cursor": "pointer"});
    var menteeAll = false;
    var programsAll = false;
    $("a#expandServices").click( function() {
        if (menteeAll == false) {
            $("div#programs-mentee ul").css("display", "block");
            $(this).text("- collapse all");
            $("div#programs-mentee img.service-collapse").css("display", "block");
            $("div#programs-mentee img.service-expand").css("display", "none");
            menteeAll = true;
        } else {
            $("div#programs-mentee ul").css("display", "none");
            $(this).text("+ expand all");
            $("div#programs-mentee img.service-collapse").css("display", "none");
            $("div#programs-mentee img.service-expand").css("display", "block");
            menteeAll = false;
        }
        console.log("click");
    });
    
    $("a#expandProducts").click( function() {
        if (programsAll == false) {
            $("div#programs-services ul").css("display", "block");
            $(this).text("- collapse all");
            $("div#programs-services img.service-collapse").css("display", "block");
            $("div#programs-services img.service-expand").css("display", "none");
            programsAll = true;
        } else {
            $("div#programs-services ul").css("display", "none");
            $(this).text("+ expand all");
            $("div#programs-services img.service-collapse").css("display", "none");
            $("div#programs-services img.service-expand").css("display", "block");
            programsAll = false;
        }
    });    
    
    /* Expand Collapse Arrows */
    $("div.service h5 img.service-collapse").css("display", "block");
    $("div.service").css("cursor", "pointer");
    $("div.service").each( function() {
        
        $(this).bind('click', function() {
            
            var ref = $("ul", this);
            var ex = $("img.service-expand", this);
            var col = $("img.service-collapse", this);
            
            if(ref.css("display") != "none") {
               col.hide();
               ex.show();
               ref.slideUp("slow"); 
            } else {
               ex.hide();
               col.show();               
               ref.slideDown("medium");
            }
            
        });
        
    });
    
    /* All hide all lists save the first for each program */
    $("ul.service-mentee:gt(0)").css("display", "none");
    $("div#programs-mentee img.service-collapse:gt(0)").css("display", "none");
    $("div#programs-mentee img.service-expand:gt(0)").css("display", "block");
    $("ul.service-products:gt(0)").css("display", "none");
    $("div#programs-services img.service-collapse:gt(0)").css("display", "none");
    $("div#programs-services img.service-expand:gt(0)").css("display", "block");
    
    /* QA */
    $("div.qLeft div.collapse:first").show();
    $("div.qLeft img.service-expand:first").hide();
    $("div.qLeft p:gt(0)").hide();
    $("div.qLeft img.service-collapse:gt(0)").hide();
    $("div.question").css("cursor", "pointer");
    
    $("div.qRight div.collapse:first").show();
    $("div.qRight img.service-expand:first").hide();
    $("div.qRight p:gt(0)").hide();
    $("div.qRight img.service-collapse:gt(0)").hide();
    
    $("div.question").each( function(i) {
        
        $(this).bind('click', function() {
            var ref = $("p", this);
            var ex = $("img.service-expand", this);
            var col = $("img.service-collapse", this);
            
            if(ref.css("display") != "none") {
               ex.show();
               col.hide();
               ref.slideUp("slow"); 
            } else {
               col.show();
               ex.hide();               
               ref.slideDown("slow");
               
            }
        });
        
    });
    
});
