var prodlist_is_switchable = {};
var prodlist_switching = {};
var prodlist_switching_direction = {};
function prodlist_auto_switch(name, interval) {
    var scroll = prodlist_is_switchable[name]
    if (scroll) {
        prodlist_switching[name] = true;
        var max = scroll.getSize();
        var index = scroll.getIndex();
        if (max > 1) {
            index += prodlist_switching_direction[name];
            if (index < 0 || index >= max) {
                prodlist_switching_direction[name] = 0 - prodlist_switching_direction[name];
                index += 2 * prodlist_switching_direction[name];
            }
        }
        scroll.seekTo(index);
        window.setTimeout("prodlist_auto_switch('" + name + "'," + interval + ")", interval);
    }
}
function prodlist_init(name, size, speed, interval) {
    $(document).ready(
            function() {
                api = $("div.prodlist_scroll_" + name).scrollable(
                        {
                            api : true,
                            keyboard : false,
                            loop : true,
                            size : size,
                            speed : speed,
                            nextPage : ".prodlist_next",
                            prevPage : ".prodlist_prev",
                            onBeforeSeek : function(event, index) {
                                if (prodlist_is_switchable[name] && !prodlist_switching[name]) {
                                    prodlist_is_switchable[name] = null;
                                }
                                return ($(".hover:visible", this.getRoot()).size() == 0);
                            },
                            onSeek : function(event, index) {
                                prodlist_switching[name] = false;
                            }
                        });
                if (interval) {
                    prodlist_is_switchable[name] = api;
                    prodlist_switching[name] = 0;
                    prodlist_switching_direction[name] = 1;
                    window.setTimeout("prodlist_auto_switch('" + name + "'," + interval + ")", interval);
                } else {
                    prodlist_is_switchable[name] = null;
                }
            });
}

