window.addEvent('domready', function(){
	initGallery();
	formCheck();
});

var initGallery = function(){
	$$('ul.miniature li img').removeEvents().addEvent('click', function(){
		$$('div.gallery').getElement('img').set('src', this.get('src'));
		$$('div.gallery').getElement('p.caption').set('html', this.get('alt'));
	});
	
	$$('h1.splash a').each(function(el){
		var picture = el.getElements('img');
		var tween = new Array();
		picture.each(function(pic, idx){
			pic.setStyle('z-index', picture.length - idx);
			tween[idx] = new Fx.Tween(pic, {
				onComplete: function(){
					if(idx + 1 >= picture.length){
						picture.setStyle('opacity', 1);
						var delay = function(){
							tween[0].start('opacity', 0);
						}.delay(2000)
					}
					else{
						var delay = function(){
							tween[idx+1].start('opacity', 0);
						}.delay(2000)
					}
				}
			});
		});
		
		var delay = function(){
			tween[0].start('opacity', 0);
		}.delay(2000)
	});
}

var formCheck = function(){
	$$('form.check').each(function(el){
		new Form.Validator(el);
	});
}
