/**
 * Image rotation
 *
 * @requires prototype
 * @requires scriptaculous
 * @author Jost Neumann <neumann@die-ordnung.de>
 */
Event.observe(window, 'load', function(e){
    var imageObjs = $$('.teasers img.teaser');
    // there hvae to be exactly 4 images
    if( imageObjs.length != 4 ){
        return;
    }
	
	// clone positions of first two images
    Position.clone(imageObjs[0], imageObjs[2]);
    Position.clone(imageObjs[1], imageObjs[3]);

    imageObjs = imageObjs.slice(2);
    imageObjs.each( function(img){
        img.hide();
        img.style.visibility = 'visible';
        //var time = 5 + ( Math.round( Math.random()*5*10 ) / 10 );
        var time = 8;
        new PeriodicalExecuter( function(pe){
        	var options = {
				'fps' : 30,
				'duration' : 2,
				'transition' : Effect.Transitions.linear
			};
            if( !Element.visible(img) ){
                new Effect.Appear(img, options);
            } else {
                new Effect.Fade(img, options);
            }
        }, time);
    });
    
});
