var rotationDelay = 7000 /* millisekunteja */
var imagewidth = 900 /* pikkelsej */

function rotateImages() {
    clearTimeout(t);
    
    $('.case').each(function() {
        var ob = $(this);
        var imagescontainer = ob.children('.case-images').children('.images-container');
        var currpos = imagescontainer.position();
        var imagescount = ob.children('.case-images').children('.images-container').children('img').size();
        var direction = ob.attr('title');
            if(currpos.left <= -(imagescount-1)*imagewidth || direction == 'right') { direction = 'right'; var animationz = currpos.left + imagewidth }
            if(currpos.left == 0 || direction == 'left') { direction = 'left' ; var animationz = currpos.left - imagewidth ; }
            ob.attr('title',direction);
        
        imagescontainer.animate({
            left:animationz
        });

    });
    
    t = setTimeout("rotateImages()",rotationDelay);
    
}

$().ready(function() {

    
    $('.case').each(function(){
        var currentCase = $(this) ;
        $(this).attr('title','left') ;
        var imagesdiv = currentCase.children('.case-images');
        var imagecontainer = imagesdiv.children('.images-container');
        var imagescount = imagecontainer.children('img').size() ;
        imagecontainer.css({
           position:"absolute",
           left:0,
           top:0,
           width:imagewidth*imagescount 
        });
    });
  t = setTimeout("rotateImages()",rotationDelay);

});
