/* iframe size control */
var cbds;
var subifname = "reflectiframe";

function reSize() {
	if (!parent.document.getElementById(subifname)) {
		return;
	}
	parent.document.getElementById(subifname).height=400;
	if(parent.document.getElementById(subifname)) {
		cbds = new DocumentSizeObserver(document, list_onload, "cbds");
	}
}

function reSizeFrame(framename)
{
	iframe = framename;
	cbds = new DocumentSizeObserver(document, list_onload, "cbds");
}	

function DocumentSizeObserver(document, eventFunc, instanceName) 
{

	this.document = document;
	this.limit = 10;
	this.wf = false;				// width 완료 여부 
	this.hf = false;				// height 완료 여부
	this.prew = 0;					// 이전 주기의 width
	this.preh = 0;					// 이전 주기의 width
	this.check = checkDocumentSize;	// resize 메소드. SetInterval에 의해 주기적 호출 
	this.execute = eventFunc; 		// 렌더링 완료 판단 후 호출 
	this.instanceName = instanceName;

	setTimeout(this.instanceName + '.check()', 100);
}

function list_onload(width, height) 
{
	try
	{
		parent.frameResize(height);
	}
	catch(e)
	{
		//alert(e);
	}	
}

function checkDocumentSize()
{
	// 윈도우가 완전히 렌더링 되어 사이즈가 고정될때까지
	if (this.limit-- <= 0) 
	{
		// 더이상 기다리지 않고, 마지막에 읽은 크기 전달 
		this.execute(this.prew, this.preh);
		return;
	}
	
	var cw = document.body.scrollWidth;
	var ch = document.body.scrollHeight;
	var dw = cw - this.prew;
	var dh = ch - this.preh;
	
	this.prew = cw; 
	this.preh = ch; 

	if (cw > 0 && dw == 0) 
		this.wf = true;
	if (ch > 0 && dh == 0) 
		this.hf = true;
		
	if (this.wf && this.hf)
		this.execute(cw, ch);
	else 
		setTimeout(this.instanceName + '.check()', 100);
}	

function frameResize(v) {
	if(v>400) {
		document.getElementById(subifname).height=v;
	} else {
		document.getElementById(subifname).height=400;	
	}
}