	//Generate the grid size based on the users screen width and screen height
		// If the screen width is less than or equal to 2000 px then the grid will be generated with the actual screen width. If greater than 2000px, then 2000px will be substituted for screenwidth, otherwise the color overlay will not fully cover the grid.
		if (screen.width <= 2000)
			{ var screenWidth = screen.width; }
		else { var screenWidth = 2000; }
		// Identify the users screen width divide by the size of the small images and round up to get the grid width size.
		var GridWidth = Math.ceil(screenWidth / 80);
		// If the screen height is less than or equal to 2000 px then the grid will be generated with the actual screen height. If greater than 2000px, then 2000px will be substituted for screenwidth, otherwise the color overlay will not fully cover the grid.
		if (screen.height <= 2000)
			{ var screenHeight = screen.height; }
		else { var screenHeight = 2000; }
		// Identify the users screen height divide by the size of the small images and round up to get the grid height size.
		var GridHeight = Math.ceil(screenHeight / 80);

	function RotatingBackground(obj,options) {
		options = options || new Object();
		this.NumberOfImages = options.numberOfImages || 97; // 97 default number for this instance
		this.MinRotationTime = options.minTime || 10000; 
		this.MaxRotationTime = options.maxTime || 90000; 
		this.SquaresWide = options.width || GridWidth; // number of Tall squares to fit in width
		this.SquaresHigh = options.height || GridHeight; // number of Tall squares to fit in height
		this.smallSquareSize = options.tall-5 || 75; 
		this.sizes = new Array(this.smallSquareSize,(this.smallSquareSize+5)*2-5,(this.smallSquareSize+5)*3-5,(this.smallSquareSize+5)*4-5);
		this.background = obj.css({width:this.SquaresWide*(this.smallSquareSize+5)+5,height:this.SquaresHigh*(this.smallSquareSize+5)+5});
		this.placeImages();
		that = this;
		this.background.children('img').each(function() {
			this.change = function() {
				$(this).attr('src',that.randomImage());
				var t = Math.floor(Math.random() * (that.MaxRotationTime - that.MinRotationTime) + that.MinRotationTime);
				window.setTimeout(function(i){i.change()},t,this)
				}
			this.change();
			
		});		
	}
	
	//Class Functions
	RotatingBackground.prototype.newImage = function(s){
			return $("<img class='back_basic'/>").css({width:this.sizes[s-1],height:this.sizes[s-1]});
	}
	
	RotatingBackground.prototype.randomImage = function() {
		// returns the string sources for a random image
		return 'i/Back'+Math.ceil(Math.random() * this.NumberOfImages)+'.jpg';
	}
												 
	RotatingBackground.prototype.placeImages = function() {
		//fill background with four different sized square images
		var fill = new Array(); // array to keep track of what is filled
		for(c=0; c<this.SquaresWide; c++) fill[c] = -1;
		for(r=0; r<this.SquaresHigh; r++) {
			for(c=0; c<this.SquaresWide; c++) {
				if(fill[c] >= r) continue; //already filled that square try next one
				var l=1;
				for(i=1; i<4; i++) { // find how big a square we can place Largest size is 4
					if(r+l >= this.SquaresHigh || c+l >= this.SquaresWide || fill[c+l] >= r) break;
					//  goes over bottom edge      goes over side edge        runs over already placed image
					l++;
				}
				var s = (l==1)?1:Math.ceil(Math.random()*l); //size of new image random int l or less
				this.background.append(this.newImage(s).css({left:(this.smallSquareSize+5)*c,top:(this.smallSquareSize+5)*r}));
				//mark squares as filled
				for(i=0; i<s; i++) {
					fill[c+i]+=s;
				}
			}
		}
	}
