    function BannerRotator(parentId, duration){
        this.contener = $('#'+parentId);
        $(this.contener).addClass('bannerRotator');
        this.duration = duration;
    }


    BannerRotator.prototype = {
        contener: null,
        items: [],
        actualDisplayItem: -1,
        timer: null,
        animatingNow: false,
        duration: 6000,

        show: function(){
            this.insertItems();
            this.mixItems();
            this.displaySelector();
            this.startRotation();
        },

        insertItems: function(){
            var bannerRotator = this;

            $(this.contener).children(':not(ul)').each(function(index, element){
                bannerRotator.insertItem(element);
            });
        },

        insertItem: function(item){
            this.items.push(item);
        },


        mixItems: function(){
            function shuffle (v){
                for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);
                return v;
            };


            this.items = shuffle(this.items);
        },

        hideItems: function(){
            for (var i = 0;i<this.items.length;i++){
                $(this.items[i]).css('display', 'none');
            }
        },


        startRotation: function(){
            if( this.items.length>0 ){
                this.hideItems();
                this.actualDisplayItem = -1;

                this.rotateNext();
            }
        },


        rotateNext: function(){
            var obj = this;

            if( this.animatingNow )
                return false;


            this.animatingNow = true;


             if( obj.actualDisplayItem>-1 )
                $( obj.items[obj.actualDisplayItem] ).fadeOut('fast', function(){
                    obj.selectNextItem();
                    $( obj.items[obj.actualDisplayItem] ).fadeIn('fast', function(){
                        obj.animatingNow = false;
                    });
                });

             else{
                obj.selectNextItem();
                $( obj.items[obj.actualDisplayItem] ).fadeIn('fast', function(){
                    obj.animatingNow = false;
                });
             }

             var obj=this;
             this.timer = setTimeout(function(){obj.rotateNext();}, this.duration);
        },



        selectNextItem: function(){
            this.actualDisplayItem++;

            if( this.actualDisplayItem>this.items.length-1 )
                this.actualDisplayItem = 0;

            this.higlightSelector();
        },



        selectItem: function(index){
            if( this.animatingNow )
                return false;

            this.animatingNow = true;

            clearTimeout(this.timer);

            var obj = this;

             if( obj.actualDisplayItem>-1 ){
                $( obj.items[obj.actualDisplayItem] ).fadeOut('fast', function(){
                    obj.actualDisplayItem = index;
                    $( obj.items[obj.actualDisplayItem] ).fadeIn('fast', function(){
                        obj.animatingNow = false;
                    });
                });
             }
             else{
                obj.actualDisplayItem = index;
                $( obj.items[obj.actualDisplayItem] ).fadeIn('fast', function(){
                    obj.animatingNow = false;
                });
             }

             obj.actualDisplayItem = index;
             obj.higlightSelector();


             obj.timer = setTimeout(function(){obj.rotateNext();}, this.duration);
        },


        displaySelector: function(){
            var obj = this;


            $(this.contener).append('<span class="selectorInfo">REKLAMA: </span>');
            $(this.contener).append('<ul />');

            for (var i = 0;i<this.items.length;i++){
                $(this.contener).children('ul').append('<li>'+(i)+'</li>');
            }

            $(this.contener).children('ul').children('li').each(function(index, element){
                $(element).click( function(){
                    obj.selectItem(index); } );


            })
        },

        higlightSelector: function(){
            var obj = this;

            $(this.contener).children('ul').children('li').removeClass('actual');

            $(this.contener).children('ul').children('li:nth-child('+(obj.actualDisplayItem+1)+')').addClass('actual');
        }
    }

