var url_fotos = new Array();
var fotos_album = new Array();
var twitter_mensaje = new Array();
var twitter_fecha = new Array();
var total_pag = 0;
var pag = 0;
var flag = 1;
var bucle = 0;
var copies = {
				unete_nombre: 'Debes escribir tu nombre',
				unete_mail: 'Debes escribir tu mail',
				unete_telefono: 'Debes Escribir solamente numeros en el telefeno ',
				unete_hv: 'El documento debe ser en pdf',
				unete_tipo: 'Debes seleccionar un tipo de convocatoria',
				contacto_nombre: 'Debes escribir tu nombre',
				contacto_apellidos: 'Debes escribir tus apellidos',
				contacto_pais: 'Debes seleccionar un pais',
				contacto_cargo: 'Debes escribir tu cargo',
				contacto_correo: 'Debes escribir un correo electronico valido',
				contacto_sector: 'Debes escribir el sector al que perteneces',
				contacto_comentarios: 'Debes escribirnos los comentarios',
				subscripcion_mail:'Debes escribir un correo electronico valido'
				};

function setStyles(cantidad){
	for (var i=1;i<=cantidad;i++){
		
		var id_servicio = $('id_serv'+i).value;
		$('event_serv_'+i).addEvents({
			'mouseenter':overServicio.bindWithEvent($('event_serv_'+i),i),
			'mouseleave':outServicio.bindWithEvent($('event_serv_'+i),i),
			'click': clickServicio.bindWithEvent($('event_serv_'+i),i)
		});
		$('over_servicio_'+i).setStyle('opacity',0);
	}
}		
	
	
	
function overServicio(e, id){
	var over = $('over_servicio_'+id);
	
	var morph = over.get('morph', {link: 'cancel', duration: 500, transition: Fx.Transitions.Sine.easeIn});
	
	morph.start({'opacity': [over.getStyle('opacity'), 1]});
}
function outServicio(e, id){
	var over = $('over_servicio_'+id);
	var morph = over.get('morph', {link: 'cancel', duration: 500, transition: Fx.Transitions.Sine.easeIn});
	morph.start({'opacity': [over.getStyle('opacity'), 0]});
}

function clickServicio(obj,id){
	var obj= $('event_serv_'+id);
	window.location.href="?opcion=portafolio&filtro="+id;	
}


		
		
function mostrarAlerta(msj)
{
	var Contenido = "<div id='msj_alerta'>"+msj+"</div>";

	var detalle_combo = new light_box({lightBoxOpacity:0.7, tema:'alerta' });
	detalle_combo.abrirLightBox(Contenido);
}


var tweet_actual;
var demora_twiit = 7000;
function twitt(){
	tweet_actual = 0;
	setInterval("msjTwitter()", demora_twiit);
}
function msjTwitter(){
	
	if((tweet_actual +1) < twitter_mensaje.length)
		tweet_actual++;
	else
		tweet_actual = 0;
	var efecto_twitt = new Fx.Morph('content_twit', {duration: 1000, transition: Fx.Transitions.Sine.easeOut});
	efecto_twitt.start({'opacity': [1, 0]}).chain (function (){
			$('content_twit').innerHTML	= "";
			$('content_twit').innerHTML	= "<blockquote>&#8220;"+twitter_mensaje[tweet_actual]+"&#8221;</blockquote><p>"+twitter_fecha[tweet_actual]+"</p>" ;
			efecto_twitt.start({'opacity': [0, 1]});
		});
}


function cambioBlog(id)
{
	var efecto_blog = new Fx.Morph('blog', {duration: 800, transition: Fx.Transitions.Sine.easeOut});
	var efecto_noticias = new Fx.Morph('noticias', {duration: 800, transition: Fx.Transitions.Sine.easeOut});
 
	if (id ==2 && flag != id){
		flag = id;
		$('blg').setStyle('color','#C4232B');
		$('noti').setStyle('color','#515151');
		
		efecto_noticias.start({
			// 'left': [0, 220],
			'opacity': [1, 0]  
		}).chain (function (){efecto_blog.start({
			// 'left': [220, 0],
			'opacity': [0, 1]  
		});})
	}else if (id ==1 && flag != id){
		flag = id;
		$('blg').setStyle('color','#515151');
		$('noti').setStyle('color','#C4232B');
		
		efecto_blog.start({
			// 'left': [0, 220],
			'opacity': [1, 0]  
		}).chain (function (){efecto_noticias.start({
			// 'left': [220, 0],
			'opacity': [0, 1]  
		});})
	}
}

function selectCustom()
{
	
$$('.comboBoo').each(function(el){
		new comboBoo(el);
	});
}


function Abrir_ventana (pagina,nombre) {
var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, width=570, height=516";
window.open(pagina,nombre,opciones);
}

