$(document).ready(function() {
    SetAccordion();
});

function SetAccordion() {

    var accordionBox = $(".accordionBox");
    if ($(accordionBox).length < 1) return;
    
    
            $(accordionBox).find("h4").wrap("<a class='ah4' href='#' />");

            var imgArrow = "<img class='imgArrow' style='padding:0 5px;' id='imgArrow' src='../Content/images/common/arrowblue.png'/>";
            var imgArrowbluedown = "<img class='imgArrow' id='imgArrow' style='padding:0 5px;' src='../Content/images/common/arrowbluedown.png'/>";
    
            $(".ah4").click(function() {

                    var parent = $(this).parents(".accordionItem:eq(0)");
                    var img = $(this).find(".imgArrow");
                    var parag = $(parent).find("div:first");
                    var h4 = $(this).find("h4:first");
                    
                    $(img).remove();

                    if ($(parent).is(".selected")) {
                        $(parag).hide("300");
                        $(parent).removeClass("selected");
                        $(h4).prepend(imgArrow);
                    } else {
                        $(parag).show("200");
                        $(parent).addClass("selected");
                        $(h4).prepend(imgArrowbluedown);
                    }
             
                    return false;
                });

                var accordionIndex = $.query.get('accid');
                $(accordionBox).find(".accordionItem.selected").removeClass("selected");
                if ((typeof accordionIndex) == "number") {
                    $(accordionBox).find(".accordionItem:eq(" + accordionIndex + ")").addClass("selected");
                } else if (accordionIndex == 'KO') {
                ;//do nothing
                }
                else {
                    $(accordionBox).find(".accordionItem:eq(0)").addClass("selected");
                }

    var divNotSelect = $(accordionBox).find(".accordionItem:not(.selected)");
      divNotSelect.find("h4").prepend(imgArrow);
      divNotSelect.find("div:first").hide();

    var divSelect = $(accordionBox).find(".accordionItem.selected");
      divSelect.find("h4").prepend(imgArrowbluedown);
      divSelect.find("div:first").show();
  }


  function processSlideshow(elem, imageList, imageDuration, fadeSpeed, current) {
          var listSize = imageList.length;
          if (!current || current >= listSize) current = 0;
          if (!imageDuration) imageDuration = 2000;
          if (!fadeSpeed) fadeSpeed = 1000;
          $(elem + " img").attr("src", imageList[current]);
          if (current == (listSize - 1)) {
              $(elem).css("background", "transparent url(" + imageList[0] + ") no-repeat");
          } else {
              $(elem).css("background", "transparent url(" + imageList[current + 1] + ") no-repeat");
          }
          $(elem + " img").animate({ opacity: "1" }, imageDuration).
     animate({ opacity: "0.01" }, fadeSpeed, function() {
         $(this).css("opacity", "1"); processSlideshow(elem, imageList, imageDuration, fadeSpeed, current + 1)
     });
  }