var scroller = {
    height : 150,
    width : 300,
    scrollerDiv : 'keyFeaturesScroller',
    rows : '',
    position : 0,
    speed: 2, //higher number is slower
    pause: 2,
    next : function() {
        new Effect.Move(this.scrollerDiv+"ItemContainer", {
            x: -parseInt(this.width),
            y: 0,
            mode: 'relative',
            duration: this.speed,
            afterFinish: function() {
                scroller.position = scroller.position + 1;
                if(scroller.position > scroller.rows) {
                    scroller.position = 1;
                }

                scroller.nextItem = $("scrollerItem_"+scroller.position).innerHTML;
                $("scrollerItem_"+scroller.position).remove();

                $(scroller.scrollerDiv+"ItemContainer").insert('<div id="scrollerItem_'+scroller.position+'" class="scrollerItem" style="height:'+scroller.height+'px;width:'+scroller.width+'px">'+scroller.nextItem+"</div>");

                $(scroller.scrollerDiv+"ItemContainer").setStyle({
                    left:"0px"
                })

                setTimeout("scroller.next();",scroller.pause*1000);
                
            }
        });
    }
}


function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }

    return vars;
}

document.observe( "dom:loaded", function() {
    if($(scroller.scrollerDiv)) {
        var get = getUrlVars();
        new Ajax.Request('../site_includes/xhr_scroller.php', {
            method:     'POST',
            parameters: 'scrollerDiv='+scroller.scrollerDiv+'&height='+scroller.height+'&width='+scroller.width+'&products_id='+get['products_id'],
            onSuccess: function(t) {
                var info = t.responseText.evalJSON();
                $(scroller.scrollerDiv).update(info.output);
                /*$(scroller.scrollerDiv).addClassName("scrollerBody");*/
                $(scroller.scrollerDiv).setStyle({
                    'width':scroller.width+'px',
                    'height':scroller.height+'px'
                    });
                
                scroller.rows = info.rows;
                
                setTimeout("scroller.next();",scroller.pause*1000);

            }
        });

        
    }
    
});