
	function GetWindowWidth() { 
		if (parseInt(navigator.appVersion)>3) {
			if (navigator.appName=="Netscape") {
				winW = window.innerWidth-16;
				winH = window.innerHeight-16;
			}
			if (navigator.appName.indexOf("Microsoft")!=-1) {
				winW = document.body.offsetWidth-20;
				winH = document.body.offsetHeight-20;
			}
			if (navigator.appName=="Opera") {
				winW = window.innerWidth-16;
				winH = window.innerHeight-16;
			}
		}
		
		return {w: winW, h: winH};
	}

	function GetFloaterFrames() {
		var divs = document.getElementsByTagName('DIV'); 
		var res = new Array();
		
		for (var i=0; i < divs.length; ++i) {
			if (divs[i].className == 'floater') {
				res.push(divs[i]);				
			}
		}	
		
		return res;
	}
	
	function SpreadBlocks() {
		ws = GetWindowWidth();
		
		center = { x: (ws.w / 2), y: (ws.h / 2) };
		
		var frm = GetFloaterFrames();
				
		
		sq = new Array();		
		if (folderId == 914) {
			sq.push( {l: 10, t: 10, r: 500, b: 500 } );
			center.y = 270;
			threshold = 5000;
			vStep = Math.max(10, Math.floor(60000 / ws.w) - 20) * 0.56;
		} else if (folderId == 913) {
			sq.push( {l: 10, t: 10, r: 500, b: 500 } );
			center.y = 220;
			threshold = 5000;
			vStep = Math.max(10, Math.floor(60000 / ws.w) - 30) * 1.2;
			
		} else {
			sq.push( {l: 10, t: 10, r: 500, b: 260 } );
			center.y = 100;
			threshold = 13000;
			vStep = Math.max(10, Math.floor(60000 / ws.w) - 30);
		}
			
		
		xOffset = Math.floor(ws.w * 0.06);
		
		
		globalSafety = 10; 
		vStep *= 1.3;
		
		
		for (i=0; i < frm.length; ++i) {
			d = frm[i];
			w = d.clientWidth; 
			h = d.clientHeight; 
						
			var safety = 120;
			var bestOverlap = 9999999;
			var bestXY = {};

			do {				
				x = Math.floor(Math.random() * ( ws.w - w - xOffset * 2)) + xOffset; 
				y = center.y + Math.floor(Math.random() * vStep * 2 + vStep);
				fits = true;
				var overlap = 0; 
										
				for (j=0; j < sq.length; ++j) {
					s = sq[j];
					if (s.b < y) continue; 
					if (s.r < x || s.l > (x+w)) continue;
					
					l = Math.max(x, s.l);
					r = Math.min(x+w, s.r);
					
					t = Math.max(y, s.t);
					b = Math.min(y+h, s.b);
					overlap = Math.max(overlap, (r - l) * (b - t));
					
				}
				//  console.log('obj: ' + i +', x: ' + x + ', y: ' + y + ', ol: ' + overlap);
				if (overlap > threshold) {
					if (overlap < bestOverlap) {
						bestOverlap = overlap;
						bestXY.x = x; 
						bestXY.y = y; 
					}
					fits = false;
				}
												
			} while (!fits && --safety);
			
			if (!safety) {
				
				x = bestXY.x;
				y = bestXY.y;
			}
						
			// console.log('verdict: x: ' + x + ', y: ' + y);
			sq.push( {l: x, t: y, r: x+w, b: y+h} );
			center.y = y;
			
			d.style.left = x + 'px';
			d.style.top = y + 'px';
		
		}
		
		if (el = document.getElementById('divList')) {
			el.style.height = (center.y + h - 250) + 'px';
		}
		
	}


	
	SpreadBlocks();
