(function (a) {

    a.fn.easySlider = function (c) {

        var b = {
            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: 800,
            auto: false,
            pause: 4000,
            continuous: false,
            numeric: false,
            numericId: 'controls',
            hideArrows: false
        };

        var c = a.extend(b, c);

        a("#slider li").css("visibility", "visible");

        this.each(function () {
            var d = a(this);
            var o = a("li", d).length;
            if (o <= 0) { return }
            var r = a("li", d).width();
            var u = a("li", d).height();
            var j = true;
            d.width(r);
            d.height(u);
            d.css("overflow", "hidden");
            var e = o - 1;
            var q = 0;
            a("ul", d).css('width', o * r);
            if (c.continuous) {
                a("ul", d).prepend(a("ul li:last-child", d).clone().css("margin-left", "-" + r + "px"));
                a("ul", d).append(a("ul li:nth-child(2)", d).clone());
                a("ul", d).css('width', (o + 1) * r);
            };
            if (!c.vertical) {
                a("li", d).css('float', 'left');
            }
            if (c.controlsShow) {
                var f = c.controlsBefore;
                if (c.numeric) {
                    f += '<ol id="' + c.numericId + '"></ol>';
                }
                else {
                    if (c.firstShow) {
                        f += '<span id="' + c.firstId + '"><a href="javascript:void(0);">' + c.firstText + '</a></span>';
                    }
                    f += ' <span class="image" id="' + c.prevId + '"><a href="javascript:void(0);">' + c.prevText + '</a></span>';
                    f += ' <span class="image" id="' + c.nextId + '"><a href="javascript:void(0);">' + c.nextText + '</a></span>';
                    if (c.lastShow) {
                        f += ' <span id="' + c.lastId + '"><a href="javascript:void(0);">' + c.lastText + '</a></span>';
                    }
                };
                f += c.controlsAfter;
                a(d).after(f);
            };
            if (c.numeric) {
                for (var l = 0; l < o; l++) {
                    a(document.createElement("li"))
						.attr('id', c.numericId + (l + 1))
						.html('<a rel=' + l + ' href="javascript:void(0);">' + (l + 1) + '</a>')
						.appendTo(a("#" + c.numericId))
						.click(function () {
						    n(a("a", a(this)).attr('rel'), true);
						});
                };
            }
            else {
                a("#" + c.nextId).click(function () { n("next", true); });
                a("#" + c.prevId).click(function () { n("prev", true); });
                a("#" + c.firstId).click(function () { n("first", true); });
                a("#" + c.lastId).click(function () { n("last", true); });
            };
            function g(h) {
                h = parseInt(h) + 1;
                a("li", "#" + c.numericId).removeClass("current");
                a("li#" + c.numericId + h).addClass("current");
            };

            function m() {
                if (q > e) q = 0;
                if (q < 0) q = e;
                if (!c.vertical) {
                    a("ul", d).css("margin-left", (q * r * -1));
                } else {
                    a("ul", d).css("margin-left", (q * u * -1));
                }
                j = true;
                if (c.numeric) g(q);
            };

            function n(h, i) {
                if (j) {
                    j = false;
                    var s = q;
                    switch (h) {
                        case "next":
                            q = (s >= e) ? (c.continuous ? q + 1 : e) : q + 1;
                            break;
                        case "prev":
                            q = (q <= 0) ? (c.continuous ? q - 1 : 0) : q - 1;
                            break;
                        case "first":
                            q = 0;
                            break;
                        case "last":
                            q = e;
                            break;
                        default:
                            q = h;
                            break;
                    };
                    var t = Math.abs(s - q);
                    var v = t * c.speed;
                    if (!c.vertical) {
                        p = (q * r * -1);
                        a("ul", d).animate(
							{ marginLeft: p },
							{ queue: false, duration: v, complete: m }
						);
                    } else {
                        p = (q * u * -1);
                        a("ul", d).animate(
							{ marginTop: p },
							{ queue: false, duration: v, complete: m }
						);
                    };

                    if (!c.continuous && c.controlsFade) {
                        if (q == e) {
                            a("#" + c.nextId).hide();
                            a("#" + c.lastId).hide();
                        } else {
                            a("#" + c.nextId).show();
                            a("#" + c.lastId).show();
                        };
                        if (q == 0) {
                            a("#" + c.prevId).hide();
                            a("#" + c.firstId).hide();
                        } else {
                            a("#" + c.prevId).show();
                            a("#" + c.firstId).show();
                        };
                    };

                    if (i) clearTimeout(k);
                    if (c.auto && h == "next" && !i) {
                        ;
                        k = setTimeout(function () {
                            n("next", false);
                        }, t * c.speed + c.pause);
                    };

                };

            };

            var k;
            if (c.auto) {
                ;
                k = setTimeout(function () {
                    n("next", false);
                }, c.pause);
            };

            if (c.numeric) g(0);

            if (!c.continuous && c.controlsFade) {
                a("#" + c.prevId).hide();
                a("#" + c.firstId).hide();
                if (q == e) {
                    a("#" + c.nextId).hide();
                    a("#" + c.lastId).hide();
                }
            };

        });

        if (c.hideArrows) {
            a("#" + c.prevId).css("visibility", "hidden");
            a("#" + c.nextId).css("visibility", "hidden");
            a(this).parent().mouseenter(function () {
                a("#" + c.prevId).css("visibility", "visible");
                a("#" + c.nextId).css("visibility", "visible")
            });
            a(this).parent().mouseleave(function () {
                a("#" + c.prevId).css("visibility", "hidden");
                a("#" + c.nextId).css("visibility", "hidden")
            })
        }

    };

})(jQuery);




