// JavaScript Document
/* ------------------------------------------------------------------------
	Developped By: Kevin fine  -> LukeTom.com
	
	Rotates through a set of random images
	------------------------------------------------------------------------- */

///******* Image 1 ********///
var previous_image;
var last_image;

function random_image() {
   var $active = $('#slideshow3 DIV.active');
   $(previous_image).addClass('last-active');
   unselectedCells = $("#slideshow3 DIV");
   random_img = Math.floor(Math.random() * unselectedCells.length); // choose a random item
  
  //*****Selects new random image if random is same a previous random image 
  while (random_img==last_image){
         random_img = Math.floor(Math.random() * unselectedCells.length); // choose a random item
   };
   
   last_image=random_img;
   previous_image = unselectedCells[random_img];
   $(previous_image).css({opacity: 0.0})
   .addClass('active')
   .animate({opacity: 1.0}, 1000, function() {
    $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "random_image()", 4000 );
});


///******* Image 2 ********///
var previous_image_2;
var last_image_2;

function random_image2() {
   var $active = $('#slideshow4 DIV.active');
   $(previous_image_2).addClass('last-active');
   unselectedCells = $("#slideshow4 DIV");
   random_img = Math.floor(Math.random() * unselectedCells.length); // choose a random item
  
  //*****Selects new random image if random is same a previous random image 
  while (random_img==last_image_2){
         random_img = Math.floor(Math.random() * unselectedCells.length); // choose a random item
   };
   
   last_image_2=random_img;
   previous_image_2 = unselectedCells[random_img];
   $(previous_image_2).css({opacity: 0.0})
   .addClass('active')
   .animate({opacity: 1.0}, 1000, function() {
    $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "random_image2()", 5000 );
});

///******* Image 2 ********///
var previous_image_3;
var last_image_3;

function random_image3() {
   var $active = $('#slideshow5 DIV.active');
   $(previous_image_3).addClass('last-active');
   unselectedCells = $("#slideshow5 DIV");
   random_img = Math.floor(Math.random() * unselectedCells.length); // choose a random item
  
  //*****Selects new random image if random is same a previous random image 
  while (random_img==last_image_3){
         random_img = Math.floor(Math.random() * unselectedCells.length); // choose a random item
   };
   
   last_image_3=random_img;
   previous_image_3 = unselectedCells[random_img];
   $(previous_image_3).css({opacity: 0.0})
   .addClass('active')
   .animate({opacity: 1.0}, 1000, function() {
    $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "random_image3()", 6000 );
});