﻿window.addEvent('domready', function() { ProductList.setup(); });

var ProductList = {
    Current: 0,
    setup: function() {
        var p = ProductList.prod = $$('#productlistinner .scrollproduct');
        $('productlistinner').setStyle('width', (240 * p.length) + 'px');

        ProductList.SetText();
        $$('#prevscreen,#largeprevscreen').addEvent('click', function(y) { ProductList.Move(y, -1); });
        $$('#nextscreen,#largenextscreen').addEvent('click', function(y) { ProductList.Move(y, 1); });
    },
    Move: function(y, direction) {
        y.stop();
        ProductList.Current += direction;

        if (ProductList.Current < 0)
            ProductList.Current = 0;

        if (ProductList.Current > Math.floor(ProductList.prod.length / 4))
            ProductList.Current = Math.floor(ProductList.prod.length / 4);

        var firstPage = ProductList.Current * 4;

        var left = -ProductList.prod[firstPage].getPosition('productlistinner').x;

        $('productlistinner').tween('left', left + 'px');
        ProductList.SetText();
    },
    SetText: function() {
        var total = ProductList.prod.length;
        var start = (ProductList.Current * 4) + 1;
        var end = start + 3;
        if (end > total)
            end = total;

    }
}
