
(function($) {

    $.BB_Slider = function(obj, options) {
        var sl_Obj = $(obj),
            buttPrev = $(".Prev", obj),
            buttNext = $(".Next", obj),
            listBlc = $(".Images ul", sl_Obj),
            listBlcWidth = $(".Images", sl_Obj).width(),
            Pages = new Array(),
            Page  = 0;

        if (0<$(".Images li", sl_Obj).length){
        buttNext.click(function(){ if (Page+1<Pages.length) { $(listBlc).animate({"left": -Pages[Page + 1]}, options.Interval, function(){ Page++; if (Page==Pages.length-1) buttNext.hide(); }); buttPrev.show(); } });

        buttPrev.click(function(){ if (0<Page) { $(listBlc).animate({"left": -Pages[Page-1]}, options.Interval, function(){ Page--; if (Page==0) buttPrev.hide(); }); buttNext.show(); } });

        x = options.left;
        y = options.left;
        Pages.push( options.left );
        $(".Images li", sl_Obj).each(function(){ if (y + $(this).innerWidth()<listBlcWidth) { y += $(this).innerWidth () + options.left; } else { Pages.push( x ); y = $(this).innerWidth () + options.left; } x += $(this).innerWidth () + options.left; });
        Pages[Pages.length-1] = x - listBlcWidth - options.left;
        if (Pages.length<2) buttNext.hide();
} else {
sl_Obj.hide();
}
    };

    $.fn.BB_Slider = function(options) {

        defaults = { Interval: 2000 };

        var options = $.extend( defaults, options );

        this.each(function() { $(this).data('SlideShow', new $.BB_Slider(this, options)); });

        return this;
    };

})(jQuery);
