// JavaScript Document
window.onload=posDivs;
window.onresize=posDivs;

var aOffset;
function posDivs(){
    var divs = document.getElementsByTagName("div");
    //get maxR
    var maxR =0;
	var adiv;
	var x;
	var aLeft;
	var aWidth;
	var sWidth;

	if (navigator.appName == "Microsoft Internet Explorer") {
	    sWidth = document.documentElement.offsetWidth;
	}
	else {
	    //window.innerHeight
	    sWidth = window.innerWidth;
	};

	for (x = 0; x < divs.length; x++) {
	    aWidth = divs[x].style.width.replace(/px/i, "") * 1;
	    aLeft = divs[x].style.left.replace(/px/i, "") * 1;
        if ((aLeft + aWidth) > maxR) {maxR = aLeft + aWidth; }
    };
    if (!aOffset) {
        aOffset = parseInt((sWidth - maxR) / 2);
    }
    else {
        //re - position
        for (x = 0; x < divs.length; x++) {
            aLeft = (divs[x].style.left.replace(/px/i, "") * 1) - aOffset;
            divs[x].style.left = aLeft + "px";
        }
        aOffset = parseInt((sWidth - (maxR - aOffset)) / 2);
    };
    
    //position
    for (x = 0; x < divs.length; x++) {
        aLeft = (divs[x].style.left.replace(/px/i, "") * 1) + aOffset;
        divs[x].style.left = aLeft + "px";
    };
}