var bannerclass = function(id, options)
{
        var _this = this;
        this.id = id;

        this.options = options;
        if(this.options.currentid == null)
                this.options.currentid = 0;


        this.items = $('#' + this.id + '_container').children();
        this.autoTimer = null;
        this.manualTimer = null;

        this.autoSlide = function(direction)
        {
                this.autoTimer  = setTimeout(function() {
                        _this.showNextElement(direction);
                        _this.autoSlide(direction);
                        },
                this.options.timeout);

        }
        this.init = function()
        {
                if(this.options.animationtype == 'slide')
                {
                        $(this.items[0]).slideDown(this.options.speed);

                }
                else if(this.options.animationtype == 'fade')
                {
                        $(this.items[0]).fadeIn(this.options.speed);
                }
                link_sel(0);
        }

        this.showNextElement = function(direction)
        {
                if (this.items.length == 1)
                {
                     clearTimeout(this.autoTimer);
                     return 0;
                }
                current = this.options.currentid;
                link_sel(current+1);
                // right
                if(direction == null)
                {
                            if ((current+1) < this.items.length)
                            {
                                        hideItem = current;
                                        showItem = current+1;
                                        this.options.currentid = current+1;
                            }
                            else
                            {
                                        link_sel(0);
                                        hideItem = current;
                                        showItem = 0;
                                        this.options.currentid = 0;
                            }
                }
                // left
                else
                {
                            if(current > 0)
                            {
                                        hideItem = current;
                                        showItem = current-1;
                                        this.options.currentid = current-1;
                            }
                            else
                            {
                                        hideItem = current;
                                        showItem = this.items.length-1;
                                        this.options.currentid = this.items.length-1;
                            }
                }

                firstItem = this.items[showItem];
                secondItem = this.items[hideItem];

                if(this.options.animationtype == 'slide')
                {
                        $(firstItem).slideDown(this.options.speed);
                        $(secondItem).slideUp(this.options.speed);
                }
                else if(this.options.animationtype == 'fade')
                {
                        $(firstItem).fadeIn(this.options.speed);
                        $(secondItem).fadeOut(this.options.speed);
                }

        };

        this.showElement = function(direction)
        {
                clearTimeout(this.autoTimer);

                current = this.options.currentid;
                if (current != this.options.id)
                {
                        hideItem = current;
                        showItem = this.options.id;
                        this.options.currentid = this.options.id;

                        firstItem = this.items[showItem];
                        secondItem = this.items[hideItem];

                        if(this.options.animationtype == 'slide')
                        {
                               $(firstItem).slideDown(this.options.speed);
                               $(secondItem).slideUp(this.options.speed);
                        }
                        else if(this.options.animationtype == 'fade')
                        {
                               $(firstItem).fadeIn(this.options.speed);
                               $(secondItem).fadeOut(this.options.speed);
                        }
                }
        };

}

