// The boxes must have a id names: div1, div2, div3, e.t.c., and they have a class style 'float'
var pleft = 5;
var pright = 0; // This must be equaly by left&right padding of the cell class (in this module: 'text');
var mindistance = 0; // Minimal distanse between boxes;
var boxw = 164; // Box width;
// Gets position of element
function gp(object_id)
{
	var offsetLeft = 0;
	var offsetTop = 0;
	offsetTrail = document.getElementById(object_id);
	while(offsetTrail)
	{
		offsetLeft += offsetTrail.offsetLeft;
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}
	return { left:offsetLeft, top:offsetTop }
}
// onResize window event function, it arrange layers with boxes 
function doresize()
{
	var i, oldy;
	//obj01 = document.getElementById('cell01'); // The cell with boxes must have id cell01
	//thewidth = obj01.offsetWidth-pleft-pright; // cell width
	thewidth = document.body.scrollWidth-pleft-pright-220-7-7-7-235-7;
	numx = Math.floor(thewidth/(boxw+mindistance)); // number of boxes in horisontal position
	i = j =1;
	if(numx > 1)
	{
		sh = thewidth-numx*boxw; // new distance between the boxes;
		sh = Math.floor(sh/(numx-1));
		while(true)
		{
			div01 = document.getElementById('cat'+i);
			if(div01==null) break;
			i++;
			if(j==numx){j=1; marg=0;}
			else {marg=sh; j++}
			div01.style.marginRight=marg;
			div01.style.marginLeft=0;
		}
		if((i-1) < numx)
		{
			numx = i-1;
			sh = thewidth-numx*boxw; // new distance between the boxes;
			sh = Math.floor(sh/(numx-1));
			i = j = 1;
			while(true)
			{
				div01 = document.getElementById('cat'+i);
				if(div01==null) break;
				i++; 
				if(j==numx){j=1; marg=0;}
				else {marg=sh; j++}
				div01.style.marginRight=marg;
				div01.style.marginLeft=0;
			}
		}
		if(j > 1)
		{
			i=i-j+1;
			div01 = document.getElementById('cat'+i);
			sh2 = Math.floor((thewidth-((j-1)*boxw+(j-2)*sh))/2);
			if((str=window.navigator.appName) == "Microsoft Internet Explorer")
			{
				sh2 /= 2;
			}
			div01.style.marginLeft=sh2;
		}
	}
}

