/**
 * @projectDescription NHN UI Javascript Framework - codename Jindo
 * @copyright NHN corp. <http://www.nhncorp.com>
 * @author AjaxUI Team
 * @version 0.2.9
 * 
 * Get some idea from prototype.js - http://prototype.conio.net
 * and Dean's work, Base.js - http://dean.edwards.name
 */

/** @id JINDO */
var JINDO = {
	/** @id JINDO.clone */
	clone  : function(source) {
		var obj = new source.constructor;
		for(var x in source) obj[x] = source[x];
		
		return obj;
	},
	/** @id JINDO.extend */
	extend : function(source, append) {
		var obj = source;
		for(var x in append) obj[x] = append[x];
		
		return obj;
	}
}

/** @id Class */
var Class = function(){
	var obj = function() {
		if (this.__init) this.__init.apply(this,arguments);
	}
	if (arguments[0]) obj.prototype = arguments[0];
	
	return obj;
}

/** @id Class.extend */
Class.extend = function(superClass) {
	var obj = Class();	
	obj.prototype = new superClass;
	for(var i=1; i < arguments.length; i++) {
		if (arguments[i]) JINDO.extend(obj.prototype, arguments[i]);
	}

	return obj;
}

/**
 * @projectDescription Jindo Ajax Extend
 * @copyright NHN corp. <http://www.nhncorp.com>
 * @author AjaxUI Team
 * @version 0.1
 * @since 0.2.9 <jindo.do.js>
 */

/** @id Ajax */
var Ajax = Class({
	_url : '',
	_request  : null,
	_response : null,
	_headers  : {},
	_crossDom : false, // cross domain?
	/** @id Ajax.__init */
	__init : function(url) {
		this.options = JINDO.extend({
			method   : 'GET',
			async    : true,
			interval : 0,
			params   : null,
			suspend  : false,
			preventCache     : false,
			ignoreWhiteSpace : false,
			contentType : 'application/x-www-form-urlencoded',
			swfPath : 'ajax.swf',
			onLoad  : function(req){},
			onError : function(){}
		}, arguments[1]||{});
		
		this._url = url;
		
		// check cross domain
		this._crossDom = (/(https?:\/\/)([a-z0-9_\-\.]{2,})(:\d+)?(\/|$)/i.test(url)) && (String(RegExp.$2) != document.domain);
		
		// get request
		this._request  = this._getXMLHTTP();
		
		// start to request
		if (!this.options.suspend) this.request();
	},
	/** @id Ajax._getXMLHTTP */
	_getXMLHTTP : function() {
		if (this._crossDom) {
			return new Ajax.swfHTTPRequest(this.options.swfPath);
		} else if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		} else if (ActiveXObject) {
			try { return new ActiveXObject('MSXML2.XMLHTTP'); }
			catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); }
			return null;
		}
	},
	/** @id Ajax._onReadyStateChange */
	_onReadyStateChange : function() {
		if (this._request.readyState == 4) {
			this.options.onLoad(this._request);
		}
	},
	/** @id Ajax._getData */
	_getData : function() {
		var a = [], p;		
		for (var x in this.options.params) {
			if (Object.prototype[x]) continue;			
			p = this.options.params[x];
			a.push(x+'='+encodeURIComponent(p.constructor==Function?p():p));
		}
		return a.length?a.join('&'):null;
	},
	/** @id Ajax.request */
	request : function() {
		var o = this.options; // options
		var m = o.method.toUpperCase(); // method		
		
		var req = this._request;
		req.onreadystatechange = this._onReadyStateChange.bind(this);
		req.open(o.method, this._url, o.async);
		req.setRequestHeader('Content-Type', o.contentType);
		for (var x in this._headers) {
			// Fix Firefox Ajax Bug - shgraph			
			if(this._headers.propertyIsEnumerable && typeof(this._headers[x]) != 'function') {
				req.setRequestHeader(x, this._headers[x]);
			}
		}
		req.send(this._getData());
		
		// repeat
		if(o.interval > 0) {
			this._timer = setTimeout(this.request.bind(this), o.interval*1000);
		}
	},
	/** @id Ajax.abort */
	abort : function() {
		this._request.abort();
	},
	/** @id Ajax.setRequestHeader */
	setRequestHeader : function(key, val) {
		this._headers[key] = val;
	},
	/** @id Ajax.getResponseHeader */
	getResponseHeader : function(key) {
		return this._request.getResponseHeader(key);
	}
});

