var working = false, timespan = null; $(function () { $(".newspic").each(function () { $(".newspic .newspictxt").html(""); $(".newspic ul.slidebtn").each(function () { $(this).width(22 * $(".newspic ul.newspicbox li").length); }); $(".newspic ul.newspicbox li").each(function () { $(this).attr("index", $(this).index()); $(".newspic .newspictxt").html($(".newspic .newspictxt").html() + "
  • " + $(this).find("a").attr("title") + "
  • "); $(".newspic ul.slidebtn").html($(".newspic ul.slidebtn").html() + ""); }); $(".newspic ul.slidebtn li").click(function () { $.newspicslidenext($(this).index()); }); $(".newspic .prev").click(function () { $.newspicslidenext($(".newspic ul.slidebtn li.no").index() - 1); }); $(".newspic .next").click(function () { $.newspicslidenext($(".newspic ul.slidebtn li.no").index() + 1); }); $.newspicslidestart(); }).hover(function () { $.newspicslidestop(); $(".newspic .prev,.newspic .next").show(); }, function () { $.newspicslidestart(); $(".newspic .prev,.newspic .next").hide(); }); }); $.newspicslidestart = function () { timespan = setinterval(function () { $.newspicslidenext($(".newspic ul.slidebtn li.no").index() + 1); }, 5000); }; $.newspicslidestop = function () { clearinterval(timespan); }; $.newspicslidenext = function (next) { var thisli = $(".newspic ul.slidebtn li.no").index(); var maxw = $(".newspic").width(), size = $(".newspic ul.newspicbox li").length; if (next > size - 1) next = 0; if (next < 0) next = size - 1; if (thisli != next && !working && size > 1) { working = true; $(".newspic ul.newspicbox li[index=" + thisli + "]").after($(".newspic ul.newspicbox li[index=" + next + "]")); $(".newspic .newspictxt li[index=" + thisli + "]").after($(".newspic .newspictxt li[index=" + next + "]")); $(".newspic .newspictxt li[index=" + thisli + "]").animate({ "margin-left": "50px" }, 300, function () { $(".newspic ul.slidebtn li").eq(next).addclass("no").siblings().removeclass("no"); $(".newspic .newspictxt li[index=" + thisli + "]").animate({ "margin-left": "-" + maxw + "px" }, 400); $(".newspic ul.newspicbox li[index=" + thisli + "]").animate({ "margin-left": "-" + maxw + "px" }, 800, function () { $(".newspic .newspictxt li:last").after($(".newspic .newspictxt li[index=" + thisli + "]")); $(".newspic ul.newspicbox li:last").after($(".newspic ul.newspicbox li[index=" + thisli + "]")); $(".newspic ul.newspicbox li[index=" + thisli + "],.newspic .newspictxt li[index=" + thisli + "]").css("margin-left", "0px"); working = false; }); }) } };