/*================================================
DEFAULT util script. by sensitivefreak, delie
-------------------------------------------------
> information
	win : 새 창 관련 유틸
		open - 새 창 띄우기
			loc 경로-------------|
			wid 가로사이즈       |--(생략 불가)
			hei 세로사이즈-------|
			etc 기타 옵션        |--(생략 가)
			nam 새창 이름--------|
		close - 창 닫기
	evt : 이벤트 관련 유틸
		add - 이벤트 등록
		del - 등록 된 이벤트 삭제 (미구현)
	dom : 엘레멘트 관련 유틸
		$ - document.getElementById("element name")기능 / prototype 에서 발췌, 이와 관련한 카피라이트는 하단에 표기
		tg_img - 이미지 토글 기능 / JPG, GIF and FF, IE, OP, Safari 지원
-------------------------------------------------
> example
	새 창을 띄울 때
		win.open(param1, param2, param3...
	이미지 롤오버 롤아웃
		<img src="[path]" onmouseover="dom.tg_img(this);" onmouseout="dom.tg_img(this);"...
		or use in Script Area
		dom.tg_img($("element id"));
-------------------------------------------------*/

var win = {
	open : function(loc, wid, hei, etc, nam) {
		if(loc) {
			var win;
			var opt = "toolbar=no, menubars=no, left=0, top=0";
			var w = (wid) ? wid : "100";
			var h = (hei) ? hei : "100";
			var e = (etc) ? "," + etc : "";
			var n = (nam) ? nam : "";
				opt += ", width=" + w + ", height=" + h + e;
				win = window.open(loc, nam, opt);
				win.focus();
		}
	},
	close : function(tar) {
		var w = (tar) ? tar : window;
			w.close();
	},
	go : function(loc) {
		if(!loc) return;
		window.location.href = loc;
	},
	print : function(loc) {
		window.print();
	}
};

var evt = {
	add : function(tgt, typ, call) {
		if(tgt.addEventListener) {
			tgt.addEventListener(typ, call, false);
		} else if(tgt.attachEvent) {
			tgt["e"+typ+call] = call;
			tgt[typ+call] = function() { tgt["e"+typ+call]( window.event ); }
			tgt.attachEvent("on"+typ, tgt[typ+call]);
		} else {
			tgt["on"+typ] = tgt["e"+typ+call];
		}
	},
	del : function() {
	}
};

var dom = {
	$ : function(emt) {
		if (arguments.length > 1) {
			for (var i = 0, elements = [], length = arguments.length; i < length; i++)
				elements.push($(arguments[i]));
			return elements;
		}
		if (typeof(emt) == "string")
			emt = document.getElementById(emt);
		return emt;
	},
	$$ : function(par, tag, cnm) {
		var emt = par.getElementsByTagName(tag);
		if(arguments.length == 3) {
			var arr = new Array();
				for(var i = 0; i < emt.length; i++) {
					if(emt[i].className == cnm) {
						arr.push(emt[i]);
					}
				}
			return arr;
		}
		else if(arguments.length == 2) {
			return emt;
		}
	},
	rule : new Array("", "_on"),
	toggle : function(emt) {
		var src = emt.getAttribute("src");
		var typ = (src.indexOf("gif") != -1) ? ".jpg" : ".gif";
		var of = "", on = "";

		if(src.indexOf(this.rule[0]+typ) != -1) {
			of = this.rule[0]+typ;
			on = this.rule[1]+typ;
		} else {
			of = this.rule[1]+typ;
			on = this.rule[0]+typ;
		}
		emt.src = src.replace(of, on);
	},
	x : function(cmt, obj_id) {
		var emt = this.$(cmt);
		if(navigator.appName == "Microsoft Internet Explorer") {
			document.write(emt.text);
			emt.id = "";
		}
		if(obj_id)
			window[obj_id] = this.$(obj_id);
	}
};

evt.add(window, "load", function() {
	if(!dom.$("head") || !dom.$("content")) return;
	Layout();
	evt.add(window, "resize", function() { Layout() });
});

function Layout() {
	var doc_size = dom.$("head").offsetHeight + dom.$("content").offsetHeight + 58;
	var win_size = dom.$("container").offsetHeight;
	var doc_foot = dom.$("foot");
		if(doc_size > win_size)
			doc_foot.style.bottom = "auto";
		else
			doc_foot.style.bottom = "0";
	
	doc_foot.style.display = "block";
};

// Product Bigsize Image Viewer Function
function ViewIMG(emt) {
	if(!emt) return;
	var img_path = emt.getAttribute("src"),
		doc_loc = "pop_bigimg.php",
		new_img = new Image();

		img_path = img_path.replace("thumb","big");
		doc_loc = doc_loc+"?img_path="+img_path;
		new_img.setAttribute("src",img_path);
		new_img.doc_loc = doc_loc;

		evt.add(new_img, "load", function() {
			win.open(this.doc_loc, this.width+24, this.height+103);
			this.setAttribute("src","");
		});
};

dom.History = function(_start) {
	this.start_year = _start;
	this.count = this.start_year;
	this.parents = dom.$("history");
	this.row = dom.$$(this.parents,"div","history-row");
	for(var i = (this.row.length-1), h4, li, count, n; i >= 0; i--) {
		if(i == 0) { this.row[i].style.paddingTop = "25px" };
		h4 = dom.$$(this.row[i],"h4")[0];
		li = dom.$$(this.row[i],"li");
		count = 1;
		for(n = (li.length-1); n >= 0; n--) {
			li[n].style.backgroundImage = "url(\""+g4_path+"/images/about/history/"+this.count+"-"+count+".gif\")";
			count++;
		}
		this.row[i].className = "history-"+this.count;
		if(i%2 != 0) this.row[i].className = "history-"+this.count+" bg";
		this.count++;
	}
};

dom.Float = function(_width, _height, _x, _y, _swf) {
	this.swf = _swf;
	this.width = _width;
	this.height = _height;
	this.x = _x-295;
	this.y = _y;
	this.url = "_float.php?swf="+this.swf+"&width="+this.width+"&height="+this.height;

	this.box = dom.$("hidden-float");
	this.frm = dom.$("float-frm");
};

dom.Float.prototype = {
	view: function(){
		this.frm.setAttribute("src", this.url);
		with(this.box.style){
			display = "block"
			position = "absolute";
			top = this.y+"px";
			left = this.x+"px";
			width = this.width+"px";
			height = this.height+"px";
		}
		with(this.frm.style){
			width = this.width+"px";
			height = this.height+"px";
		}
	},
	hide: function(){
		this.box.style.display = "none";
	}
};