Ext.onReady(function(){
	if(window._media){
		window._media.cycle = function(){
			var frames = Ext.get(this.elm).select('.image', true);
			var curr;
			var next;
			
			frames.each(function(o, e, i){
				if(o.isVisible()){
					curr = i;
					next = ++i;
					
					if(next == frames.getCount()){
						next = 0;
					}
				}
			});

			frames.item(curr).hide({duration: 2, easing: 'easeOut'});
			frames.item(next).show({duration: 2, easing: 'easeIn'});
		}
		
		var c = Ext.get(window._media.elm);
		var w = c.getWidth();
		var h = c.getHeight();
		
		c.setStyle({'background-image': 'none', 'position': 'relative'});
		
		Ext.each(window._media.files, function(f, i){
			var f = c.createChild({cls: 'image'}).setStyle({
				width: w + 'px',
				height: h + 'px',
				position: 'absolute',
				top: '0px',
				left: '0px',
				'background-image': 'url(' + window._media.path + f + ')'
			});
			
			if(i > 0) f.hide();
		});
		
		var task = {
		    run: window._media.cycle,
		    interval: 6000,
		    scope: window._media
		}
		var runner = new Ext.util.TaskRunner();
		runner.start(task);
	}
});