/*
* Mootools simple slider for Webwiz by mage
*/

window.addEvent('load', function(){
// slider container
var sliderContainer = $('news-list_146');

// array in which are the images
var imageList = [];

// which image is currently on the left side of the visible slider
var imageCounter = 0;


$('news-list_146').getChildren('.news-list-item').each(function(el) {
    imageList.push(el);
});

// this is for testing whether the current most left image passed out 
var firstImageMargin = parseInt(imageList[0].getStyle('width'));

// main function
var slideLeft = function() {
    var sliderMarginLeft = parseInt(sliderContainer.getStyle('margin-left'));  

    // let's slide the container
    sliderContainer.set('tween', {
        transition: Fx.Transitions.linear,
        duration: 1000,
    });
    sliderContainer.tween('margin-left', 
         sliderMarginLeft - 20 );  

    // if the image on the left dropper out of visible container, it is added to the end
    if (Math.abs(sliderMarginLeft) > firstImageMargin) {     
        var clone = imageList[imageCounter].clone().inject('news-list_146', 'bottom');
        imageList.push(clone);
        imageCounter++;
        firstImageMargin = firstImageMargin + parseInt(imageList[0].getStyle('width')) - 30;
    }
}

// periodical calling of the function
slideLeft.periodical(1000);

});
