

	function ImageShuffleClass(){
		
		this.Data = new Array();
		
	}
	
	//ImageShuffleClass.prototype.Data = new Array();
	
	ImageShuffleClass.prototype.Pause = 3;
	
	ImageShuffleClass.prototype.PauseAtFirst = 0;
	
	ImageShuffleClass.prototype.Fade = .85
	
	ImageShuffleClass.prototype.Rotations = 1000;
	
	ImageShuffleClass.prototype.DivId = "";
	
	ImageShuffleClass.prototype.ImgId = "";
	
	ImageShuffleClass.prototype.AnchorId = "";
	
	ImageShuffleClass.prototype.DeckSize = 0;
	
	ImageShuffleClass.prototype.Opacity = 100;
	
	ImageShuffleClass.prototype.OnDeck = 0;
	
	ImageShuffleClass.prototype.StartImg = "";
	
	ImageShuffleClass.prototype.StartHref = "";
	
	ImageShuffleClass.prototype.ImageRotations = 0;
	
	ImageShuffleClass.prototype.GetDataUrls = function(){
		
		var strReturn = "";
		
		for(var i=0; i<this.Data.length; i++){
			
			strReturn += "<br>-"+this.Data[i].url+"";
			
		}
		
		return strReturn;
		
	}
	
	ImageShuffleClass.prototype.AddItem = function(strUrl, strHref){
		
		this.Data.push({url:strUrl, href:strHref});
		
	}
	
	ImageShuffleClass.prototype.Start = function(){
		
		this.StartImg = $(this.ImgId).src;
		
		this.StartHref = $(this.AnchorId).href;
		
		$(this.DivId).style.backgroundImage='url(' + this.Data[this.OnDeck].url + ')';
		
		this.ImageRotations = this.Data.length * (this.Rotations + 1);
		
		setTimeout(this.Fader.bind(this), (this.Pause + this.PauseAtFirst) * 1000);
		
	}
	
	ImageShuffleClass.prototype.Fader = function(){
		
		//Log("Fader theimg = " + this.ImgId);
		var theimg = $(this.ImgId);
		
		// determine delta based on number of fade seconds
		// the slower the fade the more increments needed
		var fadeDelta = 100 / (30 * this.Fade);
		
		// fade top out to reveal bottom image
		if (this.Opacity < 2 * fadeDelta ){
		
			this.Opacity = 100;
			
			// stop the rotation if we're done
			if (this.ImageRotations < 1) return;
			
			this.Shuffle();
			
			// pause before next fade
			setTimeout(this.Fader.bind(this), this.Pause * 1000);
		
		}else{
		 
			this.Opacity -= fadeDelta;
		  	
			SetOpacity(theimg, this.Opacity);
		  	
			setTimeout(this.Fader.bind(this), 30);  // 1/30th of a second
			
		}
		
	}
	
	ImageShuffleClass.prototype.Shuffle = function(){
		
		var thediv = $(this.DivId);
		var theimg = $(this.ImgId);
		var theanchor = $(this.AnchorId);
		
		// copy div background-image to img.src
		theimg.src = this.Data[this.OnDeck].url;
		theanchor.href = this.Data[this.OnDeck].href;
		window.status = this.Data[this.OnDeck].href; // updates status bar (optional)
		
		// set img opacity to 100
		SetOpacity(theimg, 100);		
		
		// shuffle the deck
		var intDeckSize = this.Data.length;
		this.OnDeck = ++this.OnDeck % intDeckSize;
		
		// decrement rotation counter
		if (--this.ImageRotations < 1){
			
			// insert start/final image if we're done
			this.Data[this.OnDeck].url = this.StartImg;
			this.Data[this.OnDeck].href = this.StartHref;
		}
		
		// slide next image underneath
		thediv.style.backgroundImage='url(' + this.Data[this.OnDeck].url + ')';
		
	}	
	
	