/** @id Ajax.swfHTTPRequest */
Ajax.swfHTTPRequest = Class({
	_url     : '',
	_method  : 'GET',
	_headers : {},
	
	readyState  : 1,
	responseText : '',
	
	/** @id Ajax.swfHTTPRequest.onreadystatechange */
	onreadystatechange : function(){},
	/** @id Ajax.swfHTTPRequest.__init */
	__init : function(swf_path) {
		//this._tmpId = 'tmpSwf'+(new Date).getMilliseconds()+Math.floor(Math.random()*100000);
	},
	/** @id Ajax.swfHTTPRequest._onLoad */
	_onLoad : function(success, data) {
		if (success) {
			this.responseText = data;
			
			this.readyState = 4;
			this.onreadystatechange();
		}
	},
	/** @id Ajax.swfHTTPRequest.abort */
	abort : function() {
		// TODO : abort
	},
	/** @id Ajax.swfHTTPRequest.open */
	open : function(method, url) {
		this._method = method;
		this._url    = url;
	},
	/** @id Ajax.swfHTTPRequest.send */
	send : function(data) {
		var t   = this;
		var dat = {}, key, val, pos;
		var swf = window.document[Ajax._tmpId];
		data = (data || '').split('&');
		
		for(var i=0; i < data.length; i++) {
			pos = data[i].indexOf('=');
			key = data[i].substring(0,pos);
			val = data[i].substring(pos+1);
			
			dat[key] = val;
		}
		
		// create callback
		Ajax.swfHTTPRequest['callback_'+this._tmpId] = function() {
			t._onLoad.apply(t,arguments);
		};
		
		// request via flash
		swf.requestViaFlash(({
			'url'  : this._url,
			'type' : this._method,
			'data' : dat,
			'charset' : 'euc-kr',
			'callback'     : 'Ajax.swfHTTPRequest.callback_'+this._tmpId,
			'headers_json' : this._headers
		}).toJSON());
	},
	/** @id Ajax.swfHTTPRequest.setRequestHeader */
	setRequestHeader : function(key, val) {
		this._headers[key] = val;
	},
	/** @id Ajax.swfHTTPRequest.getResponseHeader */
	getResponseHeader : function(key) {
		return '';
	}
});

