$(document).ready(function () {
	(function () {
		$('ul.jsSliderAllClosed').each(function () {
			var $allSections = $("li.section", this),
				bIsAccordion = $(this).hasClass("jsAccordion");

			/* init slider: slide collapse all sectionContents... */
			$allSections.addClass('closed').children(".sectionContent").hide();

			/* Bind expand/collapse single sections events */
			$allSections.find(".sectionHead").css({cursor: 'pointer'}).click(function (event) {
				var $currentSection = $(this).closest("li");
				if (bIsAccordion) {
					/* add accordion behaviour (close all other sections) */
					$currentSection.siblings(":not(.closed)").addClass("closed").children(".sectionContent").slideUp("slow");
				}
				$currentSection.toggleClass("closed").children(".sectionContent").slideToggle("slow");
			});
		});
	})();
	
	var oReg = mdsRegistry.getInstance('readMore');
     /*
      * Init: addClass to all answer #openClose/#expandable elements,
      * hide all answer labels (#expandable),
      * wrap answer #openClose content in  slideWrp, and finally
      * append the utilityLinks (expand/collapse)
      */
    $("#readMore #expandable, #readMore #openClose").addClass("jsMore")
    .filter('#expandable').hide().end()
    .filter("#openClose").each(function () {
        $(this).wrapInner(
            $('<div></div>').addClass("jsSlideWrp").hide()
        ).append(
            $('<span></span>').addClass("utilityLink").text(oReg.get('showAnswer'))
        );
    });
   
    /*
     * expand/collapse answer handler
     * switch linktext, toggle highlight-class and slide
     * for current answer #openClose / #expandable
     */
    $("#readMore .utilityLink").click(function (e) {
        var $currentAnswerDD = $(this).toggleClass('jsCollapse').closest('#openClose');
        $(this).text(
            $(this).hasClass("jsCollapse") ? oReg.get('hideAnswer') : oReg.get('showAnswer')
        );
        $("div.jsSlideWrp", $currentAnswerDD).slideToggle('slow');
        $currentAnswerDD.prev("#expandable").slideToggle('fast');
        $currentAnswerDD.add(
            $currentAnswerDD.prevAll("#expandable:lt(2), #openClose:eq(0)")
        ).toggleClass('highlight');
    });   
});