// JavaScript Document
window.addEvent('resize', function(){
	var scroll = window.getSize();
			Vancho=scroll.x;
			Valto=scroll.y;
			centrarAcceso();
			$('imagen').set('html', '');
			$('cargaImagenFondo').style.top= '-30px';
			$('cargaImagenFondo').style.width= Vancho;
			$('cargaImagenFondo').set('tween', {
				duration: 700,
				transition: Fx.Transitions.Quad.easeOut
			}).tween('height', '0px');
			$('cargaImagen').style.top= '-30px';
			$('cargaImagen').style.width= Vancho;
			$('cargaImagen').style.height= '0px';

});
window.addEvent('domready', function(){
	var scroll = window.getSize();
			Vancho=scroll.x;
			Valto=scroll.y;
			$('trabajos').style.height= Valto+300+'px';
			$('fContacta').style.top= Valto+50+'px';
			$('pieFondo').fade(0.85);
			$('fondoForm').fade(0.6);
			$('cargaImagenFondo').fade(0.9);
			$('cargaImagenFondo').style.top= '-30px';
			$('cargaImagenFondo').style.width= Vancho;
			$('cargaImagenFondo').style.height= '0px';
			$('cargaImagen').style.top= '-30px';
			$('cargaImagen').style.width= Vancho;
			$('cargaImagen').style.heigsht= '0px';
			centrarAcceso();
			controlMenu();
			envCorreo();
});
function envCorreo(){
	var boton=$('envCorreo')
	boton.addEvents({
		'click': function(){
			var nombre=$('nombre').value
			var empresa=$('empresa').value
			var mail=$('mail').value
			var mensaje=$('textarea').value
			var formularioCorreo=$('formulario')
			var formularioCarga=$('formularioCarga')
			var destino='envio.asp?n='+nombre+'&e='+empresa+'&m='+mail+'&msj='+mensaje
			formularioCarga.fade(0.5);
			boton.disabled="true";
			boton.value="Enviando mensaje...";
			formularioCorreo.load(destino);
		}
	});
};

function otro(){
			var formularioCorreo=$('formulario')
				$('fContacta').set('tween', {
					duration: 700,
					transition: Fx.Transitions.Quad.easeOut,
					onComplete: function () {
						formularioCorreo.load('otro.asp');
							$('fContacta').set('tween', {
								duration: 700,
								transition: Fx.Transitions.Quad.easeOut,
								onComplete: function () {envCorreo();}
							}).tween('left', '30px');
						}
				}).tween('left', '-500px');
};

function controlMenu(){
	// The same as before: adding events
	$$('#trabajos img').fade(0.4);
	$$('#trabajos img').addEvents({
		'mouseenter': function(){
			// Always sets the duration of the tween to 1000 ms and a bouncing transition
			// And then tweens the height of the element
			this.fade(1);
		},
		'mouseleave': function(){
			// Resets the tween and changes the element back to its original size
			this.fade(0.4);
		}
	});
	$$('#trabajos a').addEvents({
		'click': function(e){
			var Rimagen=this.href;
			e.stop();
			$('cargaImagenFondo').style.top= '0px';
			$('cargaImagenFondo').set('tween', {
				duration: 700,
				transition: Fx.Transitions.Quad.easeOut
			}).tween('height', Valto+'px');
			$('cargaImagen').style.top= '0px';
			$('cargaImagen').set('tween', {
				duration: 700,
				transition: Fx.Transitions.Quad.easeOut,
				onComplete: function () {
						$('imagen').set('html', '<img class="verIMG" src="'+Rimagen+'">');
					}
			}).tween('height', Valto+'px');
		}
	});
	$('imagen').addEvents({
		'click': function (e){
			e.stop();
			$('imagen').set('html', '');
			$('cargaImagenFondo').style.top= '-30px';
			$('cargaImagenFondo').set('tween', {
				duration: 700,
				transition: Fx.Transitions.Quad.easeOut
			}).tween('height', '0px');
			$('cargaImagen').style.top= '-30px';
			$('cargaImagen').style.width= Vancho;
			$('cargaImagen').style.height= '0px';
		}
	});
};

function centrarAcceso(){
	$('recorteFondo').style.width= Vancho+'px';
	$('recorteFondo').style.height= Valto+'px';
	$('trabajos').style.width= Vancho-370+'px';
	//colocamos el pie de pagina
	$('pie').set('tween', {
				 onComplete: function(){
				//modificamos el height de los trabajos
				$('trabajos').set('tween', {
					duration: 1000,
					transition: Fx.Transitions.Quad.easeInOut,
					onComplete: function() {
							// colocamos el formulario de contacto
							$('fContacta').set('tween', {
								duration: 900,
								transition: Fx.Transitions.Quad.easeInOut
							}).tween('top', Valto-330+'px');
						}
				}).tween('height', Valto-130+'px');
					 },
		duration: 500,
		transition: Fx.Transitions.Quad.easeInOut
	}).tween('top', Valto-100+'px');

};
