/**
 * -----------------------------------------------------------------------------
 * aqa systems javascript library
 *
 * Copyright (c) 2007- Yohichiro Kato, All rights reserved.
 *
 * This program is protected by the Copyright Law.
 * No one can use, modify, and redistribute this program 
 * without the copyright person's permission. 
 * -----------------------------------------------------------------------------
 */

/**
 * -----------------------------------------------------------------------------
 * Base script
 * -----------------------------------------------------------------------------
 * @version beta version 3.20101104
 * @require none
 * @globals
 * _aqa_ : library
 * _doc_ : window.document object
 * -----------------------------------------------------------------------------
 */

if((typeof(_aqa_) != 'undefined' || typeof(_doc_) != 'undefined')){
	alert("Competition!\nsee aqabase.txt");
}

/**
 * -----------------------------------------------------------------------------
 * initialize & basic functions
 */

var _doc_ = document;
var _aqa_ = { 

	/**
	 * ------------------------------
	 * settings
	 */

	// core
	library_name : 'AqaSystems',
	library_version : 3,
	debug : false,
	cash : {
		addEvent  : [],
		recursive : [],
		unique    : null
	},
	intervals : {},
	
	// mouse status
	mouse_x : 0,
	mouse_y : 0,
	click_x : 0,
	click_y : 0,
	click_target : null,

	/**
	 * ------------------------------
	 * methods : for system core
	 */

	extend : function (o, p, _all){
		for(var i in p) if(p.hasOwnProperty(i) || _all) o[i] = p[i];
		return o;
	},

	delegate : function (o, method){
		return function (){
			return method.apply(o, arguments);
		}
	},

	// tips
	K : function (){return this;},
	E : function (){},

	// not generic
	not_generic_method : function (o){
		var a = ['toString', 'toLocaleString', 'valueOf'];
		switch (o.constructor) {
			case Array:
			case Boolean:
			case String:
				return a;
			case Number:
				return a.concat(['toFixed', 'toExponential', 'toPrecision']);
			case Date:
				return a.concat([
					'toDateString', 'toTimeString', 'toLocaleDateString', 'toLocaleTimeString',
					'getTime', 'getFullYear', 'getUTCFullYear', 'getMonth', 'getUTCMonth', 'getDate',
					'getUTCDate', 'getDay', 'getUTCDay', 'getHours', 'getUTCHours', 'getMinutes',
					'getUTCMinutes', 'getSeconds', 'getUTCSeconds', 'getMilliseconds',
					'getUTCMilliseconds', 'getTimezoneOffset', 'setTime', 'setMilliseconds',
					'setUTCMilliseconds', 'setSeconds', 'setUTCSeconds', 'setMinutes',
					'setUTCMinutes', 'setHours', 'setUTCHours', 'setDate', 'setUTCDate', 'setMonth',
					'setUTCMonth', 'setFullYear', 'setUTCFullYear', 'toUTCString'
				]);
			case RegExp:
				return a.concat(['exec', 'test']);
			case Function:
				return a.concat(['apply', 'call']);
		}
		return [];
	}
}

/**
 * -----------------------------------------------------------------------------
 * browser status
 */

_aqa_.extend(_aqa_, 
	(function (){

		var ua = navigator.userAgent.toLowerCase();
		var os = ua.match(/mac|win|linux/i)[0] || '';
		var brs = '', ver = '', ful = '';
		var fam = '';

		// get browser ver
		if(ua.match(/version\/([\.0-9]+)/) && RegExp.$1){
			ver = RegExp.$1;
		}else if(ua.match(/applewebkit\/4([\.0-9]+)/) && RegExp.$1){
			ver = '2';
		}else if(ua.match(/applewebkit\/([\.0-9]+)/) && RegExp.$1){
			ver = '1';
		}

		// get browser name etc
		if(ua.match(/(opera|chrome|sleipnir|lunascape|netscape6)[\/\s]([\.0-9]+)/) && RegExp.$1){
			// camouflaged MSIE : Opera, Sleipnir, Lunascape
			// camouflaged Safari : Chrome
		}else if(ua.match(/(msie|firefox|konqueror|netscape|safari)[\/\s]([\.0-9]+)/) && RegExp.$1){
			if(RegExp.$1 != 'msie') fam = 'gecko';
		}else if(ua.match(/(gecko)/) && RegExp.$1){
			// Gecko Family : Netscape, FireFox
			// Like Gecko : Chrome, Safari(AppleWebKit), Shiira, Konqueror, NetFront
			fam = 'gecko';
		}else if(ua.match(/(mozilla)\/([\.0-9]+)/) && RegExp.$1){
			// absolutely 'unknown'
		}else{
			// unknown
		}

		// decide browser 
		brs = ('' + RegExp.$1);
		ful = ('' + RegExp.$2);
		if(brs == 'safari' || (brs == 'opera' && ver)){
			ver = ver;
		}else if(brs == 'firefox' && ful.search(1.5) == 0){
			ver = '1.5';
		}else if(brs == 'msie' && ful.search(5.5) == 0){
			ver = '5.5';
		}else{
			ver = ful.split('.')[0];
		}

		var f = location.href.split("?")[0].split("/");
		f = f[f.length - 1].split('#')[0];
		
		var s = location.href.replace(':/' + '/', '').split('/');
		if(s.length > 2) s = s[s.length - 2] + '_' + f.split('.')[0];
		else s = '_' + f.split('.')[0];

		return {
			os_name : os,
			browser_useragent : ua,
			browser_name : brs,
			browser_version : ver,
			browser_app_version : ful,
			referrer : _doc_.referrer,
			referrer : _doc_.referrer,
			screen_width : screen.width,
			screen_height : screen.height,
			screen_color : screen.colorDepth,
			isWindows : (os == 'win'),
			isLinux : (os == 'linux'),
			isMac : (os == 'mac'),
			isMSIE : (brs == 'msie'),
			isFirefox : (brs == 'firefox'),
			isChrome : (brs == 'chrome'),
			isSafari : (brs == 'safari'),
			isOpera : (brs == 'opera'),
			isGecko : (fam == 'gecko'),
			cookie : navigator.cookieEnabled,
			java : navigator.javaEnabled(),
			file_name : f,
			page_id : s,
			position_name : ''
		}
	})()
);

