$(function() {
  var carousel_num = 3,
      carousel_speed = 1500,
      carousel_auto_speed = 3000,
      main_image_switch_speed = 1000,
      thumbnail_image_effect_speed = 150,
      thumbnail_image_effect_transparency = 0.7;
  var jScrollPaneSettings = {
    scrollbarWidth: 13,
    showArrows: true,
    arrowSize: 12
  };

  $("#imgslider #carousel").jCarouselLite({
    vertical: false,
    hoverPause: true,
    visible: carousel_num,
    speed: carousel_speed,
    auto: carousel_auto_speed,
    btnPrev: ".imgslider_next",
    btnNext: ".imgslider_prev"
  });

  var current_main_id = "";
  $("#imgslider_main p").each(function (){
    if ($(this).hasClass("imgslider_default"))
    {
      current_main_id = $(this).attr("id");
      $("#carousel ul li." + current_main_id.replace("_main", "")).each(
        function (){
          $(this).addClass("imgslider_selected");
        }
      );
    }
    else
    {
      $(this).fadeTo(1, 0);
    }
  });

  $("#carousel ul li").each(function (){
    $(this).click(function (){
      var click_main_id = $(this).attr("class").split(" ")[0] + "_main";
      if (click_main_id != current_main_id)
      {
        if (current_main_id != "")
        {
          $("#" + current_main_id).fadeTo(main_image_switch_speed, 0).css("z-index", 9);
          $("#carousel ul li." + current_main_id.replace("_main", "")).each(
            function (){
              $(this).removeClass("imgslider_selected");
            }
          );
        }
        $("#" + click_main_id).fadeTo(main_image_switch_speed, 1).css("z-index", 10);
        $("#carousel ul li." + $(this).attr("class")).each(
          function (){
            $(this).addClass("imgslider_selected");
          }
        );
        current_main_id = click_main_id;
      }
    });
    $(this).hover(
      function (){
        $(this).queue([]);
        $(this).fadeTo(thumbnail_image_effect_speed, thumbnail_image_effect_transparency);
      },
      function (){
        $(this).queue([]);
        $(this).fadeTo(thumbnail_image_effect_speed, 1);
      }
    );
  })

  $("#top_overflow_news_list").jScrollPane(jScrollPaneSettings);
  $("#top_overflow_event_list").jScrollPane(jScrollPaneSettings);

  $("#rfontsize .fontS").click(function (){
    $("#top_overflow_news_list").jScrollPane(jScrollPaneSettings);
    $("#top_overflow_event_list").jScrollPane(jScrollPaneSettings);
    return false;
  });
  $("#rfontsize .fontM").click(function (){
    $("#top_overflow_news_list").jScrollPane(jScrollPaneSettings);
    $("#top_overflow_event_list").jScrollPane(jScrollPaneSettings);
    return false;
  });
  $("#rfontsize .fontL").click(function (){
    $("#top_overflow_news_list").jScrollPane(jScrollPaneSettings);
    $("#top_overflow_event_list").jScrollPane(jScrollPaneSettings);
    return false;
  });
});

