﻿$(function () {
    $(".nsTxt").ontab(".nstHead .s", ".nstCtn", "selected");
    $("#rbox3tabBox").ontab(".rbox3tab .other a", ".paihang", "selected");
    $("#ca_timer").ontab("h4", ".time_tab", "sd");
    $(".zc").ontab("h2 span", ".txt", "t");
    $("#ca_timer h4").each(function () {
        var d = $(this).nextAll("script:first").html().replace(/[\s\S]*new Date\((.*?)\)[\s\S]*/ig, "$1");
        eval("d=new Date(" + d + ")");
        if (d > new Date()) {
            $(this).mouseover();
            return false;
        }
    }).eq(0).addClass("ft");
    $(".rollpic").rollpic(".abox");
    $(".xyxs").rolltop(1, 50);
    if ($(".conPath").length > 0) {
        $(".conPath").replaceAll(".search .links").show();
    } else {
        $(".search .links").css("visibility", "visible").rolltop(1, 5000, "li");
    }
    $(".fdgrb .tbody").rolltop(1, 5500, "tr*3");
});
$(function () {
    $(".showpic .loading").remove();
    var funbox = $("<div class=\"funbox\"></div>"), ss = $("<div class=\"ss\"></div>"), a = $("<a href=\"#\" target=\"_self\"></a>");
    $(".showpic img").each(function (i) {
        if (!$(this).parent().is("a")) {
            $(this).wrap("<a href='javascript:void(0)' target='_self' style='cursor:default'></a>");
        }
        var _a = $(this).closest("a");
        _a.attr("title", function () {
            return $(this).attr("title") || $(this).find("img").attr("alt");
        });
        ss.append($("<span>" + (i + 1) + "</span>").bind("click", function () {
            $(this).siblings().removeClass();
            $(this).addClass("selected");
            var thisimg = $(".showpic a img").hide().eq($(this).index()).show();
            $(".showpic .funbox a").attr("href", thisimg.closest("a").attr("href")).attr("title", thisimg.closest("a").attr("title")).attr("target", thisimg.closest("a").attr("target")).text(thisimg.closest("a").attr("title"))[0].onclick = thisimg.closest("a")[0].onclick;
        }));
    });
    funbox.append(ss).append(a);
    $(".showpic").append(funbox);
    ss.find("span:eq(0)").click();
    var showpicInt = null;
    $(".showpic").hover(function () {
        clearInterval(showpicInt);
    }, function () {
        showpicInt = setInterval(function () {
            var index = $(".showpic .ss .selected").index();
            $(".showpic .ss span").eq((index + 1) % $(".showpic .ss span").length).triggerHandler("click");
        }, 3000);
    }).mouseout();
});
(function ($) {
    $.fn.extend({
        rollpic: function (s) {
            return this.each(function () {
                var sDom = $(this).find(s);
                if (sDom.length == 0) return;
                var sbb = $("<div></div>").append(sDom);
                var sbox = $("<div></div>").append(sbb);
                $(this).append(sbox);
                var imghei = sDom.find("img").outerHeight(true) - 2 + "px";
                $(this).prepend($("<div class='rollpicLeft'></div>")).prepend($("<div class='rollpicRight'></div>"));
                var lrWidth = $(this).find(".rollpicLeft").outerWidth() + $(this).find(".rollpicRight").outerWidth() + 6;
                var n = parseInt(($(this).width() - lrWidth) / sDom.width());
                $(this).find(".rollpicLeft").css({
                    "float": "left",
                    "display": "inline",
                    "height": imghei,
                    "cursor": (n >= sDom.length ? "default" : "pointer")
                }).bind("click", { n: n, s: s }, function (e, isan) {
                    var _this = $(this);
                    if (!_this.data("lj")) _this.data("lj", 0);
                    var sb = _this.parent().find(e.data.s).parent();
                    var ss = _this.parent().find(e.data.s);
                    var d = ss.eq(ss.length - 1);
                    var w = d.width();
                    if (e.data.n >= ss.length || (ss.filter(":animated").length > 0 && !isan)) {
                        return;
                    } else {
                        _this.data("lj", _this.data("lj") + 1);
                        if (_this.data("lj") > e.data.n) {
                            _this.data("lj", 0);
                            return;
                        }
                        var isAuto = isan === false;
                        sb.prepend(d.css("margin-left", -(sMgr + sDom.width())));
                        d.animate({ marginLeft: "0" }, { duration: (isAuto ? 600 : 150), easing: "Linear", complete: function () {
                            if (!isAuto)
                                _this.trigger("click", [true]);
                            else
                                _this.data("lj", 0);
                        } 
                        });
                    }
                });
                $(this).find(".rollpicRight").css({
                    "float": "right",
                    "display": "inline",
                    "height": imghei,
                    "cursor": (n >= sDom.length ? "default" : "pointer")
                }).bind("click", { n: n, s: s }, function (e, isan) {
                    var _this = $(this);
                    if (!_this.data("lj")) _this.data("lj", 0);
                    var sb = _this.parent().find(e.data.s).parent();
                    var ss = _this.parent().find(e.data.s);
                    if (e.data.n >= ss.length || (ss.filter(":animated").length > 0 && !isan)) {
                        return;
                    } else {
                        _this.data("lj", _this.data("lj") + 1);
                        if (_this.data("lj") > e.data.n) {
                            _this.data("lj", 0);
                            return;
                        }
                        var isAuto = isan === false;
                        var w = ss.eq(1).width();
                        ss.eq(0).animate({ marginLeft: "-" + (sMgr + sDom.width()) }, { duration: (isAuto ? 600 : 150), easing: "Linear", complete: function () {
                            sb.append($(this).css("margin-left", "0px"));
                            if (!isAuto)
                                _this.trigger("click", [true]);
                            else
                                _this.data("lj", 0);
                        } 
                        });
                    }
                });
                sbox.css({
                    width: $(this).width() - lrWidth,
                    "overflow": "hidden",
                    "float": "left",
                    "margin": "0px 1px"
                });
                var sMgr = (sbox.width() - (sDom.width() * n)) / (n - 1);
                sDom.css({
                    "margin-right": sMgr
                });
                sbb.css({
                    width: (sDom.width() + sMgr) * sDom.length
                });
                if (n >= sDom.length) {
                    $(this).find(".rollpicLeft,.rollpicRight").unbind("click");
                    return;
                }
                var setInt = null;
                $(this).hover(function () {
                    window.clearInterval(setInt);
                }, function () {
                    setInt = setInterval(function () {
                        sbox.prevAll("div").eq(1).triggerHandler("click", [false]);
                    }, 3000);
                }).mouseout();
            });
        },
        rolltop: function (n, m, l) {
            n = n || 1;
            m = m || 20;
            l = l || "";
            var ln = parseInt(l.replace(/.*\*?(\d+)/ig, "$1")) || 1;
            l = l.replace(/\*.*/ig, "");
            return this.each(function () {
                $(this).wrapInner("<div class='roll_wrap'></div>");
                if ($(this).find(".roll_wrap").outerHeight() < $(this).height()) return;
                $(this).append($(this).find(".roll_wrap").clone(true));
                var _this = $(this);
                var setint = null;
                _this.hover(function () {
                    clearInterval(setint);
                }, function () {
                    setint = setInterval(function () {
                        var temp = _this.scrollTop();
                        var fun = function () {
                            _this.scrollTop(temp + n);
                            if (l != "") {
                                var temp2 = 0;
                                var setint2 = setInterval(function () {
                                    temp2 = _this.scrollTop();
                                    _this.scrollTop(Math.min(temp2 + n, temp + _this.find(l).outerHeight() * ln));
                                    if (_this.scrollTop() >= temp + _this.find(l).outerHeight() * ln || temp2 + n > _this.scrollTop()) {
                                        clearInterval(setint2);
                                    }
                                }, 20);
                            }
                        };
                        fun();
                        if (temp + n > _this.scrollTop()) {
                            temp -= _this.find(".roll_wrap").outerHeight();
                            fun();
                        }
                    }, m);
                }).mouseout();
            });
        },
        timemouseover: function (f, h, d) {
            return this.each(function () {
                $(this).bind("mouseover", d || {}, function (e) {
                    var _this = this;
                    $(_this).data("out", false);
                    setTimeout(f, 1000);
                }).mouseout(function () {
                    $(this).data("out", true);
                });
            });
        }
    });
})(jQuery);
(function ($) {
    $.fn.extend({
        ontab: function (s1, s2, cls, sj) {
            return this.each(function () {
                var msj = $(this).attr("sj") || sj || "mouseover";
                $(this).attr("sj", msj);
                var sd = $(this).find(s1).filter("." + cls), sdn = 0;
                if (sd.length > 0) sdn = $(this).find(s1).index(sd);
                $(this).find(s1).bind(msj, { c: cls, s: s2, s1: s1, f: this }, function (e) {
                    var _this = this, id = $(e.data.f).attr("id"), eq = $(e.data.f).find(e.data.s1).index(_this);
                    $(_this).siblings().removeClass(e.data.c);
                    $(_this).addClass(e.data.c);
                    $(e.data.f).find(e.data.s).hide().eq(eq).show();
                    $(e.data.f).find("h2 .t").attr("href", $(_this).find("a").attr("href"));
                }).eq(sdn).trigger(msj);
            });
        }
    });
})(jQuery);

