window.addEvent('domready',function() {
    /* settings */
    var showDuration = 5000;
    var containers = $$('.home-body-imagefade');
    var headings = $$('.home-head-imagefade');
    var images = [];
    var currentIndex = [];
    var intervals = [];
    containers.each(function(c, i) {
        images[i] = c.getElements('img');
        currentIndex[i] = 0;
        images[i].each(function(img,ii){ 
            if(ii > 0) {
                img.set('opacity',0);
            }
        });
    });

    /* worker */
    var show = function(i) {
        myIndex = currentIndex[i];
        new Fx.Tween(images[i][myIndex], {
        	property: 'opacity',
        	duration: 'long'
        
		}).start(0);
		(function() {new Fx.Tween(images[i][currentIndex[i] = myIndex < images[i].length - 1 ? myIndex+1 : 0], {
        	duration: 'long',
        	property: 'opacity'
		}).start(1); }).delay(100);
    };
    /* start once the page is finished loading */
    
    headings.each(function(el, i) {
    	(function() {
    		intervals[i] = show.periodical(showDuration, this, i);
		}).delay(i * 1500);
        /*el.addEvents({
            'mouseover': function() {
                intervals[i] = show.periodical(showDuration, this, i);
            },
            'mouseout': function() {
                $clear(intervals[i]);
            }
        });
        images[i].each(function(eli) {
        	eli.addEvents({	'mouseover': function() { intervals[i] = show.periodical(showDuration, this, i); },
        					'mouseout': function() { $clear(intervals[i]); }
			});	
		});	*/
    });
});           
