(function ($) {
    $.fn.movebg = function (options) {
        var defaults = {
            width: 150,
            extra: 50,
            speed: 300,
            rebound_speed: 300
        };
        var defaultser = $.extend(defaults, options);
        return this.each(function () {
            var _this = $(this);
            var _item = _this.children("ul").children("li").children("a");
            var origin = _this.children("ul").children("li.cur").index();
            var _mover = _this.find(".move-bg");
            var hidden;
            if (origin == -1) {
                origin = 0;
                hidden = "1"
            } else {
                _mover.show()
            };
            var cur = prev = origin;
            var extra = defaultser.extra;
            _mover.css({
                left: "" + defaultser.width * origin + "px"
            });
            _item.each(function (index, it) {
                $(it).mouseover(function () {
                    cur = index;
                    move();
                    prev = cur;
                });
            });
            _this.mouseleave(function () {
                cur = origin;
                move();
                if (hidden == 1) {
                    _mover.stop().fadeOut();
                }
            });

            function move() {
                _mover.clearQueue();
                if (cur < prev) {
                    extra = -Math.abs(defaultser.extra);
                } else {
                    extra = Math.abs(defaultser.extra)
                };
                _mover.queue(function () {
                    $(this).show().stop(true, true).animate({
                            left: "" + Number(cur * defaultser.width + extra) + ""
                        }, defaultser.speed),
                        function () {
                            $(this).dequeue()
                        }
                });
                _mover.queue(function () {
                    $(this).stop(true, true).animate({
                            left: "" + cur * defaultser.width + ""
                        }, defaultser.rebound_speed),
                        function () {
                            $(this).dequeue()
                        }
                });
            };
        })
    }
})(jQuery);


function MenuIcon(node, listIcon1, listIcon2, listIcon3) {
    this.node = node;
    var _this = this;
    this.listIcon1 = listIcon1;
    this.listIcon2 = listIcon2;
    this.listIcon3 = listIcon3;
    this._li = $(this.node).find("li");
    this.insetIcon(this._li, this.listIcon1, this.listIcon2);
    $(_this._li).click(function () {
        _this.nodeClick(this)
    });
}
MenuIcon.prototype.insetIcon = function (list, list1, list2) {
    if (list1.length > list.length || list2.length > list.length) {
        alert("鍥炬爣澶氫簬鑺傜偣");
        return
    }
    $(list).each(function (i, item) {
        $(item).find(".iconfont:first").addClass(list1[i]);
        $(item).find(".iconfont:last").addClass(list2[i]);
    })
}
MenuIcon.prototype.nodeClick = function (_this) {
    var itemContent = $(_this).find(".item-content"),
        siblings = itemContent.siblings(".item").find(".iconfont:last");
    $("li div.item").find("i.iconfont:last").removeClass(this.listIcon3[0]).addClass(this.listIcon2[0]);
    if (itemContent.css("display") == "none") {
        $(".item-content").hide(300);
        siblings.removeClass(this.listIcon2[0]).addClass(this.listIcon3[0]);
        itemContent.slideDown();
    } else {
        itemContent.slideUp();
        siblings.removeClass(this.listIcon3[0]).addClass(this.listIcon2[0]);
    }
}

