// JavaScript Document

var numPhoto = 16;
var numBook = 8;
var numCover = 5;
var currentPhoto = numPhoto;
var currentBook = numBook;
var currentCover = currentCover;
var mainTimer;
var diceFace = 0;
var z = 13;

function init() {
		$("#slideShowHolder").css("visibility", "visible");
		mainTimer = setInterval( rollDice, 4000 );
}

function rollDice() {
	diceFace = Math.floor( Math.random() * 3 ) + 1;
	switch( diceFace ) {
		case 1:
			var nextBook = Math.floor( Math.random() * numBook ) + 1;
			if( nextBook != currentBook ) {
				$("img[name='book"+nextBook.toString()+"']").css({'z-index' : z.toString() , 'top' : "-300px"});
				$("img[name='book"+nextBook.toString()+"']").animate( { top : "0px" }, "slow");
				currentBook = nextBook;
			}
			break;
		case 2:
			var nextPhoto = Math.floor( Math.random() * numPhoto ) + 1;
			var nextCover = Math.floor( Math.random() * numCover ) + 1;
			if(nextPhoto != currentPhoto) {
				$("img[name='photo"+nextPhoto.toString()+"']").css({'z-index' : z.toString() , 'top' : "300px"});
				$("img[name='photo"+nextPhoto.toString()+"']").animate( { top : "0px" }, "slow");
				currentPhoto = nextPhoto;
			}
			if(nextCover != currentCover) {
				$("img[name='cover"+nextCover.toString()+"']").css({'z-index' : z.toString() , 'top' : "300px"});
				$("img[name='cover"+nextCover.toString()+"']").animate( { top : "0px" }, "slow");
				currentCover = nextCover;
			}
			break;
		case 3:
			var nextPhoto = Math.floor( Math.random() * numPhoto ) + 1;
			var nextCover = Math.floor( Math.random() * numCover ) + 1;
			var nextBook = Math.floor( Math.random() * numBook ) + 1;
			
			if(nextPhoto != currentPhoto) {
				$("img[name='photo"+nextPhoto.toString()+"']").css({'z-index' : z.toString() , 'top' : "300px"});
				$("img[name='photo"+nextPhoto.toString()+"']").animate( { top : "0px" }, "slow");
				currentPhoto = nextPhoto;
			}
			if(nextBook != currentBook) {
				$("img[name='book"+nextBook.toString()+"']").css({'z-index' : z.toString() , 'top' : "-300px"});
				$("img[name='book"+nextBook.toString()+"']").delay(500).animate( { top : "0px" }, "slow");
				currentBook = nextBook;
			}
			if(nextCover != currentCover) {
				$("img[name='cover"+nextCover.toString()+"']").css({'z-index' : z.toString() , 'top' : "300px"});
				$("img[name='cover"+nextCover.toString()+"']").delay(1000).animate( { top : "0px" }, "slow");
				currentCover = nextCover;
			}
			break;
	}
	z++;
}