// write flash module
Ajax.initFlash = function(swf_path) {
	if(typeof swf_path == "undefined") swf_path = "./ajax.swf";
	Ajax._tmpId = 'tmpSwf'+(new Date).getMilliseconds()+Math.floor(Math.random()*100000);
	
	document.write('<div style="position:absolute;top:-1000px;left:-1000px;border:1px solid red"><object id="'+Ajax._tmpId+'" width="1" height="1" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"><param name="movie" value="'+swf_path+'"><param name = "allowScriptAccess" value = "always" /><embed name="'+Ajax._tmpId+'" src="'+swf_path+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="1" height="1" allowScriptAccess="always" swLiveConnect="true"></embed></object></div>');
}
/**
 * @projectDescription Jindo Array Extend
 * @copyright NHN corp. <http://www.nhncorp.com>
 * @author AjaxUI Team
 * @version 0.1
 * @since 0.2.9 <jindo.do.js>
 */


/** Extend Protoype of Array */
JINDO.extend(Array.prototype, {
	/** @id Array.prototype.has */
	has : function(needle) {
		return (this.indexOf(needle) > -1);
	},
	/** @id Array.prototype.load */
	load : function(obj) {
		for(var i=0; i<obj.length; i++) {
			this.push(obj[i]);
		}
		return this;
	},
	/** @id Array.prototype.each */
	each : function(iter) {
		for(var i=0; i<this.length; i++) {
			iter(this[i],i);
		}
	},
	/** @id Array.prototype.refuse */
	refuse : function(value) {
		return this.filter(function(v){ return v!=value });
	}
});

/** If This Browser Supports "forEach", Replace "each" */
if (Array.prototype.forEach) Array.prototype.each = Array.prototype.forEach;
/**
 * @projectDescription Jindo DOM Extend
 * @copyright NHN corp. <http://www.nhncorp.com>
 * @author AjaxUI Team
 * @version 0.1
 * @since 0.2.9 <jindo.do.js>
 */

/** @id Element */
var Element = {
	/** @id Element.show */
	show : function() {
		[].load(arguments).each(function(v){ $(v).style.display=''; });
	},
	/** @id Element.hide */
	hide : function() {
		[].load(arguments).each(function(v){ $(v).style.display='none'; });
	},
	/** @id Element.toggle */
	toggle : function() {
		[].load(arguments).each(function(v){ Element[Element.visible(v)?'hide':'show'](v) });
	},
	/** @id Element.visible */
	visible : function(oEl) {
		return ($(oEl).style.display!='none');
	},
	/** @id Element.realPos */
	realPos : function(oEl) {
		if (oEl.offsetParent) {
			var p = this.realPos(oEl.offsetParent);
			return { top: oEl.offsetTop+p.top, left: oEl.offsetLeft+p.left };
		} else {
			return { top: oEl.offsetTop, left:oEl.offsetLeft };
		}
	},
	/** @id Element.getCSS */
	getCSS : function(oEl, name) {
		return oEl.style[name];
	},
	/** @id Element.setCSS */
	setCSS : function(oEl, css) {
		JINDO.extend(oEl.style, css);
	},
	/** @id Element.hasClass */
	hasClass : function(oEl, className) {
		return $(oEl).className.split(/\s+/).has(className);
	},
	/** @id Element.addClass */
	addClass : function(oEl, className) {
		if (!this.hasClass(oEl, className)) ($(oEl).className+=' '+className).replace(/^\s+/,'');
	},
	/** @id Element.removeClass */
	removeClass : function(oEl, className) {
		$(oEl).className = $(oEl).className.replace(new RegExp('(^|\s+)'+className+'($|\s+)','g'),'');
	}
}
/**
 * @projectDescription Jindo Event Extend
 * @copyright NHN corp. <http://www.nhncorp.com>
 * @author AjaxUI Team
 * @version 0.1
 * @since 0.2.9 <jindo.do.js>
 */


/** @id Event */
var Event = {
	/** @id Event.register */
	register : function(oEl, sEvent, pFunc) {
		oEl = $(oEl);
		if (oEl.addEventListener) {
			oEl.addEventListener(sEvent, pFunc, false);
		} else if(oEl.attachEvent) {
			oEl.attachEvent('on'+sEvent, pFunc);
		}
	},
	/** @id Event.unregister */
	unregister : function(oEl, sEvent, pFunc) {
		oEl = $(oEl);
		if (oEl.removeEventListener) {
			oEl.removeEventListener(sEvent, pFunc, false);
		} else if(oEl.detachEvent) {
			oEl.detachEvent('on'+sEvent, pFunc);
		}
	},
	/** @id Event.ready */
 	ready : function(evt) {
		var e = evt || window.event;
		var b = document.body;
		
		/** Extend For Browser Event */
		JINDO.extend(e, {
			element : e.target || e.srcElement,
			page_x  : e.pageX || e.clientX+b.scrollLeft-b.clientLeft,
			page_y  : e.pageY || e.clientY+b.scrollTop-b.clientTop,
			key     : {
				alt   : e.altKey,
				ctrl  : e.ctrlKey,
				shift : e.shiftKey,
				up    : [38,104].has(e.keyCode),
				down  : [40,98].has(e.keyCode),
				left  : [37,100].has(e.keyCode),
				right : [39,102].has(e.keyCode),
				enter : (e.keyCode==13)
			},
			mouse   : {
				left   : (e.which&&e.button==0)||!!(e.button&1),
				middle : (e.which&&e.button==1)||!!(e.button&4),
				right  : (e.which&&e.button==2)||!!(e.button&2)
			},
			stop : function() { Event.stop(this); 	}
		});

		return e;
	},
	/** @id Event.stop */
	stop : function(e) {
		if (e.preventDefault) e.preventDefault();
		if (e.stopPropagation) e.stopPropagation();
		
		e.returnValue = false;
		e.cancelBubble = true;
		
		return false;
	}
}

/** @id Event.stopProc */
Event.stopProc = function(e) {
	Event.stop(e || window.event);
	return false;
}
/**
 * @projectDescription Jindo Base Extend
 * @copyright NHN corp. <http://www.nhncorp.com>
 * @author AjaxUI Team
 * @version 0.1
 * @since 0.2.9 <jindo.do.js>
 */

/** @id document.getElementByClassName */
document.getElementsByClassName = function(className, oParent) {
	var a = [].load(($(oParent) || document.body).getElementsByTagName('*'));
	var r = new RegExp('(^|\\s)'+className+'($|\\s)','gi');
	return a.filter(function(v){ return r.test(v.className); });
}


/** @id $ */
function $() {
	var ret = [];
	for(var i=0; i < arguments.length; i++) {
		if (typeof arguments[i] == 'string') {
			ret.push(document.getElementById(arguments[i]));
		} else {
			ret.push(arguments[i]);
		}
	}
	return ret[1]?ret:ret[0];
}

/** @id $A */
function $A(collection) {
	var ret = [];
	for(var i=0; i < collection.length; i++) ret.push(collection[i]);
	return ret; 
}

/** @id $C */
function $C(tag) {
	return document.createElement(tag);
}
/** @deprecated */
$c = $C;

/** @id $Agent */
function $Agent() {
	var isOpera = !!(window.opera);
	var nu = navigator.userAgent;
	var isIE = !isOpera && /MSIE/.test(nu), ie5=false, ie55=false, ie6=false, ie7=false, macIE=false;
	
	if (isIE) {
		/MSIE ([0-9\.]+)/.exec(nu);
		var ver = parseFloat(RegExp.$1);
		switch (ver) {
			case 5   : ie5 =true; break;
			case 5.5 : ie55=true; break;
			case 6   : ie6=true; break;
			case 7   : ie7=true; break;
			default  :
		}
	}
	
	return {
		IE     : isIE,
		IE5    : isIE && ie5,
		IE55   : isIE && ie55,
		IE6    : isIE && ie6,
		IE7    : isIE && ie7,
		macIE  : isIE && macIE,
		Gecko  : /Gecko/.test(nu),
		Opera  : isOpera,
		Safari : /WebKit/.test(nu),
		KHTML  : /KHTML/.test(nu)
	};
}

/**
 * legacy comportability
 */
(function(){
	var a = {
		push : function() {
			for(var i=0; i < arguments.length; i++) {
				this[this.length] = arguments[i];
			}
			return this.length;
		},
		pop  : function() {
			var el = this[Math.max(this.length-1,0)];
			if (this.length) this.length--;
			return el;
		},
		shift : function() {
			var el = this[0];
			for(var i=0; i < this.length-1; i++) {
				this[i] = this[i+1];
			}
			if (this.length) this.length--;
			return el;
		},
		unshift : function() {
			var a = new Array(arguments.length+this.length);
			for(var i=a.length-1; i > -1; i--) {
				 a[i] = (i < arguments.length)?arguments[i]:this[i-arguments.length];
			}
			for(var i=0; i < a.length; i++) {
				this[i] = a[i];	
			}
		},
		filter : function(func /*, obj*/) {
			var l = this.length, a=[], obj=arguments[1],v;
			for(var i=0; i < l; i++) {
				v = this[i];
				if (obj) { if (func.call(obj,v,i,this)) a.push(v); }
				else { if (func(v,i,this)) a.push(v); }
			}
			return a;
		},
		map : function(func /*, obj*/) {
			var l = this.length, a=new Array(l), obj=arguments[1];
			for (var i = 0; i < l; i++) {
				a[i] = obj?func.call(obj,this[i],i,this):func(this[i],i,this);
			}
			return a;
		},
		indexOf : function(el/*, from*/) {
			var from = arguments[1] || 0;
			if (from < 0) from += this.length;
			for(var i=from; i < this.length; i++) {
				if (this[i] == el) return i;
			}
			return -1;
		},
		lastIndexOf : function(el/*, from*/) {
			var from = (typeof arguments[1] == 'undefined')?this.length:arguments[1];
			if (from < 0) from += this.length;
			for(var i=from; i >= 0; i--) {
				if (this[i] == el) return i;
			}
			return -1;
		}
	};
	var f = {
		call : function(obj) {
			var r,a = [];
			( obj||{} ).prototype['__jindo_call__'] = this;
			
			switch (arguments.length) {
				case 1: return obj.__jindo_call__(); break;
				case 2: return obj.__jindo_call__(arguments[1]); break;
				case 3: return obj.__jindo_call__(arguments[1],arguments[2]); break;
				default:
					for(var i=1;i<arguments.length;i++) a.push('arguments['+i+']');
					return eval('obj.__jindo_call__('+a.join(',')+')');
			}
		},
		apply : function(obj,arg) {
			var r,a = []; arg = arg || [];
			( obj||{} ).prototype['__jindo_apply__'] = this;
			
			switch(arg.length) {
				case 0: return obj.__jindo_apply__();
				case 1: return obj.__jindo_apply__(arg[0]);
				case 2: return obj.__jindo_apply__(arg[0],arg[1]);
				default:
					for(var i=0;i<arg.length;i++) a.push('arg['+i+']');
					return eval('obj.__jindo_apply__('+a.join(',')+')');
			}
		}
	};
	for(var x in a) { if (typeof Array.prototype[x] == 'undefined') Array.prototype[x] = a[x] }
	for(var x in f) { if (typeof Function.prototype[x] == 'undefined') Function.prototype[x] = f[x] }
})();
/**
 * @projectDescription Jindo Function Extend
 * @copyright NHN corp. <http://www.nhncorp.com>
 * @author AjaxUI Team
 * @version 0.1
 * @since 0.2.9 <jindo.do.js>
 */

/** Extend Protoype of Function */
JINDO.extend(Function.prototype, {
	/** @id Function.prototype.bind */
	bind : function(obj) {
		var f=this, a=$A(arguments);a.shift();
		return function() {
			return f.apply(obj, a);
		}
	},
	/** @id Function.prototype.bindForEvent */
	bindForEvent : function(obj) {
		var f=this;
		return function(e) {
			return f.call(obj, Event.ready(e));
		}
	}
});
/**
 * @projectDescription Jindo Json Extend
 * @copyright NHN corp. <http://www.nhncorp.com>
 * @author AjaxUI Team
 * @version 0.1
 * @since 0.2.9 <jindo.do.js>
 */

/** @id Object.toJSON */
Object.prototype.toJSON = function() {
	var a = [], o;
	for (var x in this) {
		o = this[x];
		if (typeof Object.prototype[x] != 'undefined') continue;
		a.push(x.toJSON()+':'+(o.toJSON?o.toJSON():o));
	}
	return '{\n'+a.join(',\n')+'\n}';
};

/** @id Array.toJSON */
Array.prototype.toJSON = function() {
	var a = [];
	alert(this.length);
	for (var i=0; i < this.length; i++) {
		a.push(this[i].toJSON?this[i].toJSON():this[i]); 
	}
	return '['+a.join(',\n')+']';
	
};

/** @id String.toJSON */
String.prototype.toJSON   = function() { return '"'+this.replace('\\','\\\\').replace('"', '\\"')+'"'; };
/** @id Number.toJSON */
Number.prototype.toJSON   = function() { return this; }
/** @id Function.toJSON */
Function.prototype.toJSON = function() { return this.call(); }

/** @id JINDO.xml2json */
JINDO.xml2json = function(xml) {
	var obj = {}, que = [], depth = 0;	
	var parse_attr = function(obj, str) {
		str.replace(/([^=\s]+)\s*=\s*"([^"]*)"/g, function() {
			obj[arguments[1]] = arguments[2];
		});
	}
	
	xml = xml.replace(/<[\!\?][^>]*>/g,'').replace(/>\s+</g, '><'); // remove meanless code and white space
	xml = xml.replace(/<([^ >]+)(\s[^>]*)?><\/\1>/g, '<$1$2 />');
	xml = xml.replace(/<\/?([^ >]+)(\s[^>]*)?>(<\/\$1>|[^<>]*)/g, function() {
		if (arguments[0].substr(1,1) == '/') {
			// close tag
			depth--;
		} else if (que.length == 0) {
			que[depth] = obj;
			parse_attr(obj, arguments[2]);
		} else {
			var k  = arguments[1], o = {}, is_closed = false;
			
			is_closed = (arguments[2].substr(-1,1) == '/'); 
			if (arguments[3].length > 0 || is_closed) { // has text node
				o = arguments[3];
			}
			
			if (typeof que[depth][k] == 'undefined') {
				que[depth][k] = o;
			} else {				
				var v = que[depth][k];
				if (que[depth][k].constructor != Array) que[depth][k] = [v];
				que[depth][k].push(o);
			}
			
			// parse attributes
			parse_attr(o, arguments[2]);
			
			if (!is_closed) que[++depth] = o;	
		}
		
		return '';
	});
	
	return obj.toJSON();
}

