




function scrollBarFixInit(attribute,helper) {

	if(!attribute) {
			attribute = "padding-left"
	}
	
	var $ = jQuery;

	var scrollBarWidth = 0;
	
	function getScrollBarWidth() { 
	  if(scrollBarWidth == 0) {
	    $('body').append($('<div id="outer" style="overflow: scroll; width: 100px; position: absolute; left: -200px; top: 0px;"><div id="inner" style="width: 100%;"></div></div>'));              
	    scrollBarWidth = $('div#outer').width() - $('div#inner').width();
	    $('div#outer').remove();
	  }
	  return scrollBarWidth;
	}

  function isThereAScrollBar() {
    return $('html').attr('clientHeight') != $('html').attr('scrollHeight');
  }
 
  function resize(from_timeout) {
	
			if(isWindowResize()) {
        unlockBody(lastWidth - $(window).width());
      } else {
        lockBody(from_timeout);
      }
  }


  var lastWidth = $(window).width();

	function isWindowResize() {
		
		
      var widthDiff = lastWidth - $(window).width();
      lastWidth = $(window).width();
  
      var viewPortWidth = $(window).width();
		
		  return (widthDiff != (getScrollBarWidth()*-1) && widthDiff != getScrollBarWidth() && widthDiff != 0);
	}
  




  var oldStyle = "";
  var timeoutCount = 0;
  
  function unlockBody(widthDiff) {
    
    lastUnlockbody = new Date().getTime();
    // When we unlock we force no scroll bar so that we can be sure about the window size
    var style = '';
    if(isThereAScrollBar()) {
      style = attribute+': '+getScrollBarWidth()+"px;";
    }
    $("body").attr('style',style+$("body").attr('style').replace(oldStyle,''));
    oldStyle = style;
    
    timeoutCount++;
    
    setTimeout(function() {
      timeoutCount--;
      if(timeoutCount == 0) {
        resize();
      }
    },500);

		if(helper) {
			helper(getScrollBarWidth(),false,false);
		}
  }
  
  function lockBody(fromTimeout) {
	
		var window_width = $(window).width();
		
    var style = attribute+': '+getScrollBarWidth()+'px; width: '+(window_width-(getScrollBarWidth()*2))+'px;'
    if(isThereAScrollBar()) {
       var style = attribute+': '+getScrollBarWidth()+'px; width: '+(window_width-(getScrollBarWidth()*1))+'px;'
    } 

    $("body").attr('style',style+($("body").attr('style')+"").replace(oldStyle,''));
    oldStyle = style;

		// Tell helper to fix any problems th antijump script couses
		if(helper) {
			helper(getScrollBarWidth(),isThereAScrollBar(),true);
		}
		
		if(fromTimeout != true) {
			setTimeout(function() {resize(true);},100);
			setTimeout(function() {resize(true);},200);
			setTimeout(function() {resize(true);},300);
			setTimeout(function() {resize(true);},600);
			setTimeout(function() {resize(true);},1200);
		}
  }




  
  $(window).bind('resize',function(e) {
     resize();     
  });

	if(!$('body').attr('style')) {
    $('body').attr('style',' ');
  }

	resize();
}




