
function Rotador(parTipo) 
{	var p = 0;
	var index =0;				//indice que guarda que banner se esta mostrando
	var tipo=parTipo;
	var numero=0;
	var listaBanner1=new Array();
	var leftBotones=162;

//INICIO: Solo debe modificarse agregando tipos en esta sección de código

	var anchoImagen1=545;
	if (parTipo==1) 
	{
	}

	if (parTipo==2)
	{
	}

	if (parTipo==3)
	{
	}

	if (parTipo==4) 
	{
		AgregarBanner("url(/img/banners/home/rotativo_PromoExpressElectro.jpg)","/scp/per_tar_promoexpress.asp","Promo Express");
		AgregarBanner("url(/img/banners/home/rotativo_buquebus.jpg)","/scp/per_tar_buquebus.asp","Buquebús");
		AgregarBanner("url(/img/banners/home/banner_prestamos_vacaciones.jpg)","/scp/per_pres_personales.asp","Préstamos");
		AgregarBanner("url(/img/banners/home/rotativo_macroverano.jpg)","/scp/macroverano.asp","Macro Verano");
		AgregarBanner("url(/img/banners/home/banner_oleo.jpg)","/scp/per_tar_gastronomia.asp","Gastronomía");
		AgregarBanner("url(/img/banners/home/Banca_movil_home.jpg)","/scp/per_tar_mbm.asp","Macro Banca Móvil");
	} 

//FIN: Solo debe modificarse agregando tipos en esta sección de código


//	if (parTipo==2)
//	{ 
//		leftBotones=164;
//		var ancho=18*numero-2;
//	} 	
		this.banner="";
		for(p=0;p <numero; p++){
			if(p==0){
				this.banner+="<div onclick='frm1.submit();' id='ibanner"+p+"' style='display:block;margin-bottom: -19px; height: 347px; width:"+anchoImagen1+"; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; background-image:"+listaBanner1[p].Imagen+";border:0'></div>";
				}else{
				this.banner+="<div onclick='frm1.submit();' id='ibanner"+p+"' style='display:none;margin-bottom: -19px; height: 347px; width:"+anchoImagen1+"; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; background-image:"+listaBanner1[p].Imagen+";border:0'></div>";
				}			
		}
		
//        this.banner+="<div id='LR'><img id='left' onclick='javascript:rotador.left()'  onmouseover='javascript:swapl()' onmouseout='javascript:swapl()'' value=0 src='/img/buttons/left.gif' />";
//        this.banner+="<img  id='pause' onmouseover='javascript:swappause()' onmouseout='javascript:swappause()'' onclick='javascript:rotador.play() '  value=0 src='/img/buttons/pause.gif' name='pause' style='display: inline;' />" ;
//        this.banner+="<img  id='play' onmouseover='javascript:swapplay()' onmouseout='javascript:swapplay()'' onclick='javascript:rotador.play() ' value=0 src='/img/buttons/play.gif' name='play' style='display: none;'/>";
//        this.banner+="<img  id='right' onmouseover='javascript:swapr()' onmouseout='javascript:swapr()'' onclick='javascript:rotador.right() ' value=0 src='/img/buttons/right.gif'/></img></div>";
//		this.banner+="<div id='loaddiv' style=width:"+(anchoImagen1)+"px;'><img id='load' src='/img/buttons/blue.gif' style=' display: none; clear:both;width: 0%; float: rigth;'></img>";
//		this.banner+="<Form id=frm1 action='" + listaBanner1[0].Url + "' name=frm1'></Form></div>";

        this.banner+="<div align=right id='LR'><img id='left' onclick='javascript:rotador.left()'  onmouseover='javascript:swapl()' onmouseout='javascript:swapl()'' value=0 src='/img/buttons/left.gif' />";
        this.banner+="<img  id='pause' onmouseover='javascript:swappause()' onmouseout='javascript:swappause()'' onclick='javascript:rotador.play() '  value=0 src='/img/buttons/pause.gif' name='pause' style='display: inline;' />" ;
        this.banner+="<img  id='play' onmouseover='javascript:swapplay()' onmouseout='javascript:swapplay()'' onclick='javascript:rotador.play() ' value=0 src='/img/buttons/play.gif' name='play' style='display: none;'/>";
        this.banner+="<img  id='right' onmouseover='javascript:swapr()' onmouseout='javascript:swapr()'' onclick='javascript:rotador.right() ' value=0 src='/img/buttons/right.gif'/></img></div>";
		this.banner+="<div id='loaddiv' style=width:"+(anchoImagen1)+"px;'><img id='load' src='/img/buttons/blue.gif' style=' display: none; clear:both;width: 0%; float: rigth;'></img>";this.banner+="<Form id=frm1 action='" + listaBanner1[0].Url + "' name=frm1'></Form></div>";

        
    makeFlash();                 //Comienza a rotar
	this.TextoBanner=FBanner;
	this.right = right;
	this.left = left;
	this.play = play;
	this.index = index;
	this.numero = numero;
	//this.events= events;
		
	function play(){            //Detiene o comienza la rotacion de banners
	var pause;
	var play;
	pause = document.getElementById("pause");
	play = document.getElementById("play");
	if(pause.style.display== 'inline'){ //SI esta el boton de pause, entonces está rotando.

                stopFlash();                 //para de rotar
                pause.style.display= 'none'; //muestra el boton de play
	        play.style.display= 'inline';

	}else{                             //Si no, no esta rotando
	    //pasar();                      //Paso una vez para que se vea que hizo algo (si no parece que el boton no hace nada)
 	     makeFlash();                  //lo pongo a rotar
         play.style.display= 'none';   //dibujo el boton de pause
	     pause.style.display= 'inline';

	}


	}
	function pasar(){          //SetInterval llama a esta funcion cada X tiempo

	    
		if(rotador.index + 1 > (rotador.numero-1)){
				rotador.index = 0
			}else{
				rotador.index = rotador.index + 1;
			}
		for(l=0;l<numero;l++){	
		foo = document.getElementById('ibanner'+l);
	    foo1 = document.getElementById('frm1');
			if(rotador.index==l){
				foo.style.display='block';
			}else{
				foo.style.display='none';
			}
		foo1.action=listaBanner1[rotador.index].Url;
		}
		return ;
	}

	function right(){        //Pasa al banner de la derecha y pausa el rotador si esta andando
	        var pause;
	        var play;
			p = 0;
			el = document.getElementById('load');
			el.style.width= p+"%";
	        pause = document.getElementById("pause");
	        play = document.getElementById("play");
			id= "ibanner"+rotador.index;
		rotador.index;
		if(rotador.index + 1 > (rotador.numero-1)){
				rotador.index = 0
			}else{
				rotador.index = rotador.index + 1;
			}
		if(flashTimer){
		           pause.style.display= 'none';
		           play.style.display= 'inline';
                           stopFlash();

		}
	        for(l=0;l<numero;l++){	
		foo = document.getElementById('ibanner'+l);
	    foo1 = document.getElementById('frm1');
			if(rotador.index==l){
				foo.style.display='block';
			}else{
				foo.style.display='none';
			}
		foo1.action=listaBanner1[rotador.index].Url;
		}
		return ;
	}
	
	function left(){      //Pasa al banner de la izquierda y pausa el rotador si esta andando
	        var pause;
         	var play;
			p = 0;
			el = document.getElementById('load');
			el.style.width= p+"%";
          	pause = document.getElementById("pause");
           	play = document.getElementById("play");
		if(rotador.index-1 < 0){
				rotador.index = (rotador.numero-1)
			}else{
				rotador.index = rotador.index - 1;
			}
		if(flashTimer){
                           pause.style.display= 'none';
		           play.style.display= 'inline';
                           stopFlash();
		}
		for(l=0;l<numero;l++){	
		foo = document.getElementById('ibanner'+l);
	    foo1 = document.getElementById('frm1');
			if(rotador.index==l){
				foo.style.display='block';
			}else{
				foo.style.display='none';
			}
		foo1.action=listaBanner1[rotador.index].Url;
		}
		return ;
	
	}
	


	function FBanner()
	{
		return this.banner;
	}


	function AgregarBanner(parImagen, parUrl, parDescripcion)
	{
		var banner1;
		banner1=new BannerActivo();
		banner1.Imagen=parImagen;
		banner1.Url=parUrl;
		banner1.Descripcion=parDescripcion;

		listaBanner1[numero]=banner1;
		numero++;
	}
	function BannerActivo()
	{
	}



	function makeFlash()        //Hace lo que banners roten automaticamente
	{
		var tiempo=5000;
//		if (tipo==3)
//			tiempo=3000;
//		if (tipo==2)
//			tiempo=3000;
		flashTimer = setInterval(load, (tiempo/100));
		

	}
	function stopFlash()       // Detiene la rotacion de banners
	{
		clearInterval(flashTimer);
		flashTimer= 0;     //Bandera para saber si esta rotando o no. SI es 0 NO rota.
	}
	function load(){
	var el;	
	el = document.getElementById('load');
	if(el.style.width=="100%"){
			p=0;
			el.style.width = p+"%";
			pasar();
		}else{
		el.style.width = p+"%";
		p = p+1;
		}
	}
	//function events(){
	//el = document.getElementById('left');
	//el.addEventListener('mouseover',swapl)
	//el.addEventListener('mouseout',swapl)
	//el = document.getElementById('right');
	//el.addEventListener('mouseover',swapr)
	//el.addEventListener('mouseout',swapr)
	//el = document.getElementById('pause');
	//el.addEventListener('mouseover',swappause)
	//el.addEventListener('mouseout',swappause)
	//el = document.getElementById('play');
	//el.addEventListener('mouseover',swapplay)
	//el.addEventListener('mouseout',swapplay)
	//}
}

