 $(function() {

                // initialize tabs
                $('#container-1, #limited').tabs({fxFade: true});

                // set up constant rotation
                (function() {
                    // rotation interval
                    var t = 0;
                    var tabs = $('li', '#container-1').size();
                    var rotation = setInterval(function() {
                        t = ++t <= tabs ? t : 1;
                        $('#container-1').triggerTab(t);
                    }, 5000);
                    // stop rotation on tab click
                    $('#container-1>ul:eq(0)>li>a').click(function(e) {
                        if (e.clientX && rotation) { // true mouse click ocurred
                            clearInterval(rotation);
                            rotation = null;
                        }
                    });
                })();


                // setup limited rotation, for example stop after 2 rotations
                (function() {
                    // rotation interval
                    var t = 0, rotations = 0;
                    var tabs = $('li', '#limited').size();
                    var rotation = setInterval(function() {
                        t = ++t <= tabs ? t : 1;
                        if (t == 1) {
                            rotations++;
                        }
                        $('#limited').triggerTab(t);
                        if (rotations > 2 && rotation) { // stop rotation after second
                            clearInterval(rotation);
                        }
                    }, 2000);
                    // stop rotation on tab click
                    $('#limited>ul:eq(0)>li>a').click(function(e) {
                        if (e.clientX) { // true mouse click ocurred
                            clearInterval(rotation);
                            rotation = null;
                        }
                    });
                })();
            });
