var cicle = 4000;
function rotateImage(imagens){
	var timer = 0;
	imagens.each(function(image) {
		(function(){
			image.fade('in')
		}).delay(timer);
		
		timer = timer + cicle;
		(function(){
			image.fade('out');
		}).delay(timer);
	});
};

var Contato = new Class({
	initialize:function(form){
		this.form = $(form);
		new Asset.images(['../imagens/input_text_selected.jpg','../imagens/textarea_selected.jpg','../imagens/send_button_over.jpg','../imagens/send_button_press.jpg'], {
			onComplete: function(){
				this.form.getElements('input[type=text]').each(function(el){
					this.bindTextField(el);
				}.bind(this));
				this.form.getElements('textarea').each(function(el){
					this.bindTextarea(el);
				}.bind(this));
				this.form.getElements('input[type=image]').each(function(el){
					this.bindSubmit(el);
				}.bind(this));
			}.bind(this)
		});
	},
	bindTextField:function(el){
		el.addEvents({
			'focus':function(){
				this.getParent().setStyle('background-image','url(../imagens/input_text_selected.jpg)');
			},
			'blur':function(){
				this.getParent().setStyle('background-image','url(../imagens/input_text.jpg)');
			}
		});
	},
	bindTextarea:function(el){
		el.addEvents({
			'focus':function(){
				this.getParent().setStyle('background-image','url(../imagens/textarea_selected.jpg)');
			},
			'blur':function(){
				this.getParent().setStyle('background-image','url(../imagens/textarea.jpg)');
			}
		});
	},
	bindSubmit:function(el){
		el.addEvents({
			'mouseenter':function(){
				this.setProperty('src','../imagens/send_button_over.jpg');
			},
			'mouseleave':function(){
				this.setProperty('src','../imagens/send_button.jpg');
			},
			'mousedown':function(){
				this.setProperty('src','../imagens/send_button_press.jpg');
			}
		});
	}
});
window.addEvent('domready',function(){
	if( $('topo-img') ){
		var loadedImages = []; 
		var path = './imagens/';
		var images = [
			path + 'home_02.jpg',
			path + 'home_03.jpg',
			path + 'home_04.jpg'
		];
		new Asset.images(images, {
			onProgress:function(i){
				loadedImages[i] = this;
			},
			onComplete:function(){
				loadedImages.each(function(image) {
					$('topo-img').adopt(image.setStyle('opacity',0));
				});
				rotateImage( $$('#topo-img img') );
				(function(){rotateImage($$('#topo-img img'));}).periodical( $$('#topo-img img').length * cicle );
			}
		});
	}
	if( $('frm-contato') ){
		new Contato('frm-contato');
	}
});