function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
function addResizeEvent(func) {
  var oldonresize = window.onresize;
  if (typeof window.onresize != 'function') {
    window.onresize = func;
  } else {
    window.onresize = function() {
      oldonresize();
      func();
    }
  }
}

function tpUpdatePosition(){
	ww = document.body.clientWidth;
	tpDiv = document.getElementById('tpWidget');
	if (tpDiv) {
		if (ww < 948) {
			if (tpDiv.className != 'popWide') {
				
				tpDiv.className = 'popWide';
			}
		} 
		
		else {
			
			if (tpDiv.className != 'popNarrow') {
				
				tpDiv.className = 'popNarrow';
			}
		}
	}
}

//DOM-ready watcher
//use to safely trigger events earlier than the window.onLoad event
//see: http://www.codingforums.com/showthread.php?t=58882
function domFunction(f, a)
{
	var n = 0;
	var t = setInterval(function(){
		var c = true;
		n++;
		if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null)){
			c = false;
			if(typeof a == 'object'){
				for(var i in a){
					if( (a[i] == 'id' && document.getElementById(i) == null) || (a[i] == 'tag' && document.getElementsByTagName(i).length < 1) ) { 
						c = true; 
						break; 
					}
				}
			}
			if(!c) { 
				f(); 
				clearInterval(t);
			}
		}
		if(n >= 60){ 
			clearInterval(t);
		}
	}, 200);
};

//addLoadEvent(tpUpdatePosition);
if ((navigator.userAgent.toLowerCase().indexOf("win98") == -1) && (navigator.userAgent.toLowerCase().indexOf("windows 98") == -1) ) {
	// not Win98
	if (navigator.userAgent.toLowerCase().indexOf("msie 5.0") == -1) {
		// not IE 5.0
		var quickloader = new domFunction(tpUpdatePosition, {'tpWidget':'id'});
		addLoadEvent(tpUpdatePosition);
		addResizeEvent(tpUpdatePosition);
		
	}
}

