/********************
flashHome
*********************
FUNCION GENÉRICA PARA FLASH DE LA HOME
Funcionamiento en tpl:
definir bloque contenedor de las imágenes.
Definir bloque para la imagen.
Definir bloque para el texto.
Quedándo con la estrucutra:

  	<div class="container">
		<div id="imgFlash_1"> 
			<div id="textFlash_1" class="flying-text">
			</div>
		</div>
		<div id="imgFlash_2"> 
			<div id="textFlash_2" class="flying-text">
			</div>
		</div>
		<div id="imgFlash_N"> 
			<div id="textFlash_N" class="flying-text">
			</div>
		</div>
		...
		...
		...				
	</div>
Para el diseño ver archivo se puede usar el genérico ./css/flashHome.css. Utilizar sobretodo para la animación del texto

PARÁMETROS:
i 			--> 	[INT]  contador de la imagen en bucle
count		--> 	[INT]  contador de la imagen total
total		--> 	[INT]  numero de imágenes
max 		--> 	[INT]  numero de veces que se repite hasta que se detenga el flash
imgBlock 	--> 	[STR]  etiqueta del bloque de imagane
textBlock	-->		[STR]  etiqueta del bloque de texto
show_text   -->		[BOOL] Si la animación mostrará texto o no
wait		-->		[INT]  Tiempo de espera entre imágenes
speedFade	-->		[INT]  Velocidad del FadeIn
speedText	-->		[INT]  Velocidad de animación del texto (EN DESARROLLO|ANIMACION NO MUY "ELEGANTE")
_idControl  --> 	[BOOL] Si se activa para el bucle de animación
PARA INICIALIZARLO:

$(document).ready(function(){
	flashHome('1','0','4','2','imgFlash','textFlash',false,10000,3000,2000,_idControl);
});

*/
var timer_1;
var timer_2;
function flashHome(i,count,total,max,imgBlock,textBlock,show_text,wait,speedFade,speedText,_idControl){
	var control=document.getElementById(_idControl).value;
	var j;
	var imgOut;	
	var k;
	if(speedFade == 0){
		speedFade=2000;
	}
	if(speedText == 0){
		speedText=speedFade-1;
	}	
	imgOut=parseInt(wait)+parseInt(speedFade)+1;
	if (speedText >= speedFade){
		speedText = speedFade -1;
	}
	if(i==parseInt(total)-1){
		j=0;
		count=parseInt(count)+1;
	}else{
		j=parseInt(i)+1;	
	}	
	k=parseInt(i)-1;
	if(k < 0){
		k=parseInt(total)-1;
	}
	if(control!='1'){
		clearTimeout(timer_1);
		clearTimeout(timer_2);		
		$('#'+imgBlock+'_'+k).css('z-index',10);
		return false;
	}	
	document.getElementById('f_right').setAttribute("onclick", "ShowImgFlash('"+j+"','"+total+"','"+imgBlock+"');return false;");
	document.getElementById('f_left').setAttribute("onclick", "ShowImgFlash('"+k+"','"+total+"','"+imgBlock+"');return false;");	
	if(i==0){
		$('#'+imgBlock+'_'+(parseInt(total)-1)).css('z-index',1);	
		$('#'+imgBlock+'_'+i).css('z-index',2);			
	}else{
		$('#'+imgBlock+'_'+(parseInt(i)-1)).css('z-index',1);			
		$('#'+imgBlock+'_'+i).css('z-index',2);			
	}
	if(parseInt(count)<parseInt(max)){
	    
		//alert('ROUND: '+i+' .COUNT: '+count +' .TOTAL: '+total +' .MAX: '+max+' .IMG_BLOCK: '+imgBlock +' .TEXT_BLOCK: '+textBlock +' .SPEED FADE: '+speedFade +' .SPEED TEXT: '+speedText +' .VARIABLE TOTAL: '+textBlock+'_'+i+' .WAIT: '+wait+' .IMG OUT: '+imgOut);	
		if(show_text=='true'){
			$('#'+textBlock+'_'+k).css({opacity:0});
			$('#'+textBlock+'_'+i).css({opacity:0});//set all text opacity to 0		
			$('#'+textBlock+'_'+i).animate({opacity:1}, speedText); //animate first text		
		
		}else{
			document.getElementById(textBlock+'_'+k).style.display='none';	
			document.getElementById(textBlock+'_'+i).style.display='block';	
		}		
		// Animation complete.
    	$('#'+imgBlock+'_'+i).fadeIn(speedFade, function(){ 
		    	timer_1=setTimeout("ShowImgFlash('"+j+"','"+total+"','"+imgBlock+"','"+textBlock+"','0')",imgOut);    		    	
		    	timer_2=setTimeout("flashHome('"+j+"','"+count+"','"+total+"','"+max+"','"+imgBlock+"','"+textBlock+"','"+show_text+"','"+wait+"','"+speedFade+"','"+speedText+"','"+_idControl+"')",wait);  		
		});   	
	}else{
		document.getElementById(imgBlock+"_"+i).style.display='block';
		document.getElementById(textBlock+'_'+i).style.display='block';			
	}
	return false;	
}
/*******************
ShowImgFlash
********************
SE PUEDEN AÑADIR BOTÓN/ENLACE PARA ADELANTAR DE UNA IMAGEN A OTRA
Botón para pasar de una capa a otra del carrusel:

<a onclick=\"ShowImgFlash(img_show,total,imgBlock);return false;\" href='#'><img class='' src='' title=''></a>
*/
function ShowImgFlash(img_show,total,imgBlock,textBlock,is_click){
	if(is_click=='1'){
		clearTimeout(timer_1);
		clearTimeout(timer_2);		
	}
	var j;
	var imgOut;	
	var k;	
	for (var i=0; i < total; i++){
	   if (i == img_show){
	      	document.getElementById(imgBlock+"_"+i).style.display='block';
	      	document.getElementById(textBlock+'_'+i).style.display='block';	
	      	$('#'+textBlock+'_'+i).animate({opacity:1}, '10'); //animate first text	
	   }
	   else{
	      	document.getElementById(imgBlock+"_"+i).style.display='none';	 
	      	document.getElementById(textBlock+'_'+i).style.display='none';	
	   }
	}
	if(img_show==parseInt(total)-1){
		j=0;
	}else{
		j=parseInt(img_show)+1;	
	}	
	k=parseInt(img_show)-1;
	if(k < 0){
		k=parseInt(total)-1;
	}	
	document.getElementById('f_right').setAttribute("onclick", "ShowImgFlash('"+j+"','"+total+"','"+imgBlock+"','"+textBlock+"','1');return false;");
	document.getElementById('f_left').setAttribute("onclick", "ShowImgFlash('"+k+"','"+total+"','"+imgBlock+"','"+textBlock+"','1');return false;");
	//alert("llega");
}
function controlSilde(_idControl,_action,capaControl){
	//alert("ENTRA"+_idControl+" ACTION: "+_action);
	$('#'+capaControl).css('z-index',0);	
	document.getElementById(capaControl).style.display='none';	
	document.getElementById(_idControl).value=_action;
	//alert("ENTRA"+_idControl+" ACTION: "+_action);	
}



