/*
change log

2007.01.12 : µÎ¹ø Å¬¸¯ ½Ã ¾Èº¸ÀÌ°Ô ÇÏ´Â ±â´É Ãß°¡
2007.01.19 : Àü¿ªº¯¼ö »ý¼ºÀÚ¿¡¼­ ¼±¾ðÇÏ°Ô º¯°æ
             for¹®À» ¾²Áö ¾Ê°í ¼±ÅÃµÈ ºÎºÐ°ú Àü¿¡ ¼±ÅÃµÈ µÎ°³¸¸ º¯°æÇÏµµ·Ï ¼öÁ¤
2007.01.20 : ÀÌº¥Æ® °´Ã¼ ÀÌ¹ÌÁö ·Ñ¿À¹ö Ãß°¡
             ÀÌº¥Æ® °´Ã¼¿¡ ½ºÅ¸ÀÏ Å¬·¡½º Ãß°¡ÇÒ ¼ö ÀÖµµ·Ï ¼öÁ¤
2007.01/30 : multi¸¦ array·Î addÇßÀ»¶§ ÇØ´ç array¾È¿¡ ÀÖ´Â ·¹ÀÌ¾îµé ÀüºÎ µ¿ÀÏÇÑ ÀÌº¥Æ® ÀÏ¾î³¯ ¼ö ÀÖµµ·Ï ¼öÁ¤
bbs_view
	string		method		¼±ÅÃ	ÀÌº¥Æ® Å¸ÀÔ : click(onclick), roll(onmouseover)
	boolean		isClose		¼±ÅÃ	ÀÌº¥Æ® ÀÏ¾î³µÀ» °æ¿ì Å¸°ÙÀ» ´ÝÀ»°ÍÀÎÁö È®ÀÎ
	string		_tab		¼±ÅÃ	ÀÌº¥Æ®°¡ ÀÏ¾î³¯ °´Ã¼
	boolean		img_chg		¼±ÅÃ	ÀÌº¥Æ®°¡ ÀÏ¾î³¯ °´Ã¼°¡ ÀÌ¹ÌÁöÀÏ °æ¿ì rollover ÇÒ°ÍÀÎÁö

	add
		string		id		ÇÊ¼ö	ÀÌº¥Æ® ¹ß»ý ½Ã ÇØ´ç º¸¿©ÁÙ °´Ã¼ id
		string		url		¼±ÅÃ	ÀÌº¥Æ® ¹ß»ý ½Ã ÇØ´ç °´Ã¼°¡ ÀÌ¹Ì ¼±ÅÃµÇ¾îÀÖ´Â »óÅÂÀÏ °æ¿ì¿¡ ÀÌµ¿µÉ ÁÖ¼Ò
		string		multi	¼±ÅÃ	ÀÌº¥Æ® ¹ß»ý ½Ã 
*/
bbs_view = function(method, isClose, _tab, img_chg) {
	this.itemCount  = 0;
	this.item       = new Array();
	this.idType     = new Array();
	this.selectedId = null;
	this.isClose    = isClose ? true : false;
	this.closed     = true;
	this.method     = method ? method : 'click';
	this._tab       = _tab ? _tab : '_tab';
	this.img_chg    = img_chg ? true : false;
	this.tab_className  = '';
	this.default_className = '';
	this.defaultAction = 'this.view(id);';
	this.mode = 'both';

	if(this.img_chg) {
		this.img_var_init();
	}
}
bbs_view.prototype.add = function(id, url, multi) {
	var classObj = this;
	var url_     = url ? url : null;
	var obj = id;
	var thisType = 'string';
	if(this.mode == 'both') {
		if(typeof multi == 'object') {
			obj = new Array();
			thisType = 'array';
			obj['count'] = multi.length;
			obj['obj'] = new Array();
			for(var i=0; i<obj['count']; i++) {
				obj['obj'][i] = el_id(multi[i]);
				obj['obj'][i].style.display = 'none';
			}
		} else {
			thisType = 'string';
			obj = el_id(id);  // ÀÌº¥Æ® ¹ß»ý ½Ã ³ªÅ¸³ª´Â ·¹ÀÌ¾î °´Ã¼
			obj.style.display = 'none';
		}
	}
	var obj_tab  = el_id(id+this._tab);  // ÀÌº¥Æ® ¹ß»ýÇÒ °´Ã¼

	obj_tab.className = this.default_className;
	if(this.item[id] == undefined) {
		this.item[id] = new Array(url_, obj, obj_tab, id, thisType);
	}

	if(this.img_chg) {
		var outImg = new Image(), onImg = new Image();
		var returnImg = new Array();

		outImg.src = obj_tab.src.replace(this.onSearch, this._off + "$1");
		onImg.src  = outImg.src.replace(this.offSearch, this._on + "$1");

		obj_tab.setAttribute('outsrc', outImg.src);
		obj_tab.setAttribute('onsrc', onImg.src);
	}

	// onclickÀÌ³ª onmouseover ½Ã ½ÇÇàµÉ ½ºÅ©¸³Æ®
	// Ãß°¡ÇÏ·Á¸é obj_tab ºÎºÐ ÅÂ±×¿¡ thisAction ÀÌ¶ó´Â attr Ãß°¡( ex:thisAction="alert('a');" )
	if(this.method == 'click') {
		obj_tab.evtAction = obj_tab.onclick;
		obj_tab.onclick = function() {
			classObj.action(this, id);
			/*
			eval(classObj.defaultAction); // ±âº»ÀûÀ¸·Î ¼±ÅÃÇÑ °´Ã¼¿¡ ÇØ´çÇÏ´Â ·¹ÀÌ¾î º¸¿©ÁÖ±â
			if(this.thisAction) {
				eval(this.thisAction);
			}
			*/
		}
	} else if(this.method == 'roll') {
		obj_tab.evtAction  = obj_tab.onmouseover;
		obj_tab.onmouseover = function() {
			classObj.action(this, id);
			/*
			eval(classObj.defaultAction);
			if(this.thisAction) {
				eval(this.thisAction);
			}
			*/
		}
	}
}
bbs_view.prototype.action = function(obj, id) {
	if(this.defaultAction) {
		eval(this.defaultAction);
		//this.view(id);
		var objAction = obj.getAttribute('thisAction');
		if(objAction) {
			eval(objAction);
		}
	}
	try {
		if(typeof(obj.evtAction) != 'undefined') { obj.evtAction(); }
	}
	catch (e) { }
}
bbs_view.prototype.view = function(id) {
	try {
		var selId = this.selectedId;
		var selItem = this.item[selId];
		if(id == selId) {
			if(this.isClose == true && this.closed == false) {
				this.closed = true;
				if(selItem[4] == 'array') {
					for(var i=0; i<selItem[1]['count']; i++) {
						selItem[1]['obj'][i].style.display = 'none';
					}
				} else if(selItem[1] != undefined && !selItem[1]) {
					selItem[1].style.display = 'none';
				}
				selItem[2].className = this.default_className;
				if(this.img_chg) {
					selItem[2].src = selItem[2].getAttribute('outsrc');
				}
				return;
			} else {
				this.closed = false;
				if(selItem[4] == 'array') {
					for(var i=0; i<selItem[1]['count']; i++) {
						selItem[1]['obj'][i].style.display = '';
					}
				} else if(selItem[1] != undefined && !selItem[1]) {
					selItem[1].style.display = '';
				}
				selItem[2].className = this.tab_className+' '+this.default_className;
				if(selItem[0]) {
					document.location.href = selItem[0];
					return;
				}
				if(this.img_chg) {
					selItem[2].src = selItem[2].getAttribute('onsrc');
				}
				return;
			}
		}
		if(selId != undefined) {
			if(selItem[4] == 'array') {
				for(var i=0; i<selItem[1]['count']; i++) {
					selItem[1]['obj'][i].style.display = 'none';
				}
			} else if(selItem[1] != undefined && selItem[1]) {
				selItem[1].style.display = 'none';
			}
			selItem[2].className = this.default_className;
			if(this.img_chg) {
				selItem[2].src = selItem[2].getAttribute('outsrc');
			}
		}

		this.closed = false;
		if(this.img_chg) {
			this.item[id][2].src = this.item[id][2].getAttribute('onsrc');
		}
		if(this.item[id] != undefined) {
			if(this.item[id][4] == 'array') {
				for(var i=0; i<this.item[id][1]['count']; i++) {
					this.item[id][1]['obj'][i].style.display = '';
				}
			} else if(this.item[id][1] != undefined && this.item[id][1]) {
				this.item[id][1].style.display = '';
			}
		}
		this.item[id][2].className = this.default_className+' '+this.tab_className;
		this.selectedId = id;
	} catch (e) {
		alert(e);
	}
}
bbs_view.prototype.img_var_init = function() {
	this.img_chg = true;
	this._on = this._on != undefined ? this._on : '_on';
	this._off = this._off != undefined ? this._off : '_off';
	this.extReg = "(\.[^\.]+)$"; // È®ÀåÀÚ¿Í ±¸ºÐÀÚ¸¦ ºÐ·ùÇÏ´Â Á¤±Ô½Ä
	this.onSearch = new RegExp(this._on + this.extReg);
	this.offSearch = new RegExp(this._off + this.extReg);
}
