(function($) {
    $.fn.Adv = function(_properties) {
        return this.each(function() {
            $.fn.Adv.init($(this));
        })
    }
    $.fn.Adv.init = function(_this) {
        this.activeAdv = 0;
        _container = $("#ourAdvContainer", _this);
        _next = $(".next", _this);
        _prev = $(".prev", _this);
        _prev.addClass("disactive");
        _links = $("a", _container);
        this.animateCont = $("ul", _container);
        _li = $("li", this.animateCont);
        this.advAmount = _li.size();
        this.defaultWidth = 249//_li.eq(this.activeAdv).width()
        this.animateCont.width(this.advAmount * this.defaultWidth)
        _next.click(function() {
            if ($.fn.Adv.activeAdv < $.fn.Adv.advAmount - 1 && ($.fn.Adv.advAmount - 1) - $.fn.Adv.activeAdv > 2) {
                $(".prev", _this).removeClass("disactive");
                $.fn.Adv.activeAdv++;
                $.fn.Adv.animateMe();
                if (($.fn.Adv.advAmount - 1) - $.fn.Adv.activeAdv == 2) {
                    $(".next", _this).addClass("disactive");
                }
            }
            return false;
        });
        _prev.click(function() {
            if ($.fn.Adv.activeAdv > 0) {
                $(".next", _this).removeClass("disactive");
                $.fn.Adv.activeAdv--;
                $.fn.Adv.animateMe();
                if ($.fn.Adv.activeAdv <= 0) {
                    $(".prev", _this).addClass("disactive");
                }
            }
            return false;
        });

        _links.hover(
            function() {
                 $(this).find("span").stop().animate({ top: 0 }, { "duration": 300 });
            }, 
            function() {
                 $(this).find("span").stop().animate({ top: 118 }, { "duration": 300 });
            }
        )


    }
    $.fn.Adv.animateMe = function() {

        this.animateCont.animate({ left: -this.defaultWidth * this.activeAdv }, { "duration": "slow" });
    }
    $.fn.Adv.defaultWidth = null;
    $.fn.Adv.activeAdv = null;
    $.fn.Adv.advAmount = null;
    $.fn.Adv.animateCont = null;
})(jQuery);


