$.fn.mostrarCartel = function (obj){

	padre = this
	tiempo = setInterval(mostrarTanda,10000,false);

	this.append("<a class='banLastSlide' href='#' ></a>");
	
	this.children(".banLastSlide").click(function(){

		mostrarTanda($(padre).find(".banBotonerita a:last").attr("value"))
		return false;
	})

	function mostrarTanda(nTanda){
	
		nTandaActual = parseInt(	$(padre).find(".banBotonerita .select").attr("value")	);

		if(!nTanda){ // si no hay tanda, es por inicio el intervalo
		
			if(isNaN(nTandaActual)){
			
				nTanda = 0;
			} else {
			
				nTanda = nTandaActual + 1
			}

		} else {
		
			if(nTanda == nTandaActual){
			
				return false;
			}
			
		}

		clearInterval(tiempo)

		if (nTanda > $(padre).find(".banBotonerita a:last").attr("value")){
			
			return false;
		}
		

		// me fijo si existe otro titulo
		if($(padre).children(".banTitulo").html()){
		
			$(padre).children(".banTitulo").animate({"left":605, "opacity":0},500,function(){
			
				$(this).remove();
			})
		}
		
		// creo los elementos
		$(padre).append("<h1 class='banTitulo' id='banTitu" + nTanda + "'>" + $(padre).find("#cartel"+ nTanda +" h1").html() + "</h1")
		$("#banTitu" + nTanda).css("width",$(padre).outerWidth())
		
		// aparece Titulo con fade:
		$("#banTitu" + nTanda).css("opacity",0)
//		$("#banTitu" + nTanda).fadeIn(500);
		
		// aprece titulo con desplazamiento
		$("#banTitu" + nTanda).css("left",$("#banTitu" + nTanda).outerWidth()*-1)
		$("#banTitu" + nTanda).animate({"left":50, "opacity": 1},700)
		
		
		$(padre).children(".banPastilla").each(function(){
		
			
			$(this).animate({"left":$(this).outerWidth() * -1},500,function(){
			
				$(this).remove();
			})
		})
		
		$(padre).find("#cartel"+ nTanda +" div").each(function(contador){

			caja = $(this).clone().appendTo($(padre)).attr("id","banCaja"+contador)
			$(caja).addClass("banPastilla")

			leftOrg = $(caja).css("left")

			$(caja).css({
				left: $(padre).outerWidth()
			})
			
			// aparece caja
			$(caja).animate({"":0},200 + (50 * contador),function(){
			
				$(this).animate({"left":leftOrg},500)
			})
		})
		
		
		$(padre).find(".banBotonerita a").removeClass("select");
		
		//activo el boton
		$(padre).find(".banBotonerita #banA" + nTanda).addClass("select")
		
		tiempo = setInterval(mostrarTanda,10000,false);

	} // END mostrarTanda()


	this.addClass("banContenedor");
	this.append("<div class='banBotonerita'></div>")

	this.children("div[class!=banBotonerita]").each(function(contador){
		
		$(this).attr("id","cartel" + contador)
		$(this).css("display","none")
	
		$(this).parent().children(".banBotonerita").append("<a id='banA" + contador + "' href='#'></a>")
		
		btn = $(this).parent().children(".banBotonerita").children("#banA" + contador)
		
		$(btn).attr("value",contador);
		
		$(btn).click(function(){
			mostrarTanda($(this).attr("value"))
			return false;
		})
	})
	mostrarTanda(0)
}