function mostrarTitulo(id){
	var morph = $('title_proyect'+id).get('morph', {link: 'cancel', duration: 400});
	morph.start({'top': [$('title_proyect'+id).getStyle('top'), 0],'opacity':[$('title_proyect'+id).getStyle('opacity'), 0.7]});
	
	// var myFx = new Fx.Tween($('title_proyect'+id), { transition:
	// Fx.Transitions.Quad.easeOut});
	// myFx.start('top', '-63px', '0px');
	// $('title_proyect'+id).fade(0.7);
}

function ocultarTitulo(id){
	
	var morph = $('title_proyect'+id).get('morph', {link: 'cancel', duration: 400});
	morph.start({'top': [$('title_proyect'+id).getStyle('top'), -63],'opacity':[$('title_proyect'+id).getStyle('opacity'), 0]});
	/*
	 * myFx = new Fx.Tween($('title_proyect'+id), {duration:'short'});
	 * myFx.start('top', '0px', '-63px'); $('title_proyect'+id).fade("out");
	 */
}
function setStyle(id){
	$('title_proyect'+id).setStyle('top', '0');
}

function cambiarImagen(accion,alt)
{
	var ocultar = new Fx.Tween('atras', {property: 'opacity',duration:800});
	var ocultarNext = new Fx.Tween('adelante', {property: 'opacity',duration:800});
	var cargador = new Fx.Tween('cargando', {property: 'opacity',duration:200});
	
	if (accion=="mas")
		pag = pag+1;
	else if (accion=="menos")
		pag = pag-1;
	
	if (pag ==0 && accion!="")
		ocultar.start(1,0);
	else if (pag ==1 && accion=="mas")
		ocultar.start(0,1);	
	else if (pag == fotos_album.length-1)
		ocultarNext.start(1,0);
	else if (pag == (fotos_album.length - 2) && accion=="menos")
		ocultarNext.start(0,1);		
			
	var src = fotos_album[pag];
	var myFx = new Fx.Tween('img_cambia', {property: 'opacity',duration:1000});
	
	myFx.start(1,0).chain(function(){
								   cargador.start(0,1).chain(function(){
												   $('img_cambia').getFirst().dispose();															  										   	  	   var imagen = new Element('img', {'src':src,
										   'alt':alt,
										   'class': 'img_prof',
										   'events': {
											'click': clickFotoProyect
										 	}});
										   $('img_cambia').adopt(imagen);
										   imagenCargada();
											});
								   });	
}

function clickFotoProyect(){
	ligth_photos = new photo_light_box({lightBoxOpacity:0.8, tema:'fotos'});
	ligth_photos.openListPhotos(url_fotos, pag,1,1);
}

function imagenCargada (){
	var myFx = new Fx.Tween('img_cambia', {property: 'opacity',duration:1500});
	var cargador = new Fx.Tween('cargando', {property: 'opacity',duration:1200});
	cargador.start(1,0).chain(function(){myFx.start(0,1)});
}
function validarHoja(){
	var Regcorreo = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;
	var texto = /(^\S([\D]+)$)/;
	var numeros = /^([0-9]{3,20})+/;
	var Regcontrasegna = /^[aA-zZ0-9_-]{6,18}$/	
	
	var nombre = $('nombre').value;
	var mail = $('mail').value;
	var telefono = $('telefono').value;
	var tipo_conv = $('tipo_conv').value;
	var input_hv = $('input_hv').value;
	var area = $('area').value;
	
	
	if (!(nombre.match(texto))){
		mostrarAlerta(copies.unete_nombre);
		$('nombre').focus();
		return;
	}else if (!(mail.match(Regcorreo))){
		mostrarAlerta(copies.unete_mail);
		$('mail').focus();
		return;
	}else if (!(telefono.match(numeros))){
		mostrarAlerta(copies.unete_telefono);
		$('telefono').focus();
		return;
	}else if (tipo_conv ==0){
		mostrarAlerta(copies.unete_tipo);
		$('tipo_conv').focus();
		return;
	}else if (!/(\.pdf)$/i.test(input_hv)){
		mostrarAlerta(copies.unete_hv);
		$('input_hv').focus
		return;
	}else if (!(area.match(texto))){
		mostrarAlerta(copies.unete_area);
		$('url').focus();
		return;
	}else{
		$('unete').submit();
	}
} 