function LbMove(boxID, btn_left, btn_right, btnBox, Car, direction, way, moveLengh, speed, Interval, number) {
    var _ID = $("#" + boxID + "");
    var _btn_left = $("#" + btn_left + "");
    var _btn_right = $("#" + btn_right + "");
    var _btnBox = $("#" + btnBox + "");
    var jsq = 0
    var timer;
    var cj;
    var no_way = 0;
    var no_wayGet = 0;
    var fade = 0;
    var new_time = new Date;
    var ID_liLen, ID_liheight, cbtmBtn;
    ID_liLen = _ID.find("li").length;
    ID_liheight = _ID.find("li").innerHeight();
    if (direction == "left" || direction == "right") {
        _ID.find("ul").width(ID_liLen * moveLengh);
    } else if (direction == "top" || direction == "bottom") {
        _ID.find("ul").height(ID_liLen * moveLengh);
        _btnBox.hide()
    } else if (direction == "fade") {
        _ID.find("ul").width(moveLengh).height(ID_liheight);
        _ID.find("li").eq(0).show().siblings().hide();
        _ID.find("li").css({
            "position": "absolute",
            "left": 0,
            "top": 0
        });
    }
    _btnBox.empty();
    for (i = 0; i < ID_liLen; i++) {
        _btnBox.append("<span></span>");
    };
    _btnBox.find("span").eq(0).addClass("cur");
    if (way == false) {
        _btn_left.hide();
        _btn_right.hide();
        _btnBox.hide();
    }

    function Carousel() {
        if (way == false) {
            no_way++;
            if (direction == "left") {
                _ID.find("ul").css({
                    "left": -no_way
                });
                no_wayGet = parseInt(_ID.find("ul").css("left"));
                if (no_wayGet == -moveLengh) {
                    no_way = 0
                    _ID.find("li:first").insertAfter(_ID.find("li:last"));
                    _ID.find("ul").css({
                        "left": 0
                    });
                }
            }
            if (direction == "right") {
                no_wayGet = parseInt(_ID.find("ul").css("left"));
                if (no_wayGet == 0) {
                    no_way = -moveLengh
                    _ID.find("li:last").insertBefore(_ID.find("li:first"));
                    _ID.find("ul").css({
                        "left": 0
                    });
                }
                _ID.find("ul").css({
                    "left": no_way
                });
            }
            if (direction == "top") {
                _ID.find("ul").css({
                    "top": -no_way
                });
                no_wayGet = parseInt(_ID.find("ul").css("top"));
                if (no_wayGet == -moveLengh) {
                    no_way = 0
                    _ID.find("li:first").insertAfter(_ID.find("li:last"));
                    _ID.find("ul").css({
                        "top": 0
                    });
                }
            }
            if (direction == "bottom") {
                no_wayGet = parseInt(_ID.find("ul").css("top"));
                if (no_wayGet == 0) {
                    no_way = -moveLengh
                    _ID.find("li:last").insertBefore(_ID.find("li:first"));
                    _ID.find("ul").css({
                        "top": 0
                    });
                }
                _ID.find("ul").css({
                    "top": no_way
                });
            }
        } else if (way == true) {
            if (direction == "left") {
                _ID.find("ul").animate({
                    left: -moveLengh
                }, speed, function () {
                    _ID.find("li:first").insertAfter(_ID.find("li:last"));
                    _ID.find("ul").css({
                        "left": 0
                    });
                });
                if (jsq < ID_liLen - 1) {
                    jsq++;
                    _btnBox.find("span").eq(jsq).addClass("cur").siblings().removeClass("cur");
                } else {
                    jsq = 0;
                    _btnBox.find("span").eq(jsq).addClass("cur").siblings().removeClass("cur");
                }
            }
            if (direction == "right") {
                _ID.find("li:last").insertBefore(_ID.find("li:first"));
                _ID.find("ul").css({
                    "left": -moveLengh
                });
                _ID.find("ul").stop().animate({
                    left: 0
                }, speed);
                if (jsq > 0) {
                    jsq--;
                    _btnBox.find("span").eq(jsq).addClass("cur").siblings().removeClass("cur");
                } else {
                    jsq = ID_liLen - 1;
                    _btnBox.find("span").eq(jsq).addClass("cur").siblings().removeClass("cur");
                }
            }
            if (direction == "top") {
                _ID.find("ul").animate({
                    top: -moveLengh
                }, speed, function () {
                    _ID.find("li:first").insertAfter(_ID.find("li:last"));
                    _ID.find("ul").css({
                        "top": 0
                    });
                });
            }
            if (direction == "bottom") {
                _ID.find("li:last").insertBefore(_ID.find("li:first"));
                _ID.find("ul").css({
                    "top": -moveLengh
                });
                _ID.find("ul").stop().animate({
                    top: 0
                }, speed);
            }
            if (direction == "fade") {
                if (fade < ID_liLen - 1) {
                    fade++;
                } else {
                    fade = 0
                }
                _ID.find("li").eq(fade).fadeIn(speed).siblings().fadeOut(speed);
                _btnBox.find("span").eq(fade).addClass("cur").siblings().removeClass("cur");
            }
        }
    }
    if (Car == true) {
        if (ID_liLen > number) {
            timer = setInterval(Carousel, Interval);
        } else {
            clearInterval(timer);
            _btn_left.hide();
            _btn_right.hide();
            _btnBox.hide();
        }
    } else {
        clearInterval(timer);
    }
    _ID.find("li").hover(function () {
        clearInterval(timer);
    }, function () {
        if (Car == true) {
            if (ID_liLen > number) {
                timer = setInterval(Carousel, Interval);
            } else {
                clearInterval(timer);
                _btn_left.hide();
                _btn_right.hide();
                _btnBox.hide();
            }
        } else {
            clearInterval(timer);
        }
    });
    _btn_right.hover(function () {
        clearInterval(timer);
    }, function () {
        if (Car == true) {
            if (ID_liLen > number) {
                timer = setInterval(Carousel, Interval);
            } else {
                clearInterval(timer);
                _btn_left.hide();
                _btn_right.hide();
                _btnBox.hide();
            }
        } else {
            clearInterval(timer);
        }
    }).click(function () {
        if (new Date - new_time > 500) {
            new_time = new Date;
            if (direction == "left" || direction == "right") {
                _ID.find("ul").animate({
                    left: -moveLengh
                }, speed, function () {
                    _ID.find("li:first").insertAfter(_ID.find("li:last"));
                    _ID.find("ul").css({
                        "left": 0
                    });
                });
            }
            if (direction == "top" || direction == "bottom") {
                _ID.find("ul").animate({
                    top: -moveLengh
                }, speed, function () {
                    _ID.find("li:first").insertAfter(_ID.find("li:last"));
                    _ID.find("ul").css({
                        "top": 0
                    });
                });
            }
            if (direction == "fade") {
                if (fade > 0) {
                    fade--;
                } else {
                    fade = ID_liLen - 1
                }
                _ID.find("li").stop(true, true).eq(fade).fadeIn(speed).siblings().fadeOut(speed);
            }
            if (jsq < ID_liLen - 1) {
                jsq++;
                _btnBox.find("span").eq(jsq).addClass("cur").siblings().removeClass("cur");
            } else {
                jsq = 0;
                _btnBox.find("span").eq(jsq).addClass("cur").siblings().removeClass("cur");
            };
        } else {};
    });
    _btn_left.hover(function () {
        clearInterval(timer);
    }, function () {
        if (Car == true) {
            if (ID_liLen > number) {
                timer = setInterval(Carousel, Interval);
            } else {
                clearInterval(timer);
                _btn_left.hide();
                _btn_right.hide();
                _btnBox.hide();
            }
        } else {
            clearInterval(timer);
        }
    }).click(function () {
        if (new Date - new_time > 500) {
            new_time = new Date;
            if (direction == "left" || direction == "right") {
                _ID.find("li:last").insertBefore(_ID.find("li:first"));
                _ID.find("ul").css({
                    "left": -moveLengh
                });
                _ID.find("ul").stop().animate({
                    left: 0
                }, speed);
            }
            if (direction == "top" || direction == "bottom") {
                _ID.find("li:last").insertBefore(_ID.find("li:first"));
                _ID.find("ul").css({
                    "top": -moveLengh
                });
                _ID.find("ul").stop().animate({
                    top: 0
                }, speed);
            }
            if (direction == "fade") {
                if (fade < ID_liLen - 1) {
                    fade++;
                } else {
                    fade = 0
                }
                _ID.find("li").stop(true, true).eq(fade).fadeIn(speed).siblings().fadeOut(speed);
            }
            if (jsq > 0) {
                jsq--;
                _btnBox.find("span").eq(jsq).addClass("cur").siblings().removeClass("cur");
            } else {
                jsq = ID_liLen - 1;
                _btnBox.find("span").eq(jsq).addClass("cur").siblings().removeClass("cur");
            };
        } else {};
    });
    _btnBox.find("span").hover(function () {
        clearInterval(timer);
    }, function () {
        if (Car == true) {
            if (ID_liLen > number) {
                timer = setInterval(Carousel, Interval);
            } else {
                clearInterval(timer);
                _btn_left.hide();
                _btn_right.hide();
                _btnBox.hide();
            }
        } else {
            clearInterval(timer);
        }
    }).click(function () {
        if (new Date - new_time > 500) {
            new_time = new Date;
            cbtmBtn = $(this).index();
            $(this).addClass("cur").siblings().removeClass("cur");
            if (direction == "fade") {
                _ID.find("li").eq(cbtmBtn).fadeIn(speed).siblings().fadeOut(speed);
            } else {
                if (cbtmBtn > jsq) {
                    cj = cbtmBtn - jsq;
                    jsq = cbtmBtn;
                    _ID.find("ul").stop().animate({
                        left: -moveLengh * cj
                    }, speed, function () {
                        for (i = 0; i < cj; i++) {
                            _ID.find("ul").css({
                                "left": 0
                            })
                            _ID.find("li:first").insertAfter(_ID.find("li:last"));
                        };
                    });
                } else {
                    cj = jsq - cbtmBtn;
                    jsq = cbtmBtn;
                    _ID.find("ul").css({
                        "left": -moveLengh * cj
                    });
                    for (i = 0; i < cj; i++) {
                        _ID.find("ul").stop().animate({
                            left: 0
                        }, speed);
                        _ID.find("li:last").insertBefore(_ID.find("li:first"));
                    };
                };
            };
        } else {};
    });
}
(function ($) {
    $.fn.myScroll = function (options) {
        var defaults = {
            speed: 40,
            rowHeight: 24
        };
        var opts = $.extend({}, defaults, options),
            intId = [];

        function marquee(obj, step) {
            obj.find("ul").animate({
                marginTop: '-=1'
            }, 0, function () {
                var s = Math.abs(parseInt($(this).css("margin-top")));
                if (s >= step) {
                    $(this).find("li").slice(0, 1).appendTo($(this));
                    $(this).css("margin-top", 0);
                }
            });
        }
        this.each(function (i) {
            var sh = opts["rowHeight"],
                speed = opts["speed"],
                _this = $(this);
            intId[i] = setInterval(function () {
                if (_this.find("ul").height() <= _this.height()) {
                    clearInterval(intId[i]);
                } else {
                    marquee(_this, sh);
                }
            }, speed);
            _this.hover(function () {
                clearInterval(intId[i]);
            }, function () {
                intId[i] = setInterval(function () {
                    if (_this.find("ul").height() <= _this.height()) {
                        clearInterval(intId[i]);
                    } else {
                        marquee(_this, sh);
                    }
                }, speed);
            });
        });
    }
})(jQuery);