/************************************************************************************************
* PHPSCHOOL 송효진님 소스 수정																    *
* document.body.scrollTop -> document.documentElement.scrollTop 으로 수정해서 xhtml에 맞게 적용 *
* banner가 메인프레임과는 별도로 생성되어 최소 top을 110으로 제한함                             *
*************************************************************************************************/

//var MAX_TOP=126;
var MAX_TOP=8;

String.prototype.toInteger = function() {
	return this.replace(/[^0-9]/g, '') * 1;
}

//follow_banner("배너아이디", 원래의 위치, 따라다니기 시작하는 높이, 화면 위쪽마진);
function follow_banner(div_id, origin_top, limit_top, margin_top){

	var d, t, s, g, target_height;
	origin_top *= 1;
	limit_top *= 1;
	margin_top *= 1;

	d = document.getElementById(div_id);
	s = document.documentElement.scrollTop + "";
	
	target_height = s.toInteger() + margin_top;
	
	if(target_height < limit_top) {
		target_height = origin_top;
	}//body에 height값과 target 값을 비교해서 body가 움직였으면 움직일 height를 지정해줌

	t = d.style.top.toInteger();
	
	if(t != target_height) {
		g = Math.ceil((t - target_height) / 5);
		
		if(g > 50) {
			g = 50;
		} else if (g < -50) {
			g = -50;
		}
		
		//top이 최대로 올라가지 않도록 제한
		var net_top;
		if((t - g) < MAX_TOP)
			new_top=MAX_TOP;
		else
			new_top=(t - g);

		d.style.top = new_top + "px";
	}

	setTimeout("follow_banner('" + div_id + "', " + origin_top + ", " + limit_top + ", " + margin_top + ");",1);
}