
var VELO = {

	inicio : function() {
		VELO.ajustar();
		window.onresize = function (e) {
			VELO.ajustar();
		}
		if($('#capaFlash')){
		/*	if(document.getElementById('enlaceDescarga')){
				VELO.decisionAbrir();
			}*/
			$('#capaFlash a').click(function(){
					VELO.decisionCerrar();
					return false;
		 	 });
		 }	 
		$('#enlaceContacto').click(function(){
				VELO.abrirContacto();
				return false;
		  });
		$('#capaContacto a').click(function(){
				VELO.cerrarContacto();
				return false;
		  });
		if($('#enlaceAviso')){
			$('#enlaceAviso').click(function(){
					VELO.abrirAviso();
					return false;
			  });
		}	  
		if($('#enlaceAviso')){
			$('#capaAviso a').click(function(){
					VELO.cerrarAviso();
					return false;
			  });
		}	  

		if($('#enlaceDescarga')){
			$('#enlaceDescarga').click(function(){
					VELO.abrirDescarga();
					return false;
			  });

			$('#elcierre').click(function(){
					VELO.cerrarDescarga();
					return false;
			  });
		}	  
		if(document.getElementById('btES')){			  
			document.getElementById('btES').onclick = function() {
		  	if((document.getElementById('textoNombre').value == '') || (document.getElementById('textoEmail').value == '') || (document.getElementById('textoComentario').value == '')){
		  		alert('Falta algún campo por rellenar. Todos los campos son obligatorios');
		  		return false;
		  	}else if ((document.getElementById('textoEmail').value.indexOf ('@') == -1)||(document.getElementById('textoEmail').value.indexOf ('.') == -1)) { 
		  		alert('El campo Email no es correcto');
	  			return false;
				}	  	
			}
	  }
	  if(document.getElementById('btEN')){
			document.getElementById('btEN').onclick = function() {
		  	if((document.getElementById('textoNombre').value == '') || (document.getElementById('textoEmail').value == '') || (document.getElementById('textoComentario').value == '')){
		  		alert('Mandatory fields: Name, email adress, Comment');
		  		return false;
		  	}else if ((document.getElementById('textoEmail').value.indexOf ('@') == -1)||(document.getElementById('textoEmail').value.indexOf ('.') == -1)) { 
		  		alert('The email address seems to be incorrect');
	  			return false;
				}	  	
			}
	  }
	},
	decisionAbrir : function() {
		$('#generalCapa').fadeIn('slow');
	  $('#capaFlash').fadeIn('fast');
	  
	},
	decisionCerrar : function() {
    $('#capaFlash').fadeOut('fast');
    $('#generalCapa').fadeOut('slow');
	},
	cerrarContacto : function() {
    $('#capaContacto').fadeOut('fast');
    $('#generalCapa').fadeOut('slow');
	},
	abrirContacto : function() {
	  $('#generalCapa').fadeIn('slow');
	  $('#capaContacto').fadeIn('fast');
	  $('#capaContacto form').submit(function(){
		  // ocultamos boton
		  //$('button[type=submit]', this).attr('disabled','disabled');
		  $('button[type=submit]', this).hide();
		  
		  $.post('php/mail.php', {
			  name: $('#textoNombre').val(),
			  email: $('#textoEmail').val(),
			  content: $('#textoComentario').val()
		  }, function(d){
			  if (d == 'OK') {
				  $('#capaContacto form .messageOK').css('color','blue').show();
			  } else {
				  $('#capaContacto form .messageFail').css('color','red').show();
				  //$('#capaContacto form button[type=submit]').removeAttr('disabled');
				  $('#capaContacto form button[type=submit]').show();
			  }
		  });
		  return false;
	  });
	},
	cerrarAviso : function() {
    $('#capaAviso').fadeOut('fast');
    $('#generalCapa').fadeOut('slow');
	},
	abrirAviso : function() {
	  $('#generalCapa').fadeIn('slow');
	  $('#capaAviso').fadeIn('fast');
	},
	cerrarDescarga : function() {
    $('#capaDescarga').fadeOut('fast');
    $('#generalCapa').fadeOut('slow');
	},
	abrirDescarga : function() {
	  $('#generalCapa').fadeIn('slow');
	  $('#capaDescarga').fadeIn('fast');
	},
	ajustar : function() {
		if (document.getElementById('generalCapa') != null) {
			document.getElementById('generalCapa').style.width = parseInt(document.documentElement.clientWidth) + 'px';
			var escrol = document.documentElement.scrollHeight;
			var client = document.documentElement.clientHeight;
			var finalizar; 
			if(parseInt(escrol)>parseInt(client))
				finalizar = escrol + 80;
			else if(parseInt(escrol)<parseInt(client))
				finalizar = client;
			else	
				finalizar = escrol;
			document.getElementById('generalCapa').style.height = parseInt(finalizar)+ 'px';
			document.getElementById('capaVelo').style.width = parseInt(document.documentElement.clientWidth) + 'px';
			document.getElementById('capaVelo').style.height = parseInt(document.documentElement.clientHeight) + 'px';
			if (navigator.appVersion.indexOf('MSIE 6.0') != -1) {							
				document.getElementById('capaVelo').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + document.getElementById('capaVelo').currentStyle.backgroundImage.split('"')[1] + '", sizingMethod="scale")';
				document.getElementById('capaVelo').style.backgroundImage = 'url("")';
			}
		}
		
	}
}


		
		
		function addLoadEvent(fn) {
    var old = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = fn;
    } else {
        window.onload = function() {
            old();
            fn();
        }
    }
}





addLoadEvent(function() {
	VELO.inicio();
});


window.onResize = function() {
	VELO.ajustar();
}


