Ext.ns('vlees');
Ext.onReady(function(){
	Ext.get('searchform').select('input[type=submit]').each(function(e){
		var a = e.parent().createChild({tag: 'a', html: e.getValue(), cls: 'submit', href: e.parent('form').getAttribute('action')});
		
		e.remove();
		
		a.on('click', function(e,t){
			e.preventDefault();
			Ext.fly(t).parent('form').dom.submit();
		});
	});
	Ext.get('c_right').select('input[type=submit]').each(function(e){
		var a = e.parent().createChild({tag: 'a', html: e.getValue(), cls: 'submit', href: e.parent('form').getAttribute('action')});
		
		e.remove();
		
		a.on('click', function(e,t){
			e.preventDefault();
			Ext.fly(t).parent('form').dom.submit();
		});
	});
	Ext.select('.print-icoon a').on('click', function(e,t){
		e.preventDefault();
		window.print();
	});
});

Ext.onReady(function(){
	if(window._media){
		window._media.cycle = function(){
			var frames = Ext.get(this.elm).select('div.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(next).fadeIn({duration: 2});
			frames.item(curr).fadeOut({duration: 2});
		}
		
		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 + ')'
			});
			
			f.setVisibilityMode(Ext.Element.DISPLAY);
			
			if(i > 0) f.hide();
		});
		
		var task = {
		    run: window._media.cycle,
		    interval: 5000,
		    scope: window._media
		}
		var runner = new Ext.util.TaskRunner();
		runner.start(task);
	}
	
});