
/***************************************************************************************************************
 # file name : static.js
 # copyright : 2005.12.07 Kim sang gu. ver 4. 4
 # explorer Àü¿ë
 # ¼³¸í : »óÇÏ¸¦ ½ºÅ©·ÑÀ» µû¶ó ¿òÁ÷ÀÌ´Â µû¶ó´Ù´Ï´Â - °íÁ¤µÈ ·¹ÀÌ¾î ±â´É.
 ***************************************************************************************************************/

function ju__STATIC_OBJECT(uid, table, label) {
  this.uid = uid;
  this.name = "ju__tag_static[" + this.uid + "]";
  this.table = table;
  this.label = label;

  this.limit = 0;
  this.absolute = 0;
  this.timer = null;

  this.top = 0;
  this.bottom = 10;
  this.active = true;
  this.motion = true;
  this.delay = .05;
  this.message = new Array("start", "stop");

  this.activity = ju__STATIC_OBJECT_activity;
	this.setting = ju__STATIC_OBJECT_setting; 
  this.init = null;
	
	this.msgcreate = null;
  this.controller = ju__STATIC_OBJECT_controller;
  this.messenger = ju__STATIC_OBJECT_messenger;

  this.activity();
}

function ju__STATIC_OBJECT_activity() {
  var table = document.getElementById(this.table);
	
	if(table != null) {
		if(this.init == null) { this.init = ju__STATIC_OBJECT_init; this.init(); }
		this.setting();
	}

  if(this.timer) clearTimeout(this.timer);
  this.timer = setTimeout(this.name+".activity()", 1);

	return true;
}

function ju__STATIC_OBJECT_init() {
  var table = document.getElementById(this.table);

  table.style.position = "relative";
  this.absolute = table.offsetTop;
	this.limit = (this.absolute - this.top) + table.parentElement.offsetHeight - (table.offsetHeight + this.bottom);

	if(this.label) { this.msgcreate = ju__STATIC_OBJECT_msgcreate; this.msgcreate(); }
}

function ju__STATIC_OBJECT_setting() {
  var current, last, amount, tmp, sign = false;
  var table = document.getElementById(this.table);

	current = table.offsetTop;

	if(this.active == true) {
		last = document.body.scrollTop + this.top;

		if(last < this.absolute) { last = this.absolute; }

		tmp = (this.absolute - this.top) + table.parentElement.offsetHeight - (table.offsetHeight + this.bottom);
		if(this.limit != tmp) {
			this.limit = tmp;
			if(last > this.limit) { sign = true; }			
		}
		
	} else {  
		if(this.motion == false) table.style.pixelTop = 0;

		if(table.offsetTop == this.absolute) {
			if(this.timer) clearTimeout(this.timer);
			return true;
		}

		last = this.absolute;
	}

	if(last != current) {
		if(sign == false) {
			amount = (last - current) * this.delay;
			amount = (amount > 0) ? Math.ceil(amount) : Math.floor(amount);
			if((amount + current) > this.limit) { amount = this.limit - current; }
		} else { amount = this.limit - current; }
		
		table.style.pixelTop += amount;
	}
}

function ju__STATIC_OBJECT_msgcreate() {
	var tag = "";
	
	tag += "<input id='"+this.label+"_label_btn' type='checkbox' onfocus='this.blur();' onclick='"+this.name+".controller();' style='cursor:hand;'>";
	tag += "<span id='"+this.label+"_label_msg' onfocus='this.blur();' onclick='"+this.name+".controller();' style='cursor:hand;'>ÀÌµ¿¸Þ´º ¸ØÃß±â</span>";
	
	document.getElementById(this.label).innerHTML = tag;
	this.messenger();
}

function ju__STATIC_OBJECT_controller(active) {
  this.active = (active == null) ? (this.active ? false : true) : (active ? true : false);

  if(this.active == true) { this.timer = setTimeout(this.name+".activity()", 1); } 
	
	this.messenger();
}

function ju__STATIC_OBJECT_messenger() {
	document.getElementById(this.label+"_label_msg").innerHTML = this.message[(this.active?1:0)];
	document.getElementById(this.label+"_label_btn").checked   = this.active;
}

function ju__init_static() {
	var tags = document.all.tags("STATIC");
	
	if(tags == null) { return false; }
	
	for(i=0; i<tags.length; i++) {
	  if(!tags[i].table) { alert('Àû¿ëÇÒ table id´Â ¹Ýµå½Ã ÀÔ·ÂÇÏ¿©¾ß ÇÕ´Ï´Ù.'); continue; }
	  if(!document.getElementById(tags[i].table)) { alert('Á¸ÀçÇÏÁö ¾Ê´Â table idÀÔ´Ï´Ù.'); continue; }
		
		if(!document.getElementById(tags[i].label)) { tags[i].label = null; }
		
		ju__tag_static[i] = new ju__STATIC_OBJECT(i, tags[i].table, tags[i].label);
		
		if(tags[i].top)    ju__tag_static[i].top = Number(tags[i].top);
		if(tags[i].bottom) ju__tag_static[i].bottom = Number(tags[i].bottom);
		if(tags[i].start)  ju__tag_static[i].message[0] = tags[i].start;
		if(tags[i].stop)   ju__tag_static[i].message[1] = tags[i].stop;
		if(tags[i].active) ju__tag_static[i].active = eval(tags[i].active);
		if(tags[i].motion) ju__tag_static[i].motion = eval(tags[i].motion);
		if(tags[i].delay)  ju__tag_static[i].delay = Number(tags[i].delay);
	}

	document.all.tags("STATIC").getElementById = function(table) {
		var static, tags = document.all.tags("STATIC");
		
		for(i=0; i<tags.length; i++) { if(ju__tag_static[i].table == table) { return ju__tag_static[i]; } }
	}
}

var ju__tag_static = new Array();
window.attachEvent("onload", ju__init_static); 

