function divide(a,b)
{
	c = (a - (a % b)) / b;
	return c;
}

window.onresize = changeSize

function changeSize()
{
	var itemSize = 204 // should get as parameter, there from constants...
	var blocMargin = 0
	var fullItemSize = itemSize + (blocMargin * 2)
	var minMargin = 0
	
	var windowWidth = 0
	var windowHeight = 0
	var maxBlocSize = 0
	var numBlocs = 0
	var finalBlocSize = 0
	var ieSize = 0
	var emptySpaceSize = 0
	var equiSpace = 0
	var numSpaces = 0
	var bottomMargin = 0

	if (document.getElementById("items"))
	{
		var mainBlocID = document.getElementById("items")
		
/* get window size */

		if( typeof( window.innerWidth ) == 'number' ) 
		{
			windowWidth = window.innerWidth
			windowHeight = window.innerHeight
		} 
		else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
		{
			//IE 6+ in 'standards compliant mode'
			windowWidth = document.documentElement.clientWidth - 35
			windowHeight = document.documentElement.clientHeight
		} 
		else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
		{
			//IE 4 compatible
			windowWidth = document.body.clientWidth - 35
			windowHeight = document.body.clientHeight
		}
		
/* calculate the values */	

		maxBlocSize = windowWidth - (windowWidth % fullItemSize)
		numBlocs = divide(windowWidth,fullItemSize)
		emptySpaceSize = windowWidth - (numBlocs * itemSize)
		if (emptySpaceSize < (minMargin * 2))
		{
			numBlocs--;
		}
		numBlocs--;
		numSpaces = numBlocs + 1
		emptySpaceSize = windowWidth - (numBlocs * itemSize) - 10

		equiSpace = divide(emptySpaceSize,numSpaces)
		equiSpaceIE = divide(emptySpaceSize + 40,numSpaces)
		blocMargin = equiSpace
		ieMargin = equiSpaceIE

		/*document.write(finalBlocSize)
		document.write(',')	
		document.write(blocMargin)*/
		
/* attribute the values */

		var x = document.getElementsByTagName('li')
		for (var i=0;i<x.length;i++)
		{
			if (x[i].className == 'item-square')
			{
				if (x[i].style.setAttribute)
				{
					x[i].style.margin = ieMargin + "px 0 0 " + ieMargin + "px;"
				}
				else
				{
					x[i].setAttribute("style", "margin:" + blocMargin + "px 0 0 " + blocMargin + "px;")
				}
			}
		}

		topMargin = blocMargin - 10		
		bottomMargin = blocMargin - 15

		
		if (mainBlocID.style.setAttribute)
		{	
			mainBlocID.style.margin =  topMargin + "px 0 " + bottomMargin + "px -" + blocMargin + "px;"
		}
		else
		{
			mainBlocID.setAttribute("style", "margin:" + topMargin + "px 0 " + bottomMargin + "px 0;")
		}
		
		if (document.getElementById("footer").style.setAttribute)
		{
			footerTop = bottomMargin + 40
			document.getElementById("footer").style.margin = footerTop + "px 0 0 0;"
		}
		else
		{
			document.getElementById("footer").setAttribute("style", "padding-bottom:10px;")
		}

	}
}	