var BannerIndex = {};

BannerIndex.SlideEffect = function() {
  this.objects = $('.banner');
  this.puzzle = $('.images_over > img');
  this.visible = 1;
  this.stepsCount = 	5;
  this.actualStep = 1;

	this.animatePiezas(this.objects);

}

BannerIndex.SlideEffect.prototype = {


    getNextStep: function(ajax_url){
        this.actualStep = this.actualStep + 1;
        var self = this;

        $.ajax({
           type: "POST",
           url: ajax_url,
           data: "step=" + this.actualStep,
            success: function(step){
                $('#bannerComponent').append(step);

                if(self.actualStep == self.stepsCount){
                    self.animatePuzzle();
                } else {
                    self.getNextStep(ajax_url);
                }
            }
        });
    },

    animatePuzzle: function(){
        var self = this;
        self.puzzle = $('.images_over > img');
        $('#bannerComponent').fadeTransition({
						transitionTime: 500,
						pauseTime: 8000,
            afterShow: function(nextElement){
							self.animatePiezas(nextElement);
            }

        });
    },
		animatePiezas: function(element){
			puzzle = $(element).children("div.puzle").children("div.images_over").children("img");
      //$('.images_over').fadeTransition({pauseTime: 1000, transitionTime: 500, delayStart: 1000});
      var timer = 1500;
			var isfirst = true;
      puzzle.each(function(index){
	        var puz = $(this);
					puz.hide();
          timer = timer + 100;
					if(isfirst == true){
						var texts = $(element).children("div.text_banner").children('.banner_funcionalidades');
						texts.hide();
						setTimeout(function() { texts.fadeIn(500)},timer)
					}
					isfirst = false;
          setTimeout(function() {puz.fadeIn(50);} , timer);
      });
		}
}