/**
 * -----------------------------------------------------------------------------
 * basic functions
 */

_aqa_.extend(_aqa_, {

	/**
	 * ------------------------------
	 * for system core
	 */

	// clone (safari, chrome : not prototype chain if o is Function)
	clone : function (o){
		if(o != null && typeof(o) != undefined){
			var m = this.not_generic_method(o);
			var o = this.K.apply(o);
			var f = function (){};
			f.prototype = o;
			c = new f();
			for(var i = 0, l = m.length; l > i; i++){
				if(!o[m[i]]) o[m[i]] = this.delegate(o, m[i]);
			}
		}
		return c || o;
	},

	// inherit
	inherit : function (parent, _override){
		// add property on parent
		if(typeof(parent.childNodes) == 'undefined'){
			parent.childNodes = [];
		}
		if(typeof(parent.origin) == 'undefined'){
			parent.origin = parent;
		}
		// create child
		child = this.clone(parent);
		// add property on child
		child.parent = parent;
		child.childNodes = [];
		// override
		if(_override){
			this.extend(child, _override);
		}
		// register child on parent
		if(parent.childNodes instanceof Array){
			parent.childNodes[parent.childNodes.length] = child;
		}
		// child call back
		if(typeof(child.initialize) == 'function'){
			child.initialize.apply(child, this.A(arguments, 2));
		}
		// parent call back
		if(typeof(parent.onInherit) == 'function'){
			parent.onInherit(child);
		}
		return child;
	},

	// transcript
	transcript : function (o, _all, _recursive, _depth){
		_depth = _depth || /* default depth */ 3;
		if(o == null || typeof(o) == undefined) return o;
		if(typeof(o) == 'function') eval('var r = ' + o.toString());
		else if(typeof(o) == 'object') var r = new o.constructor();
		else r = this.K.apply(o);
		for(var i in r) delete r[i];
		for(var i in o){
			if(o.hasOwnProperty(i) || _all){
				if(!_recursive || (typeof(o) != 'function' && typeof(o) != 'object')){
				 r[i] = o[i];
				}else if(_recursive && _depth >= 1){
					r[i] = this.transcript(o[i], _all, true, _depth - 1);
				}else if(_recursive){
					r[i] = null;
				}
			}
		}
		return r;
	},

	// each
	each : function (o, fn /* , arg1, arg2, arg3 ... */){
		var a = this.A(arguments, 2), idx = this.cash.unique.createId(), ret;
		this.cash.recursive[idx] = [];
		ret = this._recursive(o, 1, fn, a, idx, 0);
		delete(this.cash.recursive[idx]);
		return ret;
	},

	// recursive
	recursive : function (o, max_depth, fn /* , arg1, arg2, arg3 ... */){
		var a = this_.A(arguments, 2), idx = this.cash.unique.createId(), ret;
		max_depth = max_depth || 1;
		this.cash.recursive[idx] = [];
		ret = this._recursive(o, max_depth, fn, a, idx, 0);
		delete(this.cash.recursive[idx]);
		return ret;
	},
	_recursive : function (o, max_depth, fn, a, idx, dpt){
		var c = this.cash.recursive[idx], ret = null;
		if(!this.isElement(o) && this.isObject(o)){
			if(dpt < max_depth && !this.searchValue(c, o, true, true).result){
				c[c.length] = o;
				ret = [];
				for(var i in o) ret[i] = this._recursive(o[i], max_depth, fn, a, idx, ++dpt);
			}
		}else ret = fn.apply(o, a);
		return ret;
	},

	/**
	 * ------------------------------
	 * methods : event
	 */

	addEvent : function (ele, evt, cbfn, _capt){
		_capt = _capt || false;

		// set o and f for cut scope chain (avoid memory leak ... test!!!)
		var o = [this.$(ele)], f = [cbfn], r = null, i = 0;// i ... need?
		ele = cbfn = null;

		// prepare function
		var c = function (){
			var evt = arguments[0];
			if(evt && _aqa_.isElement(evt.srcElement)){
				var p = _aqa_.getPosition(evt.target = evt.srcElement); // see getPosition
				evt.width  = evt.clientX;
				evt.height = evt.clientY;
				evt.layerX = evt.offsetX;
				evt.layerY = evt.offsetY;
				evt.pageX  = p.x;
				evt.pageY  = p.y;
			}
			if(f[i]) return f[i].apply(window, arguments);
			else return arguments.callee;
		};

		// add event
		if(o[i].addEventListener) o[i].addEventListener(evt, c, _capt);
		else if(o[i].attachEvent) o[i].attachEvent('on' + evt, c);
		else{
			var csh = this.cash.addEvent[evt] || (this.cash.addEvent[evt] = []);
			var ofn = typeof(o[i]['on' + evt]) == 'function' ? o[i]['on' + evt] : false;
			csh[r = csh.length] = c;
			o[i]['on' + evt] = function (){
				if(ofn) ofn.apply(window, arguments);
				for(var n in csh) if(csh.hasOwnProperty(n)) csh[n].apply(window, arguments);
			}
		}

		return (r === null) ? c : r; // see removeEvent
	},

	removeEvent : function (ele, evt, fn, _capt){
		if(ele.removeEventListener) ele.removeEventListener(evt, fn, _capt);
		else if(ele.detachEvent) ele.detachEvent('on' + evt, fn);
		else{
			if(this.cash.addEvent[evt] && this.isNumber(fn) && fn >= 0){
				delete(this.cash.addEvent[evt][fn]);
			}
			if(this.cash.addEvent[evt].length == 0){
				ele['on' + evt] = this.E;
				delete(this.cash.addEvent[evt]);
			}
		}
	},

	setLoad : function (fn){
		this.addEvent(window, 'load', fn);
	},

	setUnload : function (fn){
		this.addEvent(window, 'unload', fn);
	},

	// cbf(nam, old_value) this == obj
	watch : function (obj, nam, cbf, _tm){
		_tm = _tm || 100;
		var f = function (o, n){
			var v = o[n];
			var t = setTimeout(
				function (){
					clearTimeout(t);
					if(v == o[n] || cbf.apply(o, [n, v])){
						f(o, n);
					}
				},
				_tm
			);
		}
		f(obj, nam);
	},

	/**
	 * ------------------------------
	 * methods : Array (& Object)
	 */

	// A : like toArray, Array.slice,
	A : function (o, _start, _end){
		var i = _start || 0, a = [];
		try{
			if(typeof(o.length) == 'number'){
				if(!!_end && o.length > _end){
					return Array.prototype.slice.apply(o, [i, _end]);
				}else return Array.prototype.slice.apply(o, [i]);
			}
		}catch(e){/* nodelist if ie */}
		while(typeof(o[i]) != 'undefined' && (!_end || i < _end)){
			a[i] = o[i];
			i++;
		}
		return a;
	},

	// W : like array_values [php], array_keys [php]
	W : function(o, _hasOwn){
		var key = [], val = [], cnt = 0;
		if(typeof(o) == 'object') for (var i in o) if(!_hasOwn || o.hasOwnProperty(i)){
			val[cnt] = o[(key[cnt] = i)];
			cnt++;
		}
		return {result : (cnt && true || false), gain : {keys : key, values : val}};
	},

	// getValue : for multidimensional array / object tree
	// ex) getValue(o, key1, key2, ...);
	// ex) getValue(o, [key1, key2, ...]);
	getValue : function (o){
		/**
		 * ref)
		 * var check = o && o.key1 && o.key1.key2 && o.key1.key2.key3;
		 * if(typeof(check) == 'undefined') return false;
		 * else return check;
		 */
		var a = this.A(arguments, 1), key = '';
		if(a[0] instanceof Array) a = a[0];
		while(a.length){
			key = a.shift();
			if(typeof(o) == 'object' && typeof(o[key]) != 'undefined'){
				o = o[key];
			}else{
				return {result : false, gain : false};
			}
		}
		return {result : true, gain : o};
	},

	// searchValue : like in_array [php], array_search [php]
	searchValue : function (o, val, _strict, _hasOwn){
		for(var i in o){
			if(
				(o[i] === val || (!_strict && o[i] == val)) &&
				(!_hasOwn || (o.hasOwnProperty && o.hasOwnProperty(i)))
			){
				return {result : true, gain : i};
			}
		}
		if(o instanceof Array) for(var i = 0; o.length > i; i++){
			if(o[i] === val || (!_strict && o[i] == val)){
				return {result : true, gain : i};
			}
		}
		return {result : false, gain : false};
	},

	// fieldSearch : ! only multidimensional array. near SELECT(sql)
	// ex) fieldSearch(fld, {key1 : val1, ... /* ! only has own */}, _strict);
	fieldSearch : function (fld, where, _strict){
		var val = '', r = {result:false, gain:{keys : [], extract:[]}};
		for(var row = 0; fld.length > row; row++){
			for(var key in where){
				if(where.hasOwnProperty(key)){
					val = where[key];
					ret = this.getValue(fld[row], key);
					if(ret.result && (ret.gain === val || (!_strict && ret.gain == val))){
						r.result = true;
						r.gain.keys.push(row);
						r.gain.extract.push(fld[row]);
					}
				}
			}
		}
		return r;
	},

	/**
	 * ------------------------------
	 * methods : Math
	 */

	rnd : function (a, b){
		return Math.floor(Math.random() * (Math.abs(a - b) + 1)) + Math.min(a, b);
	},

	max : function (){
		var a = this.A(arguments), max = false, check = 0;
		if(a.length == 1 && a[0] instanceof Array) a = a[0];
		for(var i = 0, l = a.length; l > i; i++){
			check = Math.max(a[i], max);
			if(!isNaN(check)) max = check;
		}
		return max;
	},

	min : function (){
		var a = this.A(arguments), min = false, check = 0;
		if(a.length == 1 && a[0] instanceof Array) a = a[0];
		for(var i = 0, l = a.length; l > i; i++){
			check = Math.min(a[i], min);
			if(!isNaN(check)) min = check;
		}
		return min;
	},

	mod : function (a, b){
		var aa = Math.abs(a);
		var ab = Math.abs(b);
		var c = Math.floor(aa / ab);
		c = Math.floor(aa - c * ab);
		return (a / aa) * (b / ab) * c;
	},

	/**
	 * ------------------------------
	 * methods : String
	 */

	strCount : function (str, s, f){
		var ary = str.match(new RegExp(s, 'g' + (f ? 'i' : '')));
		if(ary) return ary.length; else return 0;
	},

	replaceAll : function (str, s1, s2, f){
		return str.replace(new RegExp(s1, 'g' + (f ? 'i' : '')), s2);
	},

	replaceAllSafe : function (str, s1, s2){
		return str.split(s1).join(s2);
	},

	reverse : function (str){
		var t = "";
		for(var i = str.length; i > 0; i--) t = t + str.substring(i - 1, i);
		return t;
	},

	extractNumber : function (str){
		return str.match(/\-?[0-9]*\.?[0-9]+/g);
	},

	ver2numeric : function (i){
		var v = i.split('.');
		return parseFloat(v.shift() + '.' + v.join(''));
	},

	trim : function (s){
		return this.rTrim(this.lTrim(s.toString()));
	},

	lTrim : function (s){
		var l, f;
		while(1){
			l = s.length;
			f = s.charCodeAt(0);
			if(f != 32 && f != 9 && f != 13 && f != 10) return s;
			s = s.substring(1, l);
		}
	},

	rTrim : function (s){
		var l, f;
		while(1){
			l = s.length;
			f = s.charCodeAt(l - 1);
			if(f != 32 && f != 9 && f != 13 && f != 10) return s;
			s = s.substring(0, l - 1);
		}
	},

	format : function (fmt, num){
		// prepare - string
		fmt = fmt.split('.');
		if(!fmt[1]) fmt[1] = '';
		if(num < 0) fmt[0] = fmt[0].replace(fmt[0].match(/[#0]/), '-');
		fmt[0] = fmt[0].reverse();
		// prepare - number
		var i = Math.pow(10, fmt[1].replaceAll('0', '#').count('#'));
		num = ('' + (Math.round(Math.abs(num) * i) / i)).split('.');
		if(!num[1]) num[1] = '';
		num[0] = num[0].reverse();
		// implementation
		for(var j = 0; j < num.length; j++){
			num[j] = num[j].replaceAll('0', '.');
			for(var i = 0; num[j].length > i; i++){
				if(!fmt[j].match(/([#0])/)) return 'Too Long!';
				fmt[j] = fmt[j].replace(RegExp.$1, num[j].substring(i, i + 1));
			}
			fmt[j] = fmt[j].replaceAll('.', '0');
		}
		return (
			(fmt[0].reverse() + (fmt[1] ? '.' + fmt[1] : ''))
			.replaceAll('#,', '')
			.replaceAll('#', '')
			.replace('-,', '-')
			.replace(',-', '-'));
	},

	toDecimal : function (val, rdx){
		if(this.isNumber(val)) val = val.toString();
		if(!this.isString(val) || !this.isNumber(rdx)) return false;
		if(rdx < 2 || rdx > 36) return false;
		var ret = 0, sgn = 1;
		val = this.trim(val.toLowerCase()).split('.');
		if(!this.isArray(val)) val = [val];
		if(val[0].indexOf('-', 0) == 0) sgn = -1;
		if(val[0].length > 0){
			ret += this.toDecimal_rootine(val[0], rdx);
		}
		if(val[1] && val[1].length > 0){
			ret += this.toDecimal_rootine(val[1], rdx, true);
		}
		return ret * sgn;
	},

	toDecimal_rootine : function (val, rdx, upn){
		var len = val.length, ret = 0, tmp = 0;
		var moj = rdx.toString(rdx).charCodeAt(0);
		var dgt = (upn ? 1 / rdx : 1);
		for(
			var i = (upn ? 0 : len - 1);
			i > -1 && i < len;
			i += (upn ? 1 : 0 - 1)
		){
			tmp = parseInt(val.charCodeAt(i));
			if(tmp >= 97) tmp -= 87; else tmp -= 48;
			if(tmp >= 0 && tmp < rdx){
				ret += tmp * dgt;
				dgt = (upn ? dgt / rdx : dgt * rdx);
			}
		}
		return ret;
	},

	/**
	 * ------------------------------
	 * methods : Date
	 */

	checkDate : function (y, m, d){
		if(!y || !m || !d) return false;
		var o = new Date(y, m - 1, d);
		if(y == o.getFullYear() && m == (o.getMonth() + 1) && d == o.getDate()){
			return true;
		}else{
			return false;
		}
	},

	/**
	 * ------------------------------
	 * methods : Value & Check
	 */

	isAvail : function (){
		var a = this.A(arguments), c = '';
		for(var i = 0; a.length > i; i++){
			c = a[i];
			if(!(c !== false && c !== null && c !== void(0) && !isNaN(c))){
				return false;
			}
		}
		return true;
	},

	getAvail : function (){
		var a = this.A(arguments), c = '';
		for(var i = 0; a.length > i; i++){
			c = a[i];
			if(c !== false && c !== null && c !== void(0) && !isNaN(c)){
				return c;
			}
		}
		return false;
	},

	isElement : function(o) {
		if(o && o.nodeType === 1){
			try{
				var c = o.cloneNode(false);
			}catch(e){return false;}
			try{
				if(c == o) return false;
				else c.nodeType = 9;
				if(c.nodeType === 1) return true;
			}catch(e){return true;}
		}
		return false;
	},

	isArray : function(o) {
		return o instanceof Array;
	},

	isHash : function(o) {
		return o instanceof Hash;
	},

	isFunction : function(o) {
		return typeof(o) == 'function';
	},

	isString : function(o) {
		return typeof(o) == 'string';
	},

	isObject : function(o) {
		return typeof(o) == 'object';
	},

	isNumber : function(o) {
		return typeof(o) == 'number';
	},

	isAvailNumber : function(o) {
		try{
			return (("" + o).match(/^[\-]?[0-9]*[\.]?[0-9]*$/) && o != "-")
		}catch(e){
			return false;
		}
	},

	isDigit : function(o) {
		try{
			return !!(("" + o).match(/^[0-9]+$/))
		}catch(e){
			return false;
		}
	},

	isDefined : function(o) {
		return typeof(o) != 'undefined';
	},

	/**
	 * ------------------------------
	 * methods : DOM tips
	 */

	// $all : [element].getElementByTagName('*')
	$all : function (o, _update){
		return this.$tag(o, '*', _update);
	},

	// $tag : [element].getElementByTagName([tag name])
	// ex) $tag(document, [tag name]) == $$([tag name])
	$tag : function (o, n, _update){
		if(!this.cash.$tag){
			this.cash.$tag = {};
		}
		var c = this.cash.$tag;
		o = this.$(o);
		if(!_update && c[n] && c[n].parent == o){
			return c[n].cash;
		}
		var r = this.A(o.getElementsByTagName(n));
		c[n] = {parent : o, cash : r};
		return r;
	},

	// $ : like prototype.js
	$ : function (e){
		if(arguments.length > 1) return this.$(this.A(arguments));
		if(typeof(e) == 'string') return _doc_.getElementById(e);
		if(this.isElement(e) || e == window || e == document) return e;
		if(e instanceof Array){
			var r = [];
			for(var t = 0, m = e.length; m > t; t++) r.push(this.$(e[t]));
			return r;
		}
		return false;
	},

	// $$ : like prototype.js
	$$ : function (_update){
		var a = this.A(arguments);
		var e = [], r = [], eles = [_doc_], s;
		if(typeof(a[0]) == 'boolean'){
			a.shift();
		}else{
			_update = false;
		}
		for(var ai = 0, al = a.length; al > ai; ai++){
			s = a[ai].split(' ');
			eles = [_doc_];
			for(var si = 0, sl = s.length; sl > si; si++){
				e = s[si].split('.');
				tag = e[0] || false;
				cls = e[1] || false;
				e = tag.split('#');
				tag = e[0] || false;
				id  = e[1] || false;
				if(id){
					var t = this.$(id);
					t = t && (tag == '' || t.tagName.toLowerCase() == tag.toLowerCase()) ? [t] : [];
				}else if(tag){
					var t = [];
					for(var i = 0, l = eles.length; l > i; i++){
						t = t.concat(this.$tag(eles[i], tag, _update));
					}
				}else{
					var t = [];
					for(var i = 0, l = eles.length; l > i; i++){
						t = t.concat(this.$all(eles[i], _update));
					}
				}
				if(cls){
					var ok = [];
					for(var i = 0, l = t.length; l > i; i++){
						if(this.searchValue(t[i].className.split(' '), cls).result){
							ok.push(t[i]);
						}
					}
				}else{
					var ok = t;
				}
				eles = ok;
			}
			r = r.concat(eles);
		}
		return r;
	},

	// $E : create element
	$E : function (type, _opt){
		var e = _doc_.createElement(type);
		if(_opt){
			if(_opt.attribute) this.extend(e, _opt.attribute);
			if(_opt.style) this.extend(e.style, _opt.style);
			if(_opt.container) _opt.container.appendChild(e);
		}
		return e;
	},

	$swap : function (a, b){
		a = this.$(a);
		b = this.$(b);
		var pa = a.parentNode;
		var pb = b.parentNode;
		var c  = document.createElement('span');
		pa.replaceChild(c, a);
		pb.replaceChild(a, b);
		pa.replaceChild(b, c);
	},

	$change : function (a, b){
		b = this.$(b);
		if(!b.parentNode) return false;
		this.insertBefore(b, a);
		b.parentNode.removeChild(b);
	},

	$clone : function (e, s){
		// warning : disable td when insert innerHTML on tr
		e = this.$(e);
		var t = e.innerHTML;
		var c = e.cloneNode(false);
		if(typeof(s) == 'string' && s != ''){
			t = t.replace(new RegExp(s, 'g'), _aqa_.unique.createId());
		}
		c.innerHTML = t;
		return c;
	},

	firstTag : function (e){
		e = this.$(e).firstChild;
		while(e && e.nodeType != 1){
			e = e.nextSibling;
		}
		return e;
	},

	lastTag : function (e){
		e = this.$(e).lastChild;
		while(e && e.nodeType != 1){
			e = e.previousSibling;
		}
		return e;
	},

	previousTag : function (e){
		e = this.$(e).previousSibling;
		while(e && e.nodeType != 1){
			e = e.previousSibling;
		}
		return e;
	},

	nextTag : function (e){
		e = this.$(e).nextSibling;
		while(e && e.nodeType != 1){
			e = e.nextSibling;
		}
		return e;
	},

	stepUp : function (e){
		e = this.$(e);
		var p = e.parentNode;
		var b = this.previousTag(e);
		if(!b || e == b || e == this.firstTag(p)) return;
		p.removeChild(e);
		p.insertBefore(e, b);
	},

	stepDown : function (e){
		e = this.$(e);
		var p = e.parentNode;
		var b = this.nextTag(e);
		if(!b || e == b || e == this.lastTag(p)) return;
		var c = this.nextTag(b);
		if(!c || b == c || b == this.lastTag(p)){
			p.removeChild(e);
			p.appendChild(e);
		}else{
			p.removeChild(e);
			p.insertBefore(e, c);
		}
	},

	moveFirst : function (e, p){
		e = this.$(e);
		p = p ? this.$(p) : e.parentNode;
		var top = this.firstTag(p);
		if(top == e) return;
		if(e.parentNode) e.parentNode.removeChild(e);
		p.insertBefore(e, top);
	},

	moveLast : function (e, p){
		e = this.$(e);
		p = p ? this.$(p) : e.parentNode;
		if(e.parentNode) e.parentNode.removeChild(e);
		p.appendChild(e);
	},

	insertBefore : function (e, t){
		t = this.$(t);
		e = this.$(e);
		var pt = t.parentNode;
		var pe = e.parentNode;
		if(!pt) return;
		if(pe) pe.removeChild(e);
		pt.insertBefore(e, t);
	},

	insertAfter : function (e, t){
		t = this.$(t);
		e = this.$(e);
		var pt = t.parentNode;
		var pe = e.parentNode;
		var nx = this.nextTag(t);
		if(!pt) return;
		if(pe) pe.removeChild(e);
		if(!nx || t == nx || t == this.lastTag(pt)){
			pt.appendChild(e);
		}else{
			pt.insertBefore(e, nx);
		}
	},

	getStyle : function (e, IEStyleProp, CSSStyleProp){
		if(e.currentStyle){
			return e.currentStyle[IEStyleProp];
		}else if(window.getComputedStyle){
			return window.getComputedStyle(e, "").getPropertyValue(CSSStyleProp);
		}
	},

	// don't use element with 'position : relative, absolute, fix'
	getPosition : function (e){
		var x = 0, y = 0;
		while(e){
			x += e.offsetLeft;
			y += e.offsetTop;
			e = e.offsetParent;
			if((e) && (this.isMSIE)){
				x += (parseInt(this.getStyle(e, "borderLeftWidth", "border-left-width")) || 0);
				y += (parseInt(this.getStyle(e, "borderTopWidth", "border-top-width")) || 0);
			}
		}
		if(this.isGecko){
			var b = document.getElementsByTagName("BODY")[0];
			x += 2*(parseInt(this.getStyle(b, "borderLeftWidth", "border-left-width")) || 0);
			y += 2*(parseInt(this.getStyle(b, "borderTopWidth", "border-top-width")) || 0);
		}
		return {top : y, left : x};
	},

	/**
	 * ------------------------------
	 * methods : Browsing (URL, Cookie, Query)
	 */

	getScriptHome : function (script_file_name){
		var nl = _doc_.getElementsByTagName('script');
		for(var i in nl){
			if(nl[i].src && nl[i].src.indexOf(script_file_name, 0) > -1){
				return ele[i].src.split(nam)[0];
			}
		}
		return '';
	},

	fromQuery : function (str){
		var dec = decodeURIComponent;
		var par = {}, itm;
		str = str || location.search;
		if(typeof(str) == 'undefined') return par;
		if(str.indexOf('?', 0) > -1) str = str.split('?')[1];
		str = str.split('&');
		for(var i = 0; str.length > i; i++){
			itm = str[i].split("=");
			if(itm[0] !== ''){
				par[itm[0]] = typeof(itm[1]) == 'undefined' ? true : dec(itm[1]);
			}
		}
		return par;
	},

	toQuery : function (par){
		var enc = encodeURIComponent;
		var str = '', amp = '';
		if(!par) return '';
		for(var i in par){
			str = str + amp + i + "=" + enc(par[i]);
			amp = '&';
		}
		return str;
	},

	setCookie : function (key, val, expires, domain, path){
		if(!navigator.cookieEnabled) return false;
		if(expires || expires === 0){
			var t = new Date();
			t.setTime(t.getTime() + 24 * 60 * 60 * 1000 * expires);
			expires = ';expires=' + t.toGMTString();
		}else expires = '';
		if(domain) domain = ';domain=' + domain; else domain = '';
		if(path) path = ';path=' + path; else path = '';
		document.cookie = key + '=' + val + expires + domain + path;
		return true;
	},

	getCookie : function (key){
		if(!navigator.cookieEnabled) return false;
		var val = {};
		var dat = (document.cookie).replace(/;\s/g, ";").split(";");
		for(var t = 0, l = dat.length; l > t; t++){
			dat[t] = dat[t].split('=');
			if(dat[t][0] == key && typeof(dat[t][1]) != 'undefined'){
				return dat[t][1];
			}
		}
		return false;
	},

	delCookie : function (key, domain, path){
		if(!navigator.cookieEnabled) return false;
		if(domain) domain = ';domain=' + domain; else domain = '';
		if(path) path = ';path=' + path; else path = '';
		var expires = ';expires=' + (new Date()).setTime(t.getTime() - 1).toGMTString();
		document.cookie = key + '=0' + expires + domain + path;
		return true;
	},

	/**
	 * ------------------------------
	 * methods : dialog, popup
	 */

	confirm : function (txt, tfn, ffn){;
		if(window.confirm(txt)){
			if(typeof(tfn) == 'function') tfn();
		}else{
			if(typeof(ffn) == 'function') ffn();
		}
	},

	/**
	 * ------------------------------
	 * methods : for frame work
	 */

	getAqaProperty : function (typ){
		var p = 0, a = [];
		for(var i in this){
			p = this[i];
			if(
				(typ == 1 && ((typeof(p) != 'function' && typeof(p) != 'object') || p == null)) ||
				(typ == 2 && typeof(p) == 'function') ||
				(typ == 3 && typeof(p) == 'object' && p !== null) ||
				!typ
			){
				a[i] = p;
			}
		}
		return a;
	},
	getAqaPrimitives : function (){return this.getAqaProperty(1);},
	getAqaFunctions : function (){return this.getAqaProperty(2);},
	getAqaObjects : function (){return this.getAqaProperty(3);},

	dump : function (o, _container, /* follows, for system */ dept, indt, org){
		var max_depth = 4;
		if(o == window || o == document || o == document.body || o == org){
			return '';
		}
		if(!dept){
			dept = 1;
			indt = '&nbsp;&nbsp;';
		}else{
			dept++;
			indt += '&nbsp;&nbsp;';
		}
		var t = '';
		for(var i in o){
			if(typeof(o.hasOwnProperty) == 'undefined' || o.hasOwnProperty(i)){
				try{
					if(typeof(o[i]) == 'object'){
						t += indt + i + "&nbsp;&nbsp;:&nbsp;&nbsp;<br />";
						if(dept <= max_depth){
							t += this.dump(o[i], _container, dept, indt, o);
						}else{
							t += indt + i + "&nbsp;&nbsp;:&nbsp;&nbsp;*** TOO DEEP!!! ***<br />";
						}
					}else if(typeof(o[i]) == 'string' && o[i].length > 200){
						t += indt + i + "&nbsp;&nbsp;:&nbsp;&nbsp;*** TOO LONG!!! ***<br />";
					}else if(typeof(o[i]) == 'string'){
						t += indt + i + "&nbsp;&nbsp;:&nbsp;&nbsp;" + o[i].replace(/</g, '&lt;').replace(/>/g, '&gt;') + "<br />";
					}else{
						t += indt + i + "&nbsp;&nbsp;:&nbsp;&nbsp;" + o[i] + "<br />";
					}
				}catch(e){
					t += indt + i + "&nbsp;&nbsp;:&nbsp;&nbsp;*** ERROR!!! ***<br />";
				}
			}
		}
		if(dept == 1){
			var inf = _doc_.createElement('div');
			inf.innerHTML = t;
			if(_container) _container.appendChild(inf);
			else document.body.appendChild(inf);
		}else{
			return t;
		}
	}
});

/**
 * -----------------------------------------------------------------------------
 * initial information
 */
_aqa_.initInformation = {
	
	info : [],
	
	run : function (){
		var slf = this;
		if(this.info.length == 1) _aqa_.setLoad(
			function (){
				var inf = '', tmp = '';
				for(var i = 0, l = slf.info.length; i < l; i++){
					if((tmp = slf.info[i]())) inf += tmp;
				}
				if(inf) alert(inf);
			}
		);
	},

	set : function (checkfn){
		this.info[this.info.length] = checkfn;
		this.run();
	},

	nocookie : function (fn){
		this.info[this.info.length] = function (){
			if(!navigator.cookieEnabled && fn) fn();
		}
	 this.run();
	},

	nojava : function (fn){
		this.info[this.info.length] = function (){
			if(!navigator.javaEnabled() && fn) fn();
		}
		this.run();
	}
}

/**
 * -----------------------------------------------------------------------------
 * unique codes
 */
_aqa_.unique = {

	id : false,

	createId : function(dgt, rdx, cnt){
		var moj = '9', max = 0, fom; 
		if(this.id){
			dgt = this.figures;
			rdx = this.radix;
			cnt = this.value;
			fom = this.form;
			cnt++;
		}else{
			if(!_aqa_.isNumber(dgt) || dgt < 3 || dgt > 14) dgt = 8;
			if(!_aqa_.isNumber(rdx)) rdx = 10;
			if(rdx < 2 || rdx > 36) rdx = 10;
			else if(rdx <= 10) moj = (rdx - 1).toString();
			else if(rdx >  10) moj = String.fromCharCode(86 + rdx);
			if(_aqa_.isNumber(cnt)) cnt = cnt.toString();
			if(_aqa_.isString(cnt)) cnt = _aqa_.toDecimal(cnt, rdx);
			else cnt = 0;
			for(var i = 0; dgt > i; i++){
				max += moj;
				fom += "0";
			}
			this.max     = _aqa_.toDecimal(max, rdx);
			this.figures = dgt;
			this.radix   = rdx;
			this.chr     = moj;
			this.form    = fom;
		}
		if(cnt > Math.pow(10, dgt) - 1) cnt = 0;
		this.value = cnt;
		cnt = (fom + cnt.toString(rdx));
		cnt = cnt.substring(cnt.length - dgt, cnt.length);
		this.id    = cnt;
		return cnt;
	},
	
	clearCreateId : function (){
		this.id = false;
	}
};

/**
 * -----------------------------------------------------------------------------
 * init
 */

_aqa_.cash.unique = _aqa_.clone(_aqa_.unique);
_aqa_.setLoad(function (){
	var tid = setInterval(
		function (){
			var fns = _aqa_.intervals;
			if(typeof(fns) != 'object') clearInterval(tid);
			else for(var i in fns){
				if(fns.hasOwnProperty(i) && typeof(fns[i]) == 'function') fns[i]();
			}
		},
		200
	);
});

