var tic, tac;
function checkCenter(){
clearInterval(tic);
if(!tac){tac=0;}
if(!!(tac == document.documentElement.offsetWidth)){
window.clearInterval(tic);
tic=null;
}
else {
window.clearInterval(tic);
tic=null;
tic=window.setInterval("floatCenter()",75);
}
}

var wrap,odds,count,div,min;
function floatCenter(){
if(tac == document.documentElement.offsetWidth){return;}
  if(!wrap){
    wrap=document.getElementById('wrapper');
  }
  if(!div){
    div = wrap.getElementsByTagName('div')[0];
  }

    wrap.style.cssFloat='left';
    wrap.style.styleFloat='left';
    wrap.style.width='auto';
    wrap.style.overflow='visible';
    wrap.style.marginLeft='0';
    wrap.style.marginRight='0';

  if(!odds){
  odds=0;
  if (document.body.currentStyle){
  //add div parent margin left & right
    odds+=parseInt(div.parentNode.currentStyle.marginLeft,5);
    odds+=parseInt(div.parentNode.currentStyle.marginRight,5);
  //add div parent padding left & right
    odds+=parseInt(div.parentNode.currentStyle.paddingLeft,5);
    odds+=parseInt(div.parentNode.currentStyle.paddingRight,5);
  //add div parent border left & right
    odds+=parseInt(div.parentNode.currentStyle.borderLeftWidth,5);
    odds+=parseInt(div.parentNode.currentStyle.borderRightWidth,5);
  }
  else if(document.defaultView.getComputedStyle){
  //add div parent margin left & right
    odds+=parseInt(document.defaultView.getComputedStyle(div.parentNode,'').marginLeft,5);
    odds+=parseInt(document.defaultView.getComputedStyle(div.parentNode,'').marginRight,5);
  //add div parent padding left & right
    odds+=parseInt(document.defaultView.getComputedStyle(div.parentNode,'').paddingLeft,5);
    odds+=parseInt(document.defaultView.getComputedStyle(div.parentNode,'').paddingRight,5);
  //add div parent border left & right
    odds+=parseInt(document.defaultView.getComputedStyle(div.parentNode,'').borderLeftWidth,5);
    odds+=parseInt(document.defaultView.getComputedStyle(div.parentNode,'').borderRightWidth,5);
  }
  }

  if( isNaN(odds) ) odds = 0;
  
  if(!count){
    count = div.offsetWidth;
    if (document.body.currentStyle){
    //add div margin left
      count+=parseInt(div.currentStyle.marginLeft,5);
      count+=parseInt(div.currentStyle.marginRight,5);
    }
    else if(document.defaultView.getComputedStyle){
    //add div margin left & right
      count+=parseInt(document.defaultView.getComputedStyle(div,'').marginLeft,5);
      count+=parseInt(document.defaultView.getComputedStyle(div,'').marginRight,5);
    }
  }
  if(!min){min=Math.ceil(count+odds);}
  var check = (Math.floor((wrap.parentNode.offsetWidth-odds)/count)*count)+odds;
  var w = Math.ceil(wrap.offsetWidth);
  if(w<=check+5){w=w;wrap.className='pass';}
  else {w=check;wrap.className='fail';}
  if(w<=min){w=min}
    wrap.style.cssFloat='none';
    wrap.style.styleFloat='none';
	
    wrap.style.width=w+'px';
	//wrap.style.offsetWidth=w+'px';
    wrap.style.overflow='auto';
    wrap.style.marginLeft='auto';
    wrap.style.marginRight='auto';

  wrap.style.display="none";
  wrap.style.display='';
  tac=document.documentElement.offsetWidth;
  }

if(document.getElementById && document.getElementsByTagName){
// attach events
if( window.addEventListener ) {
   window.addEventListener('load',checkCenter,false);    //legacy
   window.addEventListener('resize',checkCenter,false);
} else if( document.addEventListener ) {
   document.addEventListener('load',checkCenter,false);  //proper
   document.addEventListener('resize',checkCenter,false);
} else if( window.attachEvent ) {
   window.attachEvent("onload", checkCenter);            //IE only
   window.attachEvent("onresize", checkCenter);

}
}