function stylesHome(cantidad){
	
	for (var i=1;i<=cantidad;i++){
		$('cont_foto'+i).setStyle('opacity',0);
		$('cont_foto'+i).setStyle('visibility','visible');
		// $('cont_foto'+i).setStyle('opacity',0);
		// var heightText = $('text_home'+i).getStyle('height').toInt();
		// var heightFoto = $('over_foto'+i).getStyle('height').toInt();
		
		/*
		 * if (heightText < heightFoto){
		 * //$('text_home'+i).setStyle('height',(heightFoto-70)); }
		 */
					
		var id_servicio = $('id_proyect'+i).value;
		
		$('cont_foto'+i).addEvents({
			'mouseenter':overProyectoHome.bindWithEvent($('cont_foto'+i),i),
			'mouseleave':outProyectoHome.bindWithEvent($('cont_foto'+i),i),
			'click': clickProyectoHome.bindWithEvent($('id_proyect'+i),id_servicio)
		});
	}
}

function overProyectoHome(obj,id){
	// $('cont_foto'+id).setStyle('visibility','visible');
	var over = $('cont_foto'+id);
	var morph = over.get('morph', {link: 'cancel', duration: 500, transition: Fx.Transitions.Sine.easeIn,onComplete:function(){over.setStyle('visibility','visible');}});
	morph.start({'opacity': [over.getStyle('opacity'), 0.5]});
}
function outProyectoHome(obj,id){
	var over = $('cont_foto'+id);
	var morph = over.get('morph', {link: 'cancel', duration: 500, transition: Fx.Transitions.Sine.easeIn,onComplete:function(){over.setStyle('visibility','visible');}});
	morph.start({'opacity': [over.getStyle('opacity'), 0]});
	
}

function clickProyectoHome(obj,id){
	var obj= $('id_proyect'+id);
	window.location.href="?opcion=portafolio&a=verProyecto&id="+id;	
}

function validarContacto(){
	var exp_correo = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;
	var texto = /(^\S)/;
	var nombre = $('nombre').value;
	var apellidos = $('apellidos').value;
	var correo = $('correo').value;
	var pais = $('pais').value;
	var sector = $('sector').value;
	var cargo = $('cargo').value;
	var comentarios = $('comentarios').value;
	
	
	if (!nombre.match(texto)){
		mostrarAlerta (copies.contacto_nombre);
		$('nombre').focus();
		return;
	}else if (!apellidos.match(texto)){
		mostrarAlerta (copies.contacto_apellidos);
		$('apellidos').focus();
		return;
	}else if (!correo.match(exp_correo)){
		mostrarAlerta (copies.contacto_correo);
		$('correo').focus();
		return;
	}else if (pais == 0){
		mostrarAlerta (copies.contacto_pais);
		$('pais').focus();
		return;
	}else if (sector == 0){
		mostrarAlerta (copies.contacto_sector);
		$('sector').focus();
		return;
	}else if (!cargo.match(texto)){
		mostrarAlerta (copies.contacto_cargo);
		$('cargo').focus();
		return;
	}else if (!comentarios.match(texto)){
		mostrarAlerta (copies.contacto_comentarios);
		$('comentarios').focus();
		return;
	}else{
		$('form_contacto').set('send', { method: 'post',evalScripts:true, onComplete: respuestaContacto});
		$('form_contacto').send();
	}
}

function respuestaContacto(){
	$('form_contacto').reset();
	//mostrarAlertaTest();
	$('googleadwords').src="http://www.googleadservices.com/pagead/conversion/995142901/?label=4xNoCPumpQIQ9dnC2gM&amp;guid=ON&amp;script=0";
}
var flag_video = 0;
function verVideo(){
	
	var morph_video = $('video_portafolio').get('morph', {link: 'cancel', duration: 500, transition: Fx.Transitions.Sine.easeIn});
	var morph = $('img_cambia').get('morph', {link: 'cancel', duration: 500, transition: Fx.Transitions.Sine.easeIn});
	
	if (flag_video == 0){
		flag_video = 1;
		morph.start({'opacity': [1, 0]}).chain (function (){
			$('link_texto').innerHTML = "Ver Imagenes";
			$('img_cambia').setStyle('display','none');
			$('paginacion').setStyle('display', 'none');											  
			$('video_portafolio').setStyle('display','block');											  
			morph_video.start({'opacity': [0, 1]});
		});
	}else if (flag_video == 1){
		flag_video = 0;
		morph_video.start({'opacity': [1, 0]}).chain (function (){
			$('link_texto').innerHTML = "Ver Video";
			$('img_cambia').setStyle('display','block');
			$('paginacion').setStyle('display', 'block');											  
			$('video_portafolio').setStyle('display','none');											  
			morph.start({'opacity': [0, 1]});
		});
		
	}
	
}

function validarSubscripcion(){
	var mail = $('mail').value;
	var exp_correo = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;
	if (!mail.match(exp_correo)){
		mostrarAlerta (copies.subscripcion_mail);
		$('mail').focus();
		return false;
	}else {
		$('form_news').set('send', { method: 'post',evalScripts:true, onComplete: respuestaSubcripcion});
		$('form_news').send();
		return false;
	}		
}

function respuestaSubcripcion(){
	$('form_news').reset();
}
