// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var album = { 
  startup: function(images_list) { 
    new PeriodicalExecuter(album.cycle, 5); // change image every 5 seconds 
    album.images = images_list;
	album.oImages = new Array();
	album.counter = 0;
  },
  next_image: function() {
  	album.counter++;
  	if( album.counter == album.images.length ) {
		album.counter = 0;
	}
	oImage = new Image;
	if (typeof album.oImages[album.counter] == undefined) {
		oImage.src = album.current_image();
		album.oImages[album.counter] = oImage;
	}
	return album.current_image();
  },
  current_image: function() {
  	return album.images[album.counter];
  },
  current_image_object: function() {
  	return album.oImages[album.counter];
  },
  cycle: function() {	  
  	  album.next_image();

	 if (album.counter % 2) {
	 	new_image = 'bigImagesImg';
		old_image = 'bigImagesImgNew'
	 } else {
	 	old_image = 'bigImagesImg';
		new_image = 'bigImagesImgNew'
	 }
	 $(new_image).src = album.current_image();
	 new Effect.Parallel([
     	new Effect.Fade(old_image, { 
			duration: 3,
			fps: 50,
			sync: true
		}),
        new Effect.Appear(new_image, {
          duration: 2,
          fps: 50,
          sync: true
        })
	 ], { duration: 3}
	);
	
  } 
}

 
	 
 