function swapl(){
	id='left';
	el = document.getElementById(id);
	value = el.getAttribute('value');
	if(value==0){
		img = ''+id+'.gif'
		el.setAttribute('src','/img/buttons/'+img);
		el.setAttribute('value',1);
		}else{
		el.setAttribute('src','/img/buttons/'+id+'.gif');
		el.setAttribute('value',0);
		}
	}
	function swapplay(){
	id='play'
	el = document.getElementById(id);
	value = el.getAttribute('value');
	if(value==0){
		img = ''+id+'.gif'
		el.setAttribute('src','/img/buttons/'+img);
		el.setAttribute('value',1);
		}else{
		el.setAttribute('src','/img/buttons/'+id+'.gif');
		el.setAttribute('value',0);
		}
	}
	function swappause(){
	id='pause';
	el = document.getElementById(id);
	value = el.getAttribute('value');
	if(value==0){
		img = ''+id+'.gif'
		el.setAttribute('src','/img/buttons/'+img);
		el.setAttribute('value',1);
		}else{
		el.setAttribute('src','/img/buttons/'+id+'.gif');
		el.setAttribute('value',0);
		}
	}
	function swapr(){
	id='right';
	el = document.getElementById(id);
	value = el.getAttribute('value');
	if(value==0){
		img = ''+id+'.gif'
		el.setAttribute('src','/img/buttons/'+img);
		el.setAttribute('value',1);
		}else{
		el.setAttribute('src','/img/buttons/'+id+'.gif');
		el.setAttribute('value',0);
		}
	}
