﻿/// <reference path="lib/jquery-1.3.2.js" />

var CCI; if (!CCI) { CCI = {}; }
if (!CCI.Pages) { CCI.Pages = {}; }
if (!CCI.Pages.Knowledgebase) { CCI.Pages.Knowledgebase = {}; }

CCI.Pages.Knowledgebase.Init = function() {
    // Hide all the open topics, except for the one that should be open
    $(".disclosure.topics .topic").not(".opened").next().hide();
    // Hide all the open questions, except for the one that should be
    $("#answers .activator").not(".opened").next().hide();

    // Attach the topic click!
    $(".disclosure.topics .activator").click(function() {
        CCI.Pages.Knowledgebase.DisclosureClick(".disclosure.topics", this);
    }).attr({ title: 'Click to expand or collapse' });

    // Attach the sub topic click
    $(".disclosure.topics li").click(function() {
        $(".disclosure.topics .selected").removeClass('selected');
        $(this).addClass('selected');
        var id = $(this).children("a:first").attr("class").split("_");
        CCI.Utility.RenderPartial("answers", "Knowledgebase", "Support", id, null, function() {
            $("#answers .activator").not(".opened").next().hide();
        },
        "get");
        return false;
    });

    // Attach the question click
    $("#answers .activator").live("click", function() {
        CCI.Pages.Knowledgebase.DisclosureClick("#answers .disclosure", this);
        return false;
    });

    CCI.Map.Init();   
}

CCI.Pages.Knowledgebase.DisclosureClick = function(selector, el) {
    if (selector == ".disclosure.topics") {
        $("#answers:visible").children().hide("normal", function() {
            $("#answers:visible").empty();
        });
    }
    $this = $(el);
    $(selector).find('.activator.opened').removeClass('opened')
    if ($this.next().is(":visible")) {
        $this.next().hide("normal");
    } else {
        $(selector).find('.activator').next(":visible").hide("normal");
        $this.addClass('opened');
        $this.next().show("normal");
    }
    var questionID = CCI.Utility.GetValueFromClass("question_", el);
    if (questionID) {
        CCI.Utility.CMPageviewTag('Support Answer ' + questionID, '200' + questionID, '2000');
    }
}