//<!--
/*
 * Image Preloader and Rotator
 * http://web-scholar.com
 *
 * Copyright (c) 2010 Gabriele Petrioli
 *
 * Date: 2010-02-23 (Tue, 23 Feb 2010)
 */
function imageRotator( options ){
		this.$element = ((options.element instanceof jQuery) ? options.element : $(options.element)).css({'position':'relative','background-repeat':'no-repeat'});
		this.$overlay = $('<img/>').css({'position':'absolute','top':0,'left':0, 'z-index':0}).hide(0).prependTo(this.$element);
		this.images = [];
		this.effectDuration = options.effectDuration;
		this.rotateDelay = options.rotateDelay;
		this.tempImage = new Image;
		this.tempImage.onload = imageRotator.prototype.imgPreloaded;	
		this.tempImage.rotator = this;
		this.preloadIndex = 0;
		this.currentImage = 0;
		
		if (options.basepath.substring( options.basepath.length-1 ) != '/') options.basepath += '/';
		
		for (img in options.images) 
			this.images.push( {url: options.basepath + options.images[img] } );
		this.preLoad();
		this.start();
		
	}
	imageRotator.prototype.imgPreloaded = function(e)
		{ 
			this.rotator.preloadIndex++; 
			if ( this.rotator.preloadIndex < this.rotator.images.length ) 
				this.rotator.preLoad(); 
		}
	imageRotator.prototype.preLoad = function( )
		{	
			this.tempImage.src = this.images[ this.preloadIndex ].url;
		}	
	imageRotator.prototype.showNext = function( index ){
		var _this = this;
		this.currentImage = ((this.currentImage+1 == this.images.length) || (index!=null))?0:this.currentImage+1;
		this.$overlay.attr('src', this.images[this.currentImage].url );
		this.$overlay.fadeIn( this.effectDuration , function(){ _this.$element.css('background-image', 'url(' + _this.images[_this.currentImage].url + ')' ); $(this).hide(0) } );		
	}
	imageRotator.prototype.start = function(){
		this.showNext(0);
		var _self = this;
		
		if (this.images.length > 1) 
			{
				setInterval( function(){ _self.showNext(); }, _self.rotateDelay );
			}
	}
	
//-->