/* Header image rotator for Wordpress Pixel Blogging theme */
/* (c) 2009 HaveAByte.com. */

$(document).ready(function(){ // When page loads,
	randomizeHeader(); // First execution of header randomization.
});

var currentImage = 4;
var currentCell = 0;

function randomizeHeader() {
	var randomInterval = Math.floor(Math.random()*8)*1000 // 1-8 seconds between intervals
	if (randomInterval == 1) {
		randomInterval += 4;
	}
	currentCell++;
	currentImage++;
	
	if (currentCell > 3) { currentCell = 1 }; 
	if (currentImage > 8) { currentImage = 1 }; // This limits the system to 8 images!
	
	var div = $("#header_image_" + currentCell);
	var imageURL = 'http://www.longbeachchiro.com/header/' + currentImage + '.jpg';
	
	div.fadeOut("fast",function(){
		div.html('<img width="320" height="240" border="0" src="' + imageURL + '"/>');
		div.fadeIn("slow");
	});
	
	setTimeout ( "randomizeHeader()", randomInterval ); // Recursively execute this function on a random interval of 1-8 seconds
}
