var showcase = {
        refresh_rate: 5,
        increment_by: 20,
        wait_time: 11500,
        slide_width: 860,

        i: 0,
        pause_var: 0,
        $: function(id) {
            return document.getElementById(id);
        },
        handler: function() {
            if (!this.pause()) {
                this.scroll_to(this.loc() + this.increment_by);
            }
        },

        pause: function() {
            if (this.loc() % this.slide_width < this.increment_by && this.pause_var < this.wait_time) {
                if (this.pause_var === 0) {
                    this.scroll_to(this.loc() - this.loc() % this.slide_width);
                }
                this.pause_var += this.increment_by;
                return 1;
            } else {
                return 0;
            }
        },

        scroll_to: function(x) {
            var $ = this.$;
            $("showcase").scrollLeft = x;
            if (this.loc() == x - this.increment_by || this.loc() == x - this.slide_width) {
                this.scroll_to(0);
            }

            if (x < 0) {
                while (this.$("btn" + this.i)) {
                    this.i++;
                }
                this.scroll_to(this.slide_width * (i - 1));
                this.i = 0;
            }

            this.pause_var = 0;
            if (this.loc() % this.slide_width === 0) {
                while ($("btn" + this.i)) {
                    if (this.loc() / this.slide_width == this.i) {
                        $("btn" + (this.loc() / this.slide_width)).src = "img/small_circle_focus.gif";
                        $("captionbox").style.left = $("btn" + this.i).offsetLeft - $("reference_img").offsetLeft - $("caption" + this.i).value.length * 3 + 4 + "px";
                        $("captionbox").innerHTML = $("caption" + this.i).value;
                    } else {
                        $("btn" + this.i).src = "img/gray_dot.gif";
                    }
                    this.i++;
                }
            }
            this.i = 0;
        },

        loc: function() {
            return this.$("showcase").scrollLeft;
        },

        button_click: function(position, obj) {
            this.scroll_to(position);
            clearInterval(interval1);
        },

        button_hover: function(obj, i) {
            var $ = this.$;
            if (obj != this.$("btn" + (this.loc() / this.slide_width))) {		
                obj.src = "img/small_circle_hover.gif";
            }
            $("captionboxsmall").style.visibility = "visible";
            $("captionboxsmall").style.left = $("btn" + i).offsetLeft - $("reference_img").offsetLeft - $("caption" + i).value.length * 3 + 4 + "px";
            $("captionboxsmall").innerHTML = $("caption" + i).value;
        },

        button_out: function(obj) {
            if (obj != this.$("btn" + (this.loc() / this.slide_width))) {
                obj.src = "img/gray_dot.gif";
            }
            this.$("captionboxsmall").style.visibility = "hidden";
        }
    };

var interval1 = self.setInterval("showcase.handler()", showcase.refresh_rate);
