var SlideShow = function(container,images){
    
    var imgWidth = 129; /* Actual image width=109 + approximate padding(left & right) of 20px */
    var scrollDist = 774; /* On average, we are showing 6 images, so 129 * 6 = 774 */

    var slideFx = container.effect("left", {
        onComplete: function() {
            // Remove scroll arrows if we have reached the edge.
            var pos = container.getStyle("left").toInt();
            
            /*if (-pos + scrollDist < images.length * imgWidth) {
                $("right-arrow").addClass('active');
            } else {
                $("right-arrow").removeClass('active');
            }
            
            if (pos < 0) {
                $("left-arrow").addClass('on-slide');
            } else {
                $("left-arrow").removeClass('on-slide');
            }*/
        }
    });

    function slide(dist) {
        slideFx.start(dist);
    }

    $("right-arrow").addEvent("click", function(el) {
        var pos = container.getStyle("left").toInt();
        if (-pos + scrollDist < images.length * imgWidth) {
            pos -= scrollDist;
        }
        slide(pos);
    });

    $("left-arrow").addEvent("click", function(el) {
        var pos = container.getStyle("left").toInt();
        if (pos < 0) {
            pos += scrollDist;
        }
        slide(pos);
    });
}

window.addEvent("domready", function(){
    // Identify the slides.
    var ss = SlideShow($('slideShowContainer'), $$('#slideShow .newsItem'));
});
// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
Slimbox.scanPage = function() {
    $$($$(document.links).filter(function(el) {
        return el.rel && el.rel.test(/^lightbox/i);
    })).slimbox({/* Put custom options here */}, null, function(el) {
        return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
    });
};
window.addEvent("domready", Slimbox.scanPage);
