(function($){

    $.dealsDefaults = {
        vertical: true,
        btnNext: ".next",
        btnPrev: ".prev",
        interval: 10000,
        speed: 1000,
        scroll: -1,
        visible: 1,
        limit: 5
    };

    var settings = {};

    var methods = {
        init : function(opts) {

            $.extend(true, settings, $.dealsDefaults);

            if (opts) {
                $.extend(true, settings, opts);
            }

            return this.each(function() {
                routines.build.apply(this, [settings]);
            });
        }
    };


    var routines = {
        build: function(opts){
            var _root = this;
            var data = {};
            
            $.get('/latest_deals.php?limit=' + opts.limit, function(html){
                $(_root)
                    .empty()
                    .append(html)
                    .jCarouselLite({
                        vertical: opts.vertical,
                        btnNext: opts.btnNext,
                        btnPrev: opts.btnPrev,
                        auto: opts.interval,
                        speed: opts.speed,
                        scroll: opts.scroll,
                        visible: opts.visible
                    });                            
            });
            
            

            
        }
    };

    $.fn.deals = function(method) {
        if ( methods[method] ) {
            return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
            return methods.init.apply( this, arguments );
        } else {
            $.error( 'Method ' +  method + ' does not exist on jQuery.deals' );
        }
    };
})(jQuery);
