var _intervalo;
var _contenidoVisibleActual;

function init_panelRotator(){
	_contenidoVisibleActual = 0;
	_intervalo = setInterval("cambiarPanelVisible()", 10000);
	$("#panelRotator div.panelRotatorPG").css({"display":"none"});
	$("#panelRotator div.panelRotatorPG").eq(0).css({"display":"block"});
}

function cambiarPanelVisible(){
	var proximo = (_contenidoVisibleActual + 1) >= $("#panelRotator div.panelRotatorPG").length ? 0 : (_contenidoVisibleActual + 1);
	$("#panelRotator div.panelRotatorPG").eq(_contenidoVisibleActual).animate({"opacity" : 0}, 1000, function(){
			$(this).css({"display":"none"});
		});
	$("#panelRotator div.panelRotatorPG").eq(proximo).css({"display":"block"});
	$("#panelRotator div.panelRotatorPG").eq(proximo).animate({"opacity" : 1}, 1000, function(){
				//$("#panelRotator div.panelRotatorPG").eq(proximo).promoTextPG
			});

//	$("#panelRotator div.panelRotatorPG:eq("+proximo+").promoTextPG").animate({"height" : 72}, 4000);


// error x jtools
//	$("#panelRotator div.panelRotatorPG .promoTextPG").eq(_contenidoVisibleActual).delay(1000).fadeOut(10);
//	$("#panelRotator div.panelRotatorPG .promoTextPG").eq(proximo).delay(1000).slideDown(500).fadeIn(500);
// por error se usa:
$("#panelRotator div.panelRotatorPG .promoTextPG").eq(_contenidoVisibleActual).fadeIn(1000, function(){
		$(this).fadeOut(10);
	});
$("#panelRotator div.panelRotatorPG .promoTextPG").eq(proximo).fadeOut(1000, function(){
		$(this).slideDown(500).fadeIn(500);
	})



	cambiarIconoPagina(proximo);
	
	_contenidoVisibleActual = proximo;
}

function cambiarPanelPagina(pg){
	clearInterval(_intervalo);
	
	var _click_pos_eq = 0;
	$("#panelRotator div.panelRotatorPG").eq(pg).css({"display":"block"});	
	$("#panelRotator div.panelRotatorPG").eq(pg).animate({"opacity" : 1}, 1000);
	$("#panelRotator div.panelRotatorPG").each(function(){
			if(_click_pos_eq != pg && $(this).css("opacity") != 0){
				$(this).animate({"opacity" : 0}, 1000, function(){
						$(this).css({"display":"none"});
					});
			}
			_click_pos_eq++;
		});
	
	cambiarIconoPagina(pg);	
	
	_contenidoVisibleActual = pg;
	_intervalo = setInterval("cambiarPanelVisible()", 4000);
}

function cambiarIconoPagina(pg){
	$("#panelRotatorPag div").removeClass("panelRotatorBulletActive");
	$("#panelRotatorPag div").addClass("panelRotatorBulletNoActive")
	$("#panelRotatorPag div").eq(pg).removeClass("panelRotatorBulletNoActive");
	$("#panelRotatorPag div").eq(pg).addClass("panelRotatorBulletActive");
}



//agregado despues a modificar

$(document).ready(function(){
	/*
			$("#panelRotator").css({"position":"relative"});
			var _click_pos_eq = 0;
			$("#panelRotator div.panelRotatorPG").each(function(){
					$(this).css({"position":"absolute", "opacity":0, "display":"none"});
					$("#panelRotatorPag").append("<div onclick='cambiarPanelPagina(" + _click_pos_eq + ")' class='panelRotatorBullet panelRotatorBulletNoActive'></div>");
					_click_pos_eq++;
				});
			$("#panelRotator div.panelRotatorPG").eq(0).css({"opacity":1, "display":"block"});
			$("#panelRotatorPag .panelRotatorBullet").eq(0).removeClass("panelRotatorBulletNoActive");
			$("#panelRotatorPag .panelRotatorBullet").eq(0).addClass("panelRotatorBulletActive");
			$("#panelRotatorPag").append("<br style='clear:both;' />");
			init_panelRotator();
			
			$(".panelRotatorPG").fadeIn("1000", function(){
//					$("#panelRotator div.panelRotatorPG .promoTextPG").delay(1000).slideDown(500).fadeIn(500);
					$("#panelRotator div.panelRotatorPG .promoTextPG").slideUp(1000, function(){
							$(this).slideDown(500).fadeIn(500);
						});
			});
			*/

			$("#panelRotator").css({"position":"relative"});
			var _click_pos_eq = 0;
			$("#panelRotator div.panelRotatorPG").each(function(){
					$(this).css({"position":"absolute", "opacity":0});
					$("#panelRotatorPag").append("<div onclick='cambiarPanelPagina(" + _click_pos_eq + ")' class='panelRotatorBullet panelRotatorBulletNoActive'></div>");
					_click_pos_eq++;
				});
			$("#panelRotator div.panelRotatorPG").eq(0).css({"opacity":1,"display":"block"});
			$("#panelRotatorPag .panelRotatorBullet").eq(0).removeClass("panelRotatorBulletNoActive");
			$("#panelRotatorPag .panelRotatorBullet").eq(0).addClass("panelRotatorBulletActive");
			$("#panelRotatorPag").append("<br style='clear:both;' />");
			init_panelRotator();			
});// JavaScript Document
