(function($) {
    $.tools = $.tools || {};
    $.tools.scrollable = {
        version: '1.1.2',
        conf: {
            size: 5,
            vertical: false,
            speed: 400,
            keyboard: true,
            keyboardSteps: null,
            disabledClass: 'disabled',
            hoverClass: null,
            clickable: true,
            activeClass: 'active',
            easing: 'swing',
            loop: false,
            items: '.items',
            item: null,
            prev: '.prev',
            next: '.next',
            prevPage: '.prevPage',
            nextPage: '.nextPage',
            api: false
        }
    };
    var current;
    function Scrollable(root, conf) {
        var self = this,
        $self = $(this),
        horizontal = !conf.vertical,
        wrap = root.children(),
        index = 0,
        forward;
        if (!current) {
            current = self
        }
        $.each(conf, 
        function(name, fn) {
            if ($.isFunction(fn)) {
                $self.bind(name, fn)
            }
        });
        if (wrap.length > 1) {
            wrap = $(conf.items, root)
        }
        function find(query) {
            var els = $(query);
            return conf.globalNav ? els: root.parent().find(query)
        }
        root.data("finder", find);
        var prev = find(conf.prev),
        next = find(conf.next),
        prevPage = find(conf.prevPage),
        nextPage = find(conf.nextPage);
        $.extend(self, {
            getIndex: function() {
                return index
            },
            getClickIndex: function() {
                var items = self.getItems();
                return items.index(items.filter("." + conf.activeClass))
            },
            getConf: function() {
                return conf
            },
            getSize: function() {
                return self.getItems().size()
            },
            getPageAmount: function() {
                return Math.ceil(this.getSize() / conf.size)
            },
            getPageIndex: function() {
                return Math.ceil(index / conf.size)
            },
            getNaviButtons: function() {
                return prev.add(next).add(prevPage).add(nextPage)
            },
            getRoot: function() {
                return root
            },
            getItemWrap: function() {
                return wrap
            },
            getItems: function() {
                return wrap.children(conf.item)
            },
            getVisibleItems: function() {
                return self.getItems().slice(index, index + conf.size)
            },
            seekTo: function(i, time, fn) {
                if (i < 0) {
                    i = 0
                }
                if (index === i) {
                    return self
                }
                if ($.isFunction(time)) {
                    fn = time
                }
                if (i > self.getSize() - conf.size) {
                    return conf.loop ? self.begin() : this.end()
                }
                var item = self.getItems().eq(i);
                if (!item.length) {
                    return self
                }
                var e = $.Event("onBeforeSeek");
                $self.trigger(e, [i]);
                if (e.isDefaultPrevented()) {
                    return self
                }
                if (time === undefined || $.isFunction(time)) {
                    time = conf.speed
                }
                function callback() {
                    if (fn) {
                        fn.call(self, i)
                    }
                    $self.trigger("onSeek", [i])
                }
                if (horizontal) {
                    wrap.animate({
                        left: -item.position().left
                    },
                    time, conf.easing, callback)
                } else {
                    wrap.animate({
                        top: -item.position().top
                    },
                    time, conf.easing, callback)
                }
                current = self;
                index = i;
                e = $.Event("onStart");
                $self.trigger(e, [i]);
                if (e.isDefaultPrevented()) {
                    return self
                }
                prev.add(prevPage).toggleClass(conf.disabledClass, i === 0);
                next.add(nextPage).toggleClass(conf.disabledClass, i >= self.getSize() - conf.size);
                return self
            },
            move: function(offset, time, fn) {
                forward = offset > 0;
                return this.seekTo(index + offset, time, fn)
            },
            next: function(time, fn) {
                return this.move(1, time, fn)
            },
            prev: function(time, fn) {
                return this.move( - 1, time, fn)
            },
            movePage: function(offset, time, fn) {
                forward = offset > 0;
                var steps = conf.size * offset;
                var i = index % conf.size;
                if (i > 0) {
                    steps += (offset > 0 ? -i: conf.size - i)
                }
                return this.move(steps, time, fn)
            },
            prevPage: function(time, fn) {
                return this.movePage( - 1, time, fn)
            },
            nextPage: function(time, fn) {
                return this.movePage(1, time, fn)
            },
            setPage: function(page, time, fn) {
                return this.seekTo(page * conf.size, time, fn)
            },
            begin: function(time, fn) {
                forward = false;
                return this.seekTo(0, time, fn)
            },
            end: function(time, fn) {
                forward = true;
                var to = this.getSize() - conf.size;
                return to > 0 ? this.seekTo(to, time, fn) : self
            },
            reload: function() {
                $self.trigger("onReload");
                return self
            },
            focus: function() {
                current = self;
                return self
            },
            click: function(i) {
                var item = self.getItems().eq(i),
                klass = conf.activeClass,
                size = conf.size;
                if (i < 0 || i >= self.getSize()) {
                    return self
                }
                if (size == 1) {
                    if (conf.loop) {
                        return self.next()
                    }
                    if (i === 0 || i == self.getSize() - 1) {
                        forward = (forward === undefined) ? true: !forward
                    }
                    return forward === false ? self.prev() : self.next()
                }
                if (size == 2) {
                    if (i == index) {
                        i--
                    }
                    self.getItems().removeClass(klass);
                    item.addClass(klass);
                    return self.seekTo(i, time, fn)
                }
                if (!item.hasClass(klass)) {
                    self.getItems().removeClass(klass);
                    item.addClass(klass);
                    var delta = Math.floor(size / 2);
                    var to = i - delta;
                    if (to > self.getSize() - size) {
                        to = self.getSize() - size
                    }
                    if (to !== i) {
                        return self.seekTo(to)
                    }
                }
                return self
            },
            bind: function(name, fn) {
                $self.bind(name, fn);
                return self
            },
            unbind: function(name) {
                $self.unbind(name);
                return self
            }
        });
        $.each("onBeforeSeek,onStart,onSeek,onReload".split(","), 
        function(i, ev) {
            self[ev] = function(fn) {
                return self.bind(ev, fn)
            }
        });
        prev.addClass(conf.disabledClass).click(function() {
            self.prev()
        });
        next.click(function() {
            self.next()
        });
        nextPage.click(function() {
            self.nextPage()
        });
        if (self.getSize() < conf.size) {
            next.add(nextPage).addClass(conf.disabledClass)
        }
        prevPage.addClass(conf.disabledClass).click(function() {
            self.prevPage()
        });
        var hc = conf.hoverClass,
        keyId = "keydown." + Math.random().toString().substring(10);
        self.onReload(function() {
            if (hc) {
                self.getItems().hover(function() {
                    $(this).addClass(hc)
                },
                function() {
                    $(this).removeClass(hc)
                })
            }
            if (conf.clickable) {
                self.getItems().each(function(i) {
                    $(this).unbind("click.scrollable").bind("click.scrollable", 
                    function(e) {
                        if ($(e.target).is("a")) {
                            return
                        }
                        return self.click(i)
                    })
                })
            }
            if (conf.keyboard) {
                $(document).unbind(keyId).bind(keyId, 
                function(evt) {
                    if (evt.altKey || evt.ctrlKey) {
                        return
                    }
                    if (conf.keyboard != 'static' && current != self) {
                        return
                    }
                    var s = conf.keyboardSteps;
                    if (horizontal && (evt.keyCode == 37 || evt.keyCode == 39)) {
                        self.move(evt.keyCode == 37 ? -s: s);
                        return evt.preventDefault()
                    }
                    if (!horizontal && (evt.keyCode == 38 || evt.keyCode == 40)) {
                        self.move(evt.keyCode == 38 ? -s: s);
                        return evt.preventDefault()
                    }
                    return true
                })
            } else {
                $(document).unbind(keyId)
            }
        });
        self.reload()
    }
    $.fn.scrollable = function(conf) {
        var el = this.eq(typeof conf == 'number' ? conf: 0).data("scrollable");
        if (el) {
            return el
        }
        var globals = $.extend({},
        $.tools.scrollable.conf);
        conf = $.extend(globals, conf);
        conf.keyboardSteps = conf.keyboardSteps || conf.size;
        this.each(function() {
            el = new Scrollable($(this), conf);
            $(this).data("scrollable", el)
        });
        return conf.api ? el: this
    }
})(jQuery); (function($) {
    $.fn.wheel = function(fn) {
        return this[fn ? "bind": "trigger"]("wheel", fn)
    };
    $.event.special.wheel = {
        setup: function() {
            $.event.add(this, wheelEvents, wheelHandler, {})
        },
        teardown: function() {
            $.event.remove(this, wheelEvents, wheelHandler)
        }
    };
    var wheelEvents = !$.browser.mozilla ? "mousewheel": "DOMMouseScroll" + ($.browser.version < "1.9" ? " mousemove": "");
    function wheelHandler(event) {
        switch (event.type) {
        case "mousemove":
            return $.extend(event.data, {
                clientX: event.clientX,
                clientY: event.clientY,
                pageX: event.pageX,
                pageY: event.pageY
            });
        case "DOMMouseScroll":
            $.extend(event, event.data);
            event.delta = -event.detail / 3;
            break;
        case "mousewheel":
            event.delta = event.wheelDelta / 120;
            break
        }
        event.type = "wheel";
        return $.event.handle.call(this, event, event.delta)
    }
    var t = $.tools.scrollable;
    t.plugins = t.plugins || {};
    t.plugins.mousewheel = {
        version: '1.0.1',
        conf: {
            api: false,
            speed: 50
        }
    };
    $.fn.mousewheel = function(conf) {
        var globals = $.extend({},
        t.plugins.mousewheel.conf),
        ret;
        if (typeof conf == 'number') {
            conf = {
                speed: conf
            }
        }
        conf = $.extend(globals, conf);
        this.each(function() {
            var api = $(this).scrollable();
            if (api) {
                ret = api
            }
            api.getRoot().wheel(function(e, delta) {
                api.move(delta < 0 ? 1: -1, conf.speed || 50);
                return false
            })
        });
        return conf.api ? ret: this
    }
})(jQuery); (function($) {
    $.tools = $.tools || {};
    $.tools.overlay = {
        version: '1.1.2',
        addEffect: function(name, loadFn, closeFn) {
            effects[name] = [loadFn, closeFn]
        },
        conf: {
            top: '10%',
            left: 'center',
            absolute: false,
            speed: 'normal',
            closeSpeed: 'fast',
            effect: 'default',
            close: null,
            oneInstance: true,
            closeOnClick: true,
            closeOnEsc: true,
            api: false,
            expose: null,
            target: null
        }
    };
    var effects = {};
    $.tools.overlay.addEffect('default', 
    function(onLoad) {
        this.getOverlay().fadeIn(this.getConf().speed, onLoad)
    },
    function(onClose) {
        this.getOverlay().fadeOut(this.getConf().closeSpeed, onClose)
    });
    var instances = [];
    function Overlay(trigger, conf) {
        var self = this,
        $self = $(this),
        w = $(window),
        closers,
        overlay,
        opened,
        expose = conf.expose && $.tools.expose.version;
        var jq = conf.target || trigger.attr("rel");
        overlay = jq ? $(jq) : null || trigger;
        if (!overlay.length) {
            throw "Could not find Overlay: " + jq
        }
        if (trigger && trigger.index(overlay) == -1) {
            trigger.click(function(e) {
                self.load(e);
                return e.preventDefault()
            })
        }
        $.each(conf, 
        function(name, fn) {
            if ($.isFunction(fn)) {
                $self.bind(name, fn)
            }
        });
        $.extend(self, {
            load: function(e) {
                if (self.isOpened()) {
                    return self
                }
                var eff = effects[conf.effect];
                if (!eff) {
                    throw "Overlay: cannot find effect : \"" + conf.effect + "\""
                }
                if (conf.oneInstance) {
                    $.each(instances, 
                    function() {
                        this.close(e)
                    })
                }
                e = e || $.Event();
                e.type = "onBeforeLoad";
                $self.trigger(e);
                if (e.isDefaultPrevented()) {
                    return self
                }
                opened = true;
                if (expose) {
                    overlay.expose().load(e)
                }
                var top = conf.top;
                var left = conf.left;
                var oWidth = overlay.outerWidth({
                    margin: true
                });
                var oHeight = overlay.outerHeight({
                    margin: true
                });
                if (typeof top == 'string') {
                    top = top == 'center' ? Math.max((w.height() - oHeight) / 2, 0) : parseInt(top, 10) / 100 * w.height()
                }
                if (left == 'center') {
                    left = Math.max((w.width() - oWidth) / 2, 0)
                }


                if (!conf.absolute) {
                    top += w.scrollTop();
                    left += w.scrollLeft()
                }
                overlay.css({
                    top: top,
                    left: left,
                    position: 'absolute'
                });
                e.type = "onStart";
                $self.trigger(e);
                eff[0].call(self, 
                function() {
                    if (opened) {
                        e.type = "onLoad";
                        $self.trigger(e)
                    }
                });
                if (conf.closeOnClick) {
                    $(document).bind("click.overlay", 
                    function(e) {
                        if (!self.isOpened()) {
                            return
                        }
                        var et = $(e.target);
                        if (et.parents(overlay).length > 1) {
                            return
                        }
                        $.each(instances, 
                        function() {
                            this.close(e)
                        })
                    })
                }
                if (conf.closeOnEsc) {
                    $(document).unbind("keydown.overlay").bind("keydown.overlay", 
                    function(e) {
                        if (e.keyCode == 27) {
                            $.each(instances, 
                            function() {
                                this.close(e)
                            })
                        }
                    })
                }
                return self
            },
            close: function(e) {
                if (!self.isOpened()) {
                    return self
                }
                e = e || $.Event();
                e.type = "onBeforeClose";
                $self.trigger(e);
                if (e.isDefaultPrevented()) {
                    return
                }
                opened = false;
                effects[conf.effect][1].call(self, 
                function() {
                    e.type = "onClose";
                    $self.trigger(e)
                });
                var allClosed = true;
                $.each(instances, 
                function() {
                    if (this.isOpened()) {
                        allClosed = false
                    }
                });
                if (allClosed) {
                    $(document).unbind("click.overlay").unbind("keydown.overlay")
                }
                return self
            },
            getContent: function() {
                return overlay
            },
            getOverlay: function() {
                return overlay
            },
            getTrigger: function() {
                return trigger
            },
            getClosers: function() {
                return closers
            },
            isOpened: function() {
                return opened
            },
            getConf: function() {
                return conf
            },
            bind: function(name, fn) {
                $self.bind(name, fn);
                return self
            },
            unbind: function(name) {
                $self.unbind(name);
                return self
            }
        });
        $.each("onBeforeLoad,onStart,onLoad,onBeforeClose,onClose".split(","), 
        function(i, ev) {
            self[ev] = function(fn) {
                return self.bind(ev, fn)
            }
        });
        if (expose) {
            if (typeof conf.expose == 'string') {
                conf.expose = {
                    color: conf.expose
                }
            }
            $.extend(conf.expose, {
                api: true,
                closeOnClick: conf.closeOnClick,
                closeOnEsc: false
            });
            var ex = overlay.expose(conf.expose);
            ex.onBeforeClose(function(e) {
                self.close(e)
            });
            self.onClose(function(e) {
                ex.close(e)
            })
        }
        closers = overlay.find(conf.close || ".close");
        if (!closers.length && !conf.close) {
            closers = $('<div class="close"></div>');
            overlay.prepend(closers)
        }
        closers.click(function(e) {
            self.close(e)
        })
    }
    $.fn.overlay = function(conf) {
        var el = this.eq(typeof conf == 'number' ? conf: 0).data("overlay");
        if (el) {
            return el
        }
        if ($.isFunction(conf)) {
            conf = {
                onBeforeLoad: conf
            }
        }
        var globals = $.extend({},
        $.tools.overlay.conf);
        conf = $.extend(true, globals, conf);
        this.each(function() {
            el = new Overlay($(this), conf);
            instances.push(el);
            $(this).data("overlay", el)
        });
        return conf.api ? el: this
    }
})(jQuery); (function($) {
    $.tools = $.tools || {};
    $.tools.expose = {
        version: '1.0.5',
        conf: {
            maskId: null,
            loadSpeed: 'slow',
            closeSpeed: 'fast',
            closeOnClick: true,
            closeOnEsc: true,
            zIndex: 9998,
            opacity: 0.8,
            color: '#456',
            api: false
        }
    };
    function viewport() {
        if ($.browser.msie) {
            var d = $(document).height(),
            w = $(window).height();
            return [window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth, d - w < 20 ? w: d]
        }
        return [$(window).width(), $(document).height()]
    }
    function Expose(els, conf) {
        var self = this,
        $self = $(this),
        mask = null,
        loaded = false,
        origIndex = 0;
        $.each(conf, 
        function(name, fn) {
            if ($.isFunction(fn)) {
                $self.bind(name, fn)
            }
        });
        $(window).resize(function() {
            self.fit()
        });
        $.extend(this, {
            getMask: function() {
                return mask
            },
            getExposed: function() {
                return els
            },
            getConf: function() {
                return conf
            },
            isLoaded: function() {
                return loaded
            },
            load: function(e) {
                if (loaded) {
                    return self
                }
                origIndex = els.eq(0).css("zIndex");
                if (conf.maskId) {
                    mask = $("#" + conf.maskId)
                }
                if (!mask || !mask.length) {
                    var size = viewport();
                    mask = $('<div/>').css({
                        position: 'absolute',
                        top: 0,
                        left: 0,
                        width: size[0],
                        height: size[1],
                        display: 'none',
                        opacity: 0,
                        zIndex: conf.zIndex
                    });
                    if (conf.maskId) {
                        mask.attr("id", conf.maskId)
                    }
                    $("body").append(mask);
                    var bg = mask.css("backgroundColor");
                    if (!bg || bg == 'transparent' || bg == 'rgba(0, 0, 0, 0)') {
                        mask.css("backgroundColor", conf.color)
                    }
                    if (conf.closeOnEsc) {
                        $(document).bind("keydown.unexpose", 
                        function(evt) {
                            if (evt.keyCode == 27) {
                                self.close()
                            }
                        })
                    }
                    if (conf.closeOnClick) {
                        mask.bind("click.unexpose", 
                        function(e) {
                            self.close(e)
                        })
                    }
                }
                e = e || $.Event();
                e.type = "onBeforeLoad";
                $self.trigger(e);
                if (e.isDefaultPrevented()) {
                    return self
                }
                $.each(els, 
                function() {
                    var el = $(this);
                    if (!/relative|absolute|fixed/i.test(el.css("position"))) {
                        el.css("position", "relative")
                    }
                });
                els.css({
                    zIndex: Math.max(conf.zIndex + 1, origIndex == 'auto' ? 0: origIndex)
                });
                var h = mask.height();
                if (!this.isLoaded()) {
                    mask.css({
                        opacity: 0,
                        display: 'block'
                    }).fadeTo(conf.loadSpeed, conf.opacity, 
                    function() {
                        if (mask.height() != h) {
                            mask.css("height", h)
                        }
                        e.type = "onLoad";
                        $self.trigger(e)
                    })
                }
                loaded = true;
                return self
            },
            close: function(e) {
                if (!loaded) {
                    return self
                }
                e = e || $.Event();
                e.type = "onBeforeClose";
                $self.trigger(e);
                if (e.isDefaultPrevented()) {
                    return self
                }
                mask.fadeOut(conf.closeSpeed, 
                function() {
                    e.type = "onClose";
                    $self.trigger(e);
                    els.css({
                        zIndex: $.browser.msie ? origIndex: null
                    })
                });
                loaded = false;
                return self
            },
            fit: function() {
                if (mask) {
                    var size = viewport();
                    mask.css({
                        width: size[0],
                        height: size[1]
                    })
                }
            },
            bind: function(name, fn) {
                $self.bind(name, fn);
                return self
            },
            unbind: function(name) {
                $self.unbind(name);
                return self
            }
        });
        $.each("onBeforeLoad,onLoad,onBeforeClose,onClose".split(","), 
        function(i, ev) {
            self[ev] = function(fn) {
                return self.bind(ev, fn)
            }
        })
    }
    $.fn.expose = function(conf) {
        var el = this.eq(typeof conf == 'number' ? conf: 0).data("expose");
        if (el) {
            return el
        }
        if (typeof conf == 'string') {
            conf = {
                color: conf
            }
        }
        var globals = $.extend({},
        $.tools.expose.conf);
        conf = $.extend(globals, conf);
        this.each(function() {
            el = new Expose($(this), conf);
            $(this).data("expose", el)
        });
        return conf.api ? el: this
    }
})(jQuery); (function($) {
    var t = $.tools.overlay;
    t.plugins = t.plugins || {};
    t.plugins.gallery = {
        version: '1.0.0',
        conf: {
            imgId: 'img',
            next: '.PicNext',
            prev: '.PicPrev',
            info: '.info',
            progress: '.progress',
            disabledClass: 'disabled',
            activeClass: 'active',
            opacity: 0.8,
            speed: 'slow',
            template: '<strong>${title}</strong> <span>${index} / ${total}</span>',
            autohide: true,
            preload: true,
            api: false
        }
    };
    $.fn.gallery = function(opts) {
        var conf = $.extend({},
        t.plugins.gallery.conf),
        api;
        $.extend(conf, opts);
        api = this.overlay();
        var links = this,
        overlay = api.getOverlay(),
        next = overlay.find(conf.next),
        prev = overlay.find(conf.prev),
        info = overlay.find(conf.info),
        progress = overlay.find(conf.progress),
        els = prev.add(next).add(info).css({
            opacity: conf.opacity
        }),
        close = api.getClosers(),
        index;
        function load(el) {
            progress.fadeIn();
            els.hide();
            close.hide();
            var url = el.attr("href");
            var image = new Image();
            image.onload = function() {
                progress.fadeOut();
                var img = $("#" + conf.imgId, overlay);
                if (!img.length) {
                    img = $("<img/>").attr("id", conf.imgId).css("visibility", "hidden");
                    overlay.prepend(img)
                }
                img.attr("src", url).css("visibility", "hidden");
                var width = image.width;
                var left = ($(window).width() - width) / 2;
                index = links.index(links.filter("[href='" + url + "']"));
                links.removeClass(conf.activeClass).eq(index).addClass(conf.activeClass);
                var cls = conf.disabledClass;
                els.removeClass(cls);
                if (index === 0) {
                    prev.addClass(cls)
                }
                if (index == links.length - 1) {
                    next.addClass(cls)
                }
                var text = conf.template.replace("${title}", el.attr("name") || el.data("title")).replace("${index}", index + 1).replace("${total}", links.length);
                var padd = parseInt(info.css("paddingLeft"), 10) + parseInt(info.css("paddingRight"), 10);
                info.html(text).css({
                    width: width - padd
                });
                overlay.animate({
                    width: width,
                    height: image.height,
                    left: left
                },
                conf.speed, 
                function() {
                    img.hide().css("visibility", "visible").fadeIn(function() {
                        if (!conf.autohide) {
                            els.fadeIn();
                            close.show()
                        }
                    })
                })
            };
            image.onerror = function() {
                overlay.fadeIn().html("Cannot find image " + url)
            };
            image.src = url;
            if (conf.preload) {
                links.filter(":eq(" + (index - 1) + "), :eq(" + (index + 1) + ")").each(function() {
                    var img = new Image();
                    img.src = $(this).attr("href")
                })
            }
        }
        function addClick(el, isNext) {
            el.click(function() {
                if (el.hasClass(conf.disabledClass)) {
                    return
                }
                var trigger = links.eq(i = index + (isNext ? 1: -1));
                if (trigger.length) {
                    load(trigger)
                }
            })
        }
        addClick(next, true);
        addClick(prev);
        $(document).keydown(function(evt) {
            if (!overlay.is(":visible") || evt.altKey || evt.ctrlKey) {
                return
            }
            if (evt.keyCode == 37 || evt.keyCode == 39) {
                var btn = evt.keyCode == 37 ? prev: next;
                btn.click();
                return evt.preventDefault()
            }
            return true
        });
        function showEls() {
            if (!overlay.is(":animated")) {
                els.show();
                close.show()
            }
        }
        if (conf.autohide) {
            overlay.hover(showEls, 
            function() {
                els.fadeOut();
                close.hide()
            }).mousemove(showEls)
        }
        var ret;
        this.each(function() {
            var el = $(this),
            api = $(this).overlay(),
            ret = api;
            api.onBeforeLoad(function() {
                load(el)
            });
            api.onClose(function() {
                links.removeClass(conf.activeClass)
            })
        });
        return conf.api ? ret: this
    }
})(jQuery); (function($) {
    $.fn.easySlider = function(options) {
        var defaults = {
            prevId: 'prevBtn',
            prevText: 'Previous',
            nextId: 'nextBtn',
            nextText: 'Next',
            controlsShow: true,
            controlsBefore: '',
            controlsAfter: '',
            controlsFade: true,
            firstId: 'firstBtn',
            firstText: 'First',
            firstShow: false,
            lastId: 'lastBtn',
            lastText: 'Last',
            lastShow: false,
            vertical: false,
            speed: 500,
            auto: true,
            pause: 2000,
            continuous: true,
            pagenum: 7,
            marginLeftRight: 14,
			marginTopBottom: 1
        };
        var options = $.extend(defaults, options);
        this.each(function() {
            var obj = $(this);
            var s = $("li", obj).length;
            var w = $("li", obj).width();
            var h = $("li", obj).height();
            obj.width(options.pagenum * (w + options.marginLeftRight));
            obj.height(h + options.marginTopBottom);
            obj.css("overflow", "hidden");
            var ts = s - options.pagenum;
            var t = 0;
            $("ul", obj).css('width', s * (w + options.marginLeftRight));
            if (!options.vertical) $("li", obj).css('float', 'left');
            if (options.controlsShow) {
                var html = options.controlsBefore;
                if (options.firstShow) html += '<span id="' + options.firstId + '"><a href=\"javascript:void(0);\" onfocus=\"this.blur()\">' + options.firstText + '</a></span>';
                html += ' <span id="' + options.prevId + '"><a href=\"javascript:void(0);\" onfocus=\"this.blur()\">' + options.prevText + '</a></span>';
                html += ' <span id="' + options.nextId + '"><a href=\"javascript:void(0);\" onfocus=\"this.blur()\">' + options.nextText + '</a></span>';
                if (options.lastShow) html += ' <span id="' + options.lastId + '"><a href=\"javascript:void(0);\" onfocus=\"this.blur()\">' + options.lastText + '</a></span>';
                html += options.controlsAfter;
                $(obj).after(html)
            };
            $("a", "#" + options.nextId).click(function() {
                animate("next", true)
            });
            $("a", "#" + options.prevId).click(function() {
                animate("prev", true)
            });
            $("a", "#" + options.firstId).click(function() {
                animate("first", true)
            });
            $("a", "#" + options.lastId).click(function() {
                animate("last", true)
            });
            function animate(dir, clicked) {
                var ot = t;
                switch (dir) {
                case "next":
                    t = (ot >= ts) ? (options.continuous ? 0: ts) : t + 1;
                    break;
                case "prev":
                    t = (t <= 0) ? (options.continuous ? ts: 0) : t - 1;
                    break;
                case "first":
                    t = 0;
                    break;
                case "last":
                    t = ts;
                    break;
                default:
                    break
                };
                var diff = Math.abs(ot - t);
                var speed = diff * options.speed;
                if (!options.vertical) {
                    p = (t * (w + options.marginLeftRight) * -1);
                    $("ul", obj).animate({
                        marginLeft: p
                    },
                    speed)
                } else {
                    p = (t * h * -1);
                    $("ul", obj).animate({
                        marginTop: p
                    },
                    speed)
                };
                if (!options.continuous && options.controlsFade) {
                    if (t == ts) {
                        $("a", "#" + options.nextId).hide();
                        $("a", "#" + options.lastId).hide()
                    } else {
                        $("a", "#" + options.nextId).show();
                        $("a", "#" + options.lastId).show()
                    };
                    if (t == 0) {
                        $("a", "#" + options.prevId).hide();
                        $("a", "#" + options.firstId).hide()
                    } else {
                        $("a", "#" + options.prevId).show();
                        $("a", "#" + options.firstId).show()
                    }
                };
                if (clicked) clearTimeout(timeout);
                if (options.auto && dir == "next" && !clicked) {;
                    timeout = setTimeout(function() {
                        animate("next", false)
                    },
                    diff * options.speed + options.pause)
                }
            };
            var timeout;
            if (options.auto) {;
                timeout = setTimeout(function() {
                    animate("next", false)
                },
                options.pause)
            };
            if (!options.continuous && options.controlsFade) {
                $("a", "#" + options.prevId).hide();
                $("a", "#" + options.firstId).hide()
            }
        })
    }
})(jQuery);
