$(document).ready(function(){
	$('.content-box').corner();
	make_sliders();
	$('#correo-form').attr('onSubmit','return sendCorreo();');
});


function make_sliders(){
	$('.slide').each(function(){
		$(this).attr('href','#').attr('title','ver miniatura').attr('target','');
		texto = $(this).text();
		new_text = texto.substring(0,texto.indexOf('.'));
		$(this).text(new_text);
		opencloseid = $(this).attr('id')+'-openclose';
		$(this).after('<span id="'+opencloseid+'" class="closed">&nbsp;&nbsp;<span/>');
	});
	$('.slide').click(function(){
		opencloseid = $(this).attr('id')+'-openclose';
		$('#'+opencloseid).toggleClass('opened');
		reference = $(this).attr('id');
		altura = $('#'+reference+'-div').height();
		(altura > 505) ? duracion = 1500 : duracion = 1000;
		$('#'+reference+'-div').slideToggle(duracion);
	});
}

function sendCorreo(){
	text = '';
	var ck_name = /^[a-záéíóúñüèêâçß\s]{3,20}$/i;
	var ck_email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	campos = $('#correo-form :input');
	for(i=0;i<campos.length;i++){
		c = campos[i];
		if(c.value==''){
			text += c.name+' está vacío\n';
		}else if(c.name == 'name'){
			if(!ck_name.test(c.value)){
				text += 'el nombre debe tener entre 3 y 20 caracteres alfabéticos\n';
			}
		}else if(c.name == 'email'){
			if(!ck_email.test(c.value)){
				text += 'el email no es correcto\n';
			}
		}
	}
	if(text != ''){
		alert(text);
		return false;
	}else{
		return true;
	}
}
