var currentImg = 0;
function theRotator() {

	var height = jQuery("#hbgimg").attr('height');
	jQuery(".home-image").css('height',height);
	setInterval('rotate()',5000);
}

function rotate() {
jQuery("#hbgimg").fadeOut(500, function(){
jQuery("#hbgimg").attr('src',photos[currentImg]).bind('readystatechange load', function(){
if (this.complete) jQuery(this).fadeIn(500);
});
}); 

	currentImg++;
			if(currentImg == photos.length) {
				currentImg = 0;
			}

};
(function(jQuery){
    //cache needed for overagressive garbage collectors.
    var cache = [];
    //images can either be an array of paths to images or a  single image. 
   jQuery.loadImages = function(images){
        //convert to array if needed so rest of script works
        if (!(images instanceof Array)) {
            images = [images];
        }
        
        var imagesLength = images.length;
        var loadedCounter = 0;
        
        for (var i = imagesLength; i--;) {
            var cacheImage = document.createElement('img');
            cacheImage.src = images[i];
            cache.push(cacheImage);
            cacheImage.onload = function(){ 
                loadedCounter++;
                if (loadedCounter >= imagesLength) {
                       theRotator();
                }
            }
        }
    }
})(jQuery)

jQuery.loadImages(photos);