Ku = {};
Ku.Selectbox2 = Class({
	_opHeight : 0,
	__init : function(id) {
		
		if($Agent().Opera==true) return false;
		var s = this._source  = $(id);
		this.options = JINDO.extend({
			height      : s.offsetHeight,
			width       : s.offsetWidth,
			fontSize    : 12, // px
			listSize    : 8,
			skinActive  : false,
			opacity     : 3,
			skinFormat  : 'http://images.hangame.co.kr/hangame/skidrush/renew/common/select_arw.gif', // left, right, up, down, bt
			mouseAct    : false,
			borderActive: true,
			borderColor : '#0E1114',
			borderHColor: '#FFFFFF', //hidden color
			borderTColor: false,
			borderRColor: false,
			borderBColor: false,
			borderLColor: false,
			optTxtColor : '#D2D2D2',
			optBgColor  : '#0E1114',
			optTxtHover : '#0E1114',
			optBgHover  : 'gray',
			optAlign    : 'left',
			useImage    : false,
			paddingList : '2px 5px 2px 5px'
		}, arguments[1]);


		var o = this.options;
		var e = this._element = $C('div');
		var c = this._container = e.appendChild($C('div')); // container
		var p = Element.realPos(this._source);
		
		// replace html element
		this._source.parentNode.insertBefore(e, s);
		this._source.style.display = 'none';

		// border
		this.borderact();

		Element.setCSS(e, {
			top    : p.top+'px',
			left   : p.left+'px',
			width  : o.width+'px',
			height : (o.height-2)+'px',
			color  : o.optTxtColor,
			background : o.optBgColor
		});

		Element.setCSS(c, {
			width    : o.width+'px',
			height   : (o.height-2)+'px',
			fontSize : o.fontSize+'px',
			overflow : 'auto',
			cursor   : 'pointer'
		});

		this.disable();

		// button layer
		var b = c.appendChild($c('div'));
		Element.setCSS(b, {
			height     : '100%',
			background : 'no-repeat url('+o.skinFormat.replace('%s', 'bt')+') 50% 50%',
			cssFloat   : 'right',
			styleFloat : 'right'
		});

		// text box
		this._txt_element = $C('div');
		this._source.parentNode.insertBefore(this._txt_element, s);
		with(this._txt_element) {
			if (this.options.useImage) {
				var img = $C('img');
				img.onload = function() {
					this.parentNode.style.height = o.height+'px';
					this.parentNode.style.background = 'url('+this.src+') '+o.optBgColor+' no-repeat 0px 0px';
					this.parentNode.removeChild(this);
				}
				appendChild(img).src = s.options[s.selectedIndex].text;
			} else {
				appendChild(document.createTextNode(s.options[s.selectedIndex].text));
				style.height = o.fontSize+'px';
			}
			style.overflow = 'hidden';
			style.marginTop = Math.max(Math.floor((o.height-offsetHeight)/2-1),0)+'px';
			style.marginLeft = style.marginTop;
		}
		c.appendChild(this._txt_element);
		c.appendChild($C('div')).style.clear = 'both';

		// re-margin
		var im = $C('img');
		im.onload = function(){b.style.width=im.width+'px'}
		im.src = o.skinFormat.replace('%s', 'bt');

		// options
		this._list_element = e.appendChild($C('div'));
		Element.setCSS(this._list_element, {
			position : 'absolute',
			zIndex   : 1000
		});
		
		var el = this._list_element.appendChild($C('div'));
		Element.setCSS(el, {
			position     : 'absolute',
			top          : '2px',			
			left         : '-1px',
			overflow     : 'auto'
//			overflowY    : 'auto'
		});
		if (o.borderActive) {
			el.style.borderTop    = '1px solid '+this.ColorR;
			el.style.borderRight  = '1px solid '+this.ColorR;
			el.style.borderBottom = '1px solid '+this.ColorB;
			el.style.borderLeft   = '1px solid '+this.ColorL;
		}

		el.onmousedown = this.onscrollbar.bindForEvent(this);
		if(o.mouseAct) el.onmouseover  = this.onmouseover.bind(this);
		this.paint();
		Element.hide(this._list_element);

		// event binding
		this._event_onmousedown = this.onmousedown.bindForEvent(this);
	},
	disable : function() {
		var s = this._source, o = this.options, e = this._element;
		var c = this._container;

		Element.setCSS(e, {
			filter  : (s.disabled)?'alpha(opacity='+o.opacity+'0)':'alpha(opacity=100)',
			opacity : (s.disabled)?'0.'+o.opacity:'1'
		});
		
		c.onmousedown = (s.disabled)?'':this.onmousedown.bindForEvent(this);
		c.onmouseup   = (s.disabled)?'':this.onmouseup.bind(this);
		if(o.mouseAct) c.onmouseover = (s.disabled)?'':this.onmouseover.bindForEvent(this);
		if(o.mouseAct) c.onmouseout  = (s.disabled)?'':this.onmouseout.bind(this);
	},
	borderact : function() {
		var s = this._source, o = this.options, e = this._element;

		this.ColorT = (o.borderTColor)?o.borderTColor:o.borderColor;
		this.ColorR = (o.borderRColor)?o.borderRColor:o.borderColor;
		this.ColorB = (o.borderBColor)?o.borderBColor:o.borderColor;
		this.ColorL = (o.borderLColor)?o.borderLColor:o.borderColor;

		if (o.borderActive) {
			e.style.borderTop    = (o.mouseAct)?'1px solid '+ o.borderHColor:'1px solid '+ this.ColorT;
			e.style.borderRight  = (o.mouseAct)?'1px solid '+ o.borderHColor:'1px solid '+ this.ColorR;
			e.style.borderBottom = (o.mouseAct)?'1px solid '+ o.borderHColor:'1px solid '+ this.ColorB;
			e.style.borderLeft   = (o.mouseAct)?'1px solid '+ o.borderHColor:'1px solid '+ this.ColorL;			
		}
	},	
	onmouseover : function(e) {
		var e = this._element;

		Element.setCSS(e, {
			borderTop    : '1px solid '+ this.ColorT,
			borderRight  : '1px solid '+ this.ColorR,		
			borderBottom : '1px solid '+ this.ColorB,
			borderLeft   : '1px solid '+ this.ColorL
		});
	},
	onmouseout : function(e) {
		var e = this._element;

		Element.setCSS(e, {
			border    : '1px #FFFFFF solid'
		});
	},
	onmousedown : function(e) {
		if (!Element.visible(this._list_element)) {
			this.paint();
			if (this._list_element.firstChild.offsetWidth < this._element.offsetWidth) {
				if($Agent().IE) this._list_element.firstChild.style.width = (this._element.clientWidth+2)+'px';
					else this._list_element.firstChild.style.width = this._element.clientWidth+'px';
				//this._list_element.style.left  = '7px';
			};
			Element.show(this._list_element);
			
			var op = this._list_element.firstChild.firstChild; 
			if (this._list_element.firstChild.offsetHeight-2 > op.offsetHeight*this.options.listSize) {
				this._list_element.firstChild.style.height = (op.offsetHeight*this.options.listSize)+"px";
			}
		} else {
			Element.hide(this._list_element);
			Event.unregister(document.body, 'mousedown', this._event_onmousedown);
		}
	},
	onmouseup : function() {
		if (Element.visible(this._list_element)) {
			Event.register(document.body, 'mousedown', this._event_onmousedown);
		}
	},
	onselect : function(e) {
		var el=e.element, o=this.options;
		var idx = o.useImage?el.parentNode._index:el._index;

		this.setIndex(idx);

		this.onmousedown();
		this.borderact();
		if (this._source.onchange) this._source.onchange();
	},
	onover : function(e) {
		var el=e.element, o=this.options;

		if (o.useImage) {
			var c=$A(el.parentNode.parentNode.childNodes), idx=el.parentNode._index;
		} else {
			var c=$A(el.parentNode.childNodes), idx=el._index;
		}

		c.map(function(v,i) {
			if (v.className != 'nhn_ajaxui_gony_selectbox_option') return v;
			if (o.useImage) {
				v.firstChild.style.backgroundColor = 'transparent'; // fix IE bug
			} else {
				
				v.style.color = (i==idx)?o.optTxtHover:o.optTxtColor;
			}
			v.style.backgroundColor = (i==idx)?o.optBgHover:o.optBgColor;

			return v;
		});
	},
	onscrollbar : function(e) {
		e.stop();
	},
	paint : function() {
		var o=this.options,s=this._source,op;
		this._list_element.firstChild.innerHTML = '';
		this._list_element.firstChild.style.width = '';
		this._list_element.firstChild.style.height = '';
		this._maxImageWidth = 0;
		for(var i=0; i < s.options.length; i++) {
			op = this._makeOption(s.options[i].value, s.options[i].text);
			op._index  = i;

			Element.setCSS(op, {
				padding  : this.options.paddingList,
				cursor   : 'pointer',
				fontSize : o.fontSize+'px',
				color    : (i==this._source.selectedIndex)?o.optTxtHover:o.optTxtColor,
				background : (i==this._source.selectedIndex)?o.optBgHover:o.optBgColor
			});
			this._list_element.firstChild.appendChild(op);
		}
		
		// re-index
		this.setIndex(s.selectedIndex);
	},
	setValue : function(val) {
		this._source.value = val;
		this.setIndex(this._source.selectedIndex);
	},
	setIndex : function(idx) {
		var s = this._source, o = this.options, e = this._txt_element;
		s.selectedIndex = idx;
		if (o.useImage) {
			e.style.backgroundImage = 'url("'+s.options[s.selectedIndex].text+'")';
		} else {
			e.firstChild.nodeValue = s.options[s.selectedIndex].text;
		}
		Element.setCSS(e, {
			fontSize : o.fontSize+'px',
			color    : o.optTxtColor
		});
	},
	_makeOption : function(value, text) {
		var o = $C('div'), t = this;
		o.className = 'nhn_ajaxui_gony_selectbox_option';
		o._value = value;

		// support image option - 2006. 11. 14
		if (this.options.useImage) {
			var img = $C('IMG');
			o.appendChild(img).src = text;

			Event.register(img, 'mousedown', this.onselect.bindForEvent(this));
			Event.register(img, 'mouseover', this.onover.bindForEvent(this));
		} else {
			o.appendChild(document.createTextNode(text));
			o.style.textAlign = this.options.optAlign;
			Event.register(o, 'mousedown', this.onselect.bindForEvent(this));
			Event.register(o, 'mouseover', this.onover.bindForEvent(this));
		}

		return o;
	}
});

