// Alternate promotional images
// In this case we are taking one promo image (hardcoded in the webpage) and then alternating it with a random faculty book image
// Slideshow done with the cycle plugin with jQuery
// Author: Daniel Lucas
// July 29, 2008

// Start jQuery function
$(document).ready(function() {
	// Begin HTML Output
	
	//Animate slideshow.  
	//Make a callback after a slide has loaded
	$("#bookcover").cycle({
		fx: 'fade',
		timeout: 5000,
		after: onAfter
		
	});
	
	// Callback function
	function onAfter() {
		
		// Create linked image and text to be inserted.
		randNum = Math.ceil(Math.random()*27);
		//debug for Firebug console.log(randNum);
		imageLink = "<a href=\"/display/facultybooks/list.php\"  class=\"homeLinks\"><em>";
		imageURL = "<img src=\"/display/facultybooks/cover_images/" + randNum + ".gif\" />";
		imageCaption = "<br />Recent Faculty Books";
		imageEndLink = "</em></a>";
		imageDivContents = imageLink + imageURL + imageCaption + imageEndLink;

		// Debug console alerts for Firebug 
		//console.log(imageDivContents);
		//console.log(this.id);

		// Insert created image and text into randomBookCover div
		// Only if we are not already on that slide.
		if (this.id!='randomBookCover') {
			$('#randomBookCover').html(imageDivContents);
		}
		
	}
	
	
});

