		var code= "";
function generateMondrian() {
		var width = 5000; //540;
		var height = 4000; //440;
		var max_w = Math.round(Math.random() * 7) + 5;
		var max_h = Math.round(Math.random() * 4) + 3;
		var border_width = 0;
		var min_px = 10;
		
		//pick at random number of coloured patches of each type (between 0-3)
		var max_colours = [0, Math.round(Math.random() * 3), Math.round(Math.random() * 3), Math.round(Math.random() * 3)];
		
		//colours sampled from wikipedia copy of Mondrian painting
		//                  white      red        yellow     blue
		var colour_vals = ["#ffffff", "#c71b00", "#f6ca00", "#3470aa"];
		
		
		//calculate remaining whitespace in table exluding the borders and 10px minimum for each box
		var w = width -  (max_w - 1) * border_width - min_px * max_w;
		var h = height - (max_h - 1) * border_width - min_px * max_h;

		//initialize arrays of column/row widths/heights
		var widths = [];
		var heights = [];
		for (var x = 0; x < max_w; x++) {
			widths[x] = 0;
		}
		for (var x = 0; x < max_h; x++) {
			heights[x] = 0;
		}		
		
		//distribute leftover height and width randomly within boxes
		while (w > 0) {
			widths[Math.round(Math.random() * max_w)] += Math.ceil(w / 5);
			w -= Math.ceil(w / 5);
		}
		while (h > 0) {
			heights[Math.round(Math.random() * max_h)] += Math.ceil(h / 5);
			h-= Math.ceil(h / 5);
		}
			
		//initialize grid of colours
		var colours = new Array();
		for (var x = 0; x < max_w; x++) {
			var arr = new Array();
			for (var y = 0; y < max_h; y++) {
				arr[y] = 0;
			}
			colours[x] = arr;
		}		
		//paint random areas with colour
		for (var c = 1; c < 4; c++) {
			for (var i = 0; i < max_colours[c]; i++) {
				colours[Math.round(Math.random() * (max_w - 1))][Math.round(Math.random() * (max_h - 1))] = c;
			}
		}
		
		//generate the table
		code += "<table width=\"5000px\" height=\"4000px\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
		
		for (var x = 0; x < max_h; x++) {
			if (x < max_h - 1) {
				code += "<tr>";
			} else {
				code += "<tr class=\"bottom\">";			
			}
			
			//1 in 2 chance to subdivide into two sub-squares
			var subdivide = Math.round(Math.random() * 1) + 1 == 1;		
			
			
			//don't subdivide < 30px rows
			if (heights[x] + min_px < 30) {
				subdivide = false;
			}
			
			//find a random point to start the subdivision
			var sub_point = Math.round(Math.random() * (max_w - 1));
			var sub_width = Math.round(Math.random() * 1) + 1;
			
			
			//make sure we don't go outside of the grid
			if (sub_width == 2 && sub_point == max_w - 1) {
				sub_point--;
			}
			
			
			//calculate subdivided height
			var he = subdivide? Math.round((heights[x] + min_px - border_width) / 2) : (heights[x] + min_px);
			
			
			//print a row
			for (var y = 0; y < max_w; y++) {
				var style="width: " + (widths[y] + min_px) + "px; height: " + he + "px;";
				style += " background-color: " + colour_vals[colours[y][x]] + ";";				
				
				code += "<td ";
				
				if (subdivide && (y != sub_point && y != sub_point + sub_width - 1)) {
					code += "rowspan=\"2\" ";
				}
				
				if (y < max_w - 1) {
					code += "style=\"" + style +"\">&nbsp;</td>";
				} else {
					code += "class=\"right\" style=\"" + style + "\">&nbsp;</td>";
				}
			}
			code += "</tr>";
			
			
			//print extra td's for subdivisions
			if (subdivide) {
				code += "<tr>";
				
				for (var z = 0; z < sub_width; z++) {
					if (z + sub_point == max_w - 1) {
						code += "<td class=\"right\" height="+he+"></td>";				
					} else {
						code += "<td height="+he+"></td>";
					}
				}
				code += "</tr>";
			}
			
		}
		code += "</table>";
		
		newWindowopen()
		//write it out
		//var mondrian = $('mondrian');
		//mondrian.setHTML(code);
	};