Ku.Radiobox = Class({
	__init : function(name) {
		var s = this._sources = $A(document.getElementsByName(name));
		this.options = JINDO.extend({
			onChange   : function(v,i){},
			skinFormat : 'http://static.naver.com/search/common/ico_radio_%s.gif' // on, off
		}, arguments[1]);

		// for image cache
		var o = this.options;
		$c('img').src = o.onImg = o.skinFormat.replace('%s', 'on');
		$c('img').src = o.offImg = o.skinFormat.replace('%s', 'off');

		// image elemnts
		var e = this._elements = [];
		for(var i=0; i < s.length; i++) {
			e.push($C('img'));
			e[i].onclick = this.onclick.bind(this,i);
		}
		this.paint();
		
		// replace html elements
		s.each(function(v,i) {
			v.parentNode.insertBefore(e[i],v);
			e[i].style.cursor = "pointer";
			Element.hide(v);
		});
	},
	onclick : function(idx) {
		var s = this._sources[idx];
		var c = s.checked;
		s.checked = true;

		this.paint();
		if (s.onclick) s.onclick();
		if (c != s.checked) this.options.onChange(s.value,idx);
	},
	setIndex : function(i) {
		this._sources[i].checked = true;
		this.paint();
	},
	setValue : function(val) {
		this._sources.each(function(v){ if(v.value == val)v.checked=true });
		this.paint();
	},
	getValue : function() {
		var val;
		this._sources.each(function(v){ if(v.checked)val=v.value });
		return val;
	},
	getIndex : function() {
		var idx;
		this._sources.each(function(v,i){ if(v.checked)idx=i });
		return idx;
	},
	paint : function() {

		var t = this;
		this._elements.each(function(v,i) {
			v.src = t._sources[i].checked?t.options.onImg:t.options.offImg;
		});
	}	
});

