// JavaScript Document
  //Variables:
  var transition_time_showcase;
  var image_id;
  var animation_duration;
  var imgs_array;
  var stop_timer;
  var imgs_divs_qtd;
  var imgs_qtd;
  var animation_qtd;
  var animation;

  //When loaded main object of the html
  $(document).ready(function(){
      //Variables:
      transition_time_showcase = 7000;
      transition_time_images = 700;
      image_id = 0;
      animation_duration = 700;
      stop_timer = true;
      imgs_divs_qtd = $('div.imgs_showcase').length; //All animated divs
      imgs_qtd = $('div.imgs_showcase img').length; //All images in animated divs
      animation_qtd = imgs_qtd / imgs_divs_qtd;
      animation = 0;

      //Actions:
          //Call the 'implements_images_id'
    	  implements_images_id();
          //Calls function to init
          _init();
  });

  //Functions:
      function implements_images_id() {
		  //Create a news array with images ids
          imgs_array = new Array(1,2,3,4,5,6,7,8);
	  }//End 'implements_images_id' function

      function _init() {
          //Init time to images transitions
          $(document).everyTime( transition_time_showcase , 'home_showcase', function() {
                //To animation
				animation == (animation_qtd-1) ? animation = 0 : animation++;
                //Timer to images animation
                $(document).everyTime( transition_time_images , 'home_showcase_images', function() {
                    //Sort the image
                    image_id = Math.floor(Math.random() * imgs_array.length);
                    //Calls 'change_images' function
                    change_images(imgs_array[image_id]);
                    //Cut the sorted number in array
                    imgs_array.splice(image_id,1);
                    //If finish images animation run condition below
				    if ( imgs_array.length == 0 ) {
                        implements_images_id(); //Implements array to new animation
						stop_timer = true; //To stop timer of the main timer
					    $(document).stopTime('home_showcase_images'); //Stop images timer to animation
					    //Calls the '_init' function
					    _init();
				    }
			  });
          });
      }

      function change_images( id ) {
      //Stop main timer of the showcase
          if ( stop_timer == true ) { $(document).stopTime('home_showcase'); stop_timer = false; };
          //Animate image with opacity
          //When finish animation calls 'animate_complete' function
          $('div.img_' + id ).animate({ opacity:0 }, { duration: animation_duration, complete: function() { animate_complete( id ); }});
	  }//End 'change_images' function

      function animate_complete( id ){
		  //Variables:
		  img_height = $('div.img_'+ id ).height();

          //Back animation
          $('div.img_' + id ).animate({ scrollTop: img_height * animation }, { duration: 30, complete: function() {
              $('div.img_' + id ).animate({ opacity:1 }, { duration: animation_duration });
		  }});
	  }//End 'animate_complete' function