//非统考专业课ajax加载课表
$(function () {
    if ($(".kbListTab").length == 0 || $(".kbListTab").hasClass("toftk")) return;
    $(".kbListTab a").live("click", function () {
        $("#ajaxkb").html("<p style='line-height:24px;padding-left:10px; border-bottom:#CECECE solid 1px;'>数据加载中……</p>").load("/channel/kaoyan/ajaxkb.jsp?id=" + $(this).attr("href").replace(/\D/ig, "") + "&title=" + encodeURI(encodeURI($(this).html())));
        if ($(".kbListTab .selected").length > 0) $(".showTit").hide();
        $(".kbListTab .selected").removeClass("selected");
        $(this).closest("td").addClass("selected");
        $(this).blur();
        return false;
    });
    var id = window.location.href.split("#")[1] || $(".kbListTab a:first").attr("href").replace(/\D/ig, "");
    var toHot = window.location.href.split("#")[1] || "";
    var fa = $(".kbListTab a[href='#" + id + "']");
    if (fa.length == 0) fa = $(".kbListTab a:first");
    fa.click();
    if (toHot) {
        $(window).scrollTop(920);
    }
});

/*新版新加*/
$(function () {
    if (window.checkMenu) checkMenu();
    if (window.leftMenu) leftMenu();
    var pagetop_s3 = $("#pagetop_s3");
    if (pagetop_s3.length > 0) {
        $("table.pagetop .right .s3").html(pagetop_s3.html());
        pagetop_s3.remove();
    }
    var kbmenuindex = ($(".kbmenu .ss").length > 0 ? $(".kbmenu .ss").index(".kbmenu .s1") : 0);
    var kbev = $(".kbmenu").attr("ev") || "mouseover";
    $(".kbmenu .s1").bind(kbev, function () {
        if ($(this).hasClass("no")) return;
        $(this).addClass("ss").siblings(".s1").removeClass("ss");
        $(this).closest(".kbmenu").nextAll(".kbtxt").hide().eq($(this).closest(".kbmenu").find(".s1").index(this)).show();
    }).eq(kbmenuindex).trigger(kbev);
    var ktboxcheck = $(".ktboxNav ~ .ktbox[name='" + $(".ktboxNav").attr("tab") + "']");
    var ktboxNavindex = ($(".ktboxNav").length > 0 ? ($(".ktboxNav").nextAll(".ktbox").index(ktboxcheck)) : 0);
    $(".ktboxNav a").click(function () {
        $(this).addClass("selected").siblings("a").removeClass("selected");
        $(this).closest(".ktboxNav").nextAll(".ktbox").hide().eq($(this).closest(".ktboxNav").find("a").index(this)).show();
        $(this).blur();
        return false;
    }).eq(ktboxNavindex).click();
    $(".tr17").show(), $(".td17").hide();
    $(".kttable2 .xqing").live("click", function () {
        $(this).toggleClass("xqing2");
        $(this).closest("tr").next(".tr17").children(".td17").toggle();
    });
    $("#lnav,.lnav2").each(function () {
        var lnav = $(this);
        lnav.find("h2,h3").click(function () {
            var h = $(this);
            $(this).next("ul").slideToggle(600, function () {
                h.find("i").toggleClass("close");
                var width = parseInt(h.css("border-bottom-width").replace(/\D/ig, ""));
                h.css("border-bottom-width", [1, 0][width] + "px");
            });
        });
    });
    $(".nstCtn ul.data").each(function () {
        var h2 = !($(this).attr("h2") == "no");
        if (h2) {
            $(this).before($("<h4 />").append($(this).find("li:eq(0) a")));
            $(this).find("li:eq(0)").remove();
        }
    });
    $(".paHover .a1").mouseover(function () {
        $(this).siblings(".a1").show();
        $(this).siblings(".pa").hide();
        $(this).hide().next(".pa").show();
    }).eq(0).css("border-color", "#fff").mouseover().next(".pa").css("border-color", "#fff");
});

function luceneSearch() {
    var kw = document.search.keyword;
    if (kw) {
        $("form[name='search'] .input").focus();
        if (kw.value.length <= 0) {
            alert("请输入关键字！");
            kw.focus();
            return false;
        } else {
            document.search.submit();
        }
    }
}
$(function () {
    $("form[name='search'] .input").blur(function () {
        if ($(this).val() == "") {
            $(this).val("请输入关键字！").css("color", "#D5D6D5").attr("notxt", "y");
        }
    }).focus(function () {
        if ($(this).val() == "请输入关键字！" && $(this).attr("notxt") == "y") {
            $(this).val("").css("color", "").attr("notxt", "n");
        }
    }).blur();
});
//问答展示
$(function () {
    var answer = $(".answer:first");
    answer.show();
    $(".q").click(function () {
        $(".answer").hide();
        $(this).next().show();
    });
});
jQuery.extend(jQuery.easing,
{
    Linear: function (x, t, b, c, d) {
        return c * t / d + b;
    }
});

