/**
 * Created by IntelliJ IDEA.
 * User: dave
 * Date: Jun 20, 2010
 * Time: 4:59:11 PM
 * To change this template use File | Settings | File Templates.
 */
(function($) {

    $.fn.flipr = function(settings) {
        lc=0;
        o=null;
        var config = {'foo': 'bar',
            'times'   :0,
            'speed'   :3000
        };

        if (settings) $.extend(config, settings);


        this.each(function() {
            init($(this));
        });

        return this;

        function init(obj) {
            o=obj;
            tw=o.width();
            th=o.height();

            images=$(o).find('img');
            $(o).find('img').remove();

            imageCount=images.length-1;
            $(o).append(images[0]);

            lc=1;
            flip();
        }

        function flip(){
            //alert('Flip');
            $(document).everyTime(config.speed, function(i){flop(i);}, config.times);   }
        };

        function flop(i) {
            //console.log('i => '+i+' lc: '+lc);
            $(o).find('img').remove();
            $(o).append(images[lc]);
            (lc == imageCount) ? lc=0 : lc++;
        }

})(jQuery);

