// img over out
function imgOver(obj) { obj.src = obj.src.replace("Off.gif", "On.gif");}
function imgOut(obj) { obj.src = obj.src.replace("On.gif", "Off.gif");}

Function.prototype.bind = function(){
    // http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Functions:arguments
    var _$A = function(a){return Array.prototype.slice.call(a);}
    if(arguments.length < 2 && (typeof arguments[0] == "undefined")) return this;
    var __method = this, args = _$A(arguments), object = args.shift();
    return function() {
      return __method.apply(object, args.concat(_$A(arguments)));
    }
};

$n = {
	create : function() {
		return function() { this.initialize.apply(this, arguments); } 
	},
	overed : function(destination, source) {
		for (var property in source) {destination[property] = source[property];}
		return destination;
	},
	extend : function(ext, sup) {
		var ext_prototype = ext.prototype; var sup_prototype = sup.prototype;
		for (var property in sup_prototype) { if(!ext_prototype[property]) ext_prototype[property] = sup_prototype[property]; }
	},
	log : {
		LEVEL : 2,
		levels: {
			DEBUG:0,
			INFO:1,
			ERROR:2
		},
		setLogLevel : function(lv) {
			if(lv == "DEBUG") $n.log.LEVEL = $n.log.levels.DEBUG; 
			else if(lv == "INFO") $n.log.LEVEL = $n.log.levels.DEBUG;
			else if(lv == "ERROR") $n.log.LEVEL = $n.log.levels.DEBUG;
		},
		log : function(s) {
			try {
				if(typeof(console) != "undefined") console.log(s);
				else alert($n.object.toString(s));
			} catch(e) {}
		},
		debug : function(s) {
			if($n.log.LEVEL <= $n.log.levels.DEBUG) $n.log.log(s);;
		},
		info : function(s) {
			if($n.log.LEVEL <= $n.log.levels.INFO) $n.log.log(s);;
		},
		error : function(s) {
			if($n.log.LEVEL <= $n.log.levels.ERROR) $n.log.log(s);;
		}
	},
	date : {
		yyyyMMdd : function(d) {
			if(!d) d = new Date();
			return d.yyyyMMdd();
		}
	},
	math : {
		abs : function(x) {
			return Math.abs(x);
		},
		random : function(n) {
			if(typeof(n) == "undefined") return Math.random();
			else return $n.math.floor(Math.random() * n, 0);
			
		},
		round : function(n, index) {
			return $n.math._get("round", n, index);
		},
		ceil : function(n, index) {
			return $n.math._get("ceil", n, index);
		},
		floor : function(n, index) {
			return $n.math._get("floor", n, index);
		},
		_get : function(type, n, index) {
			if(typeof(index) == "undefined" || index == null) {
				index = 0;
			}
			if(index==0) return eval("Math."+type+"(n)");
			else {
				var p = Math.pow(10, index);
				return eval("Math."+type+"(n * p) / p");
			}
		}
	},
	cookie : {
		set : function(name, value) {
			var argc = arguments.length;
			var argv = arguments;
			var expires = ( argc > 2) ? argv[2]:null;
			var path = ( argc > 3) ? argv[3]:null;
			var domain = ( argc > 4) ? argv[4]:null;
			var secure = ( argc > 5) ? argv[5]:false;
	
			document.cookie = name + "=" + escape(value) +
				((expires == null) ? "" : ("; expires =" + expires.toGMTString())) +
				((path == null) ? "" : ("; path =" + path)) +
				((domain == null) ? "" : ("; domain =" + domain)) +
				((domain == true) ? "; secure" : "");
		},
		get : function(name) {
			var dcookie = document.cookie;
			var cname = name + "=";
			var clen = dcookie.length;
			var cbegin = 0;
			while (cbegin < clen) {
				var vbegin = cbegin + cname.length;
					if (dcookie.substring(cbegin, vbegin) == cname) {
						var vend = dcookie.indexOf (";", vbegin);
						if (vend == -1) vend = clen;
					return unescape(dcookie.substring(vbegin, vend));
				}
				cbegin = dcookie.indexOf(" ", cbegin) + 1;
				if (cbegin == 0) break;
			}
			return "";
		}
	},
	visible : function(e) {
		var _is_display = false;
		if(e) e.each(function() {if(this.style.display != "none") _is_display = true; });
		return _is_display;
	},
	focusNblur : function(selector, focusClass, blurClass) {
		if(typeof focusClass == "undefined") focusClass = "focus";
		if(typeof blurClass == "undefined") blurClass = "default";
		$(selector).focus(function(e) {
			var ee = $(e.target);
			ee.removeClass(blurClass);
			ee.addClass(focusClass);
		}).blur(function(e) {
			var ee = $(e.target);
			ee.removeClass(focusClass);
			ee.addClass(blurClass);
		});
	},
	object : {
		toString : function(obj) {
			var str = "";
			if(typeof obj == "string") return obj;
			else {
				for (var property in obj) {
					str += property + ":" + "{" + $n.object.toString(obj[property])+ "}";
				}
				return str;
			}
		},
		empty : function(obj) {
			if(typeof obj == "undefine" || obj == null) return true;
			if(typeof obj == "string") return $n.valid.empty(obj);
			if(typeof obj == "object") {
				var _ret = true;
				for (var property in obj) {
					_ret = false; break;
				}
				return _ret;
			}
		}
	},
	utils : {
		stripTag : function(s) {
			s = s.replace(/&(lt|gt);/g, function (strMatch, p1){	return (p1 == "lt")? "<" : ">"; });
			return s.replace(/<\/?[^>]+(>|$)/g, "");
		},
		toTag : function(s) {
			s = s.replace(/&(lt|gt);/g, function (strMatch, p1){	return (p1 == "lt")? "<" : ">"; });
			return s;
		},
		cutstring : function(s, length, postfix) {
			if(!s) return "";
			if(!postfix) postfix = "";
			if(s.length <= length) return s;
//			if($n.utils.byteSize(s) <= length) return s;
			else return s.substring(0, length) + postfix;
		},
		cutstring1 : function(s, length) {
			return $n.utils.cutstring(s, length, "...");
		},
		trim : function(str) {
			return str.replace(/(^\s*)|(\s*$)/g, "");
		}, 
		byteSize : function(str, twoByteWeight) {
			if(typeof twoByteWeight == "undefined") twoByteWeight = 2;
			if(!str ||  typeof str != 'string') return 0;
			var cnt = 0;
			for (var i = 0; i < str.length; i++) {
				if (str.charCodeAt(i) > 127)
					cnt += twoByteWeight;
				else
					cnt++;
			}
			return $n.math.ceil(cnt);
		},
		strlengthByByte : function(str, size, twoByteWeight) {
			if(typeof twoByteWeight == "undefined") twoByteWeight = 2;
			if(!str ||  typeof str != 'string') return 0;
			var cnt = 0, len = 0;
			
			for (var i = 0; i < str.length; i++) {
				if (str.charCodeAt(i) > 127)
					cnt += twoByteWeight;
				else
					cnt++;
				if(cnt > size) return len;
				len++;

			}
			return len;
		},
		cutbytestring : function(s, size, postfix, twoByteWeight) {
			if(!s) return "";
			if(!postfix) postfix = "";
			if($n.utils.byteSize(s) <= size) return s;
			else return s.substring(0, $n.utils.strlengthByByte(s, size, twoByteWeight)) + postfix;
		},
		cutbytestring1 : function(s, size, twoByteWeight) {
			return $n.utils.cutbytestring(s, size, "...", twoByteWeight);
		}
	},	
	valid : {
		empty : function(str) {
			if(typeof str == "string" && $n.utils.trim(str).length > 0) 
				return false;
			return true;
		},
		email : function(str) {
			return (/\w+([-+.]\w+)*@\w+([-.]\w+)*\.[a-zA-Z]{2,4}$/).test(str);
		},
		kor : function(str) {
			str = $n.utils.trim(str);
			return (/^[°¡-ÆR]+$/).test(str);
		},
		numengkor : function(str) {
			str = $n.utils.trim(str);
			return (/^[°¡-ÆR0-9a-zA-Z]+$/).test(str);
		},
		notkor : function(str) {
			str = $n.utils.trim(str);
			return (/[°¡-ÆR]+/).test(str);
		},
		numdash : function(str) {
			str = $n.utils.trim(str);
			return (/^[0-9]{1}[0-9\-]+$/).test(str);
		},
		url : function(str) {
			str = $n.utils.trim(str);
			return (/^http:\/\/([\w\-]+\.)+/).test(str);
		},
		num : function(str) {
			str = $n.utils.trim(str);
			return (/^[0-9]+$/).test(str);
		},
		include2byte : function(str) {
			if(!str ||  typeof str != 'string') return false;
			for (var i = 0; i < str.length; i++) {
				if (str.charCodeAt(i) > 127)
					return true;
			}
			return false;
		}
	},
	mainurl : function() {
		var url = document.location.href;
		//return url;
		if(url.indexOf("me.sayclub.com") > 0) {
			return "http://me.sayclub.com";
		} else return _staticUrl;
	} 
}

$n.template = $n.create();
$n.template.prototype = {
	initialize : function(tmpl, json) {
		this.setTemplate(tmpl);
		this.setData(json);
	}, 
	setFile : function(src) {
		// TODO
	},
	setTemplate : function(tmpl) { if(tmpl) this._template = tmpl;},
	
	setData : function(data) {
		if(data && data != "") {
			this._data = $n.overed(this._data||{}, data||{});
		} else {
			this._data = {};
		}
	},
	html : function() {
		var js = this._template.replace(/[\r\t\n]/g, " ")
			.replace(/'(?=[^%]*%>)/g, "\t")
			.split("'").join("\\'")
			.split("\t").join("'")
			.replace(/<%=(.+?)%>/g, "',$1,'")
			.split("<%").join("');")
			.split("%>").join("write.push('");
		var f = new Function('obj', "var write=[];with (obj){write.push('"+js+"');}return write.join('');");
		if (!this._data) return f;
		var r = f(this._data);
		return r;
	}
	
}



$n.object.select = $n.create();
$n.object.select.prototype = {
	initialize : function(id, name, value, option) {
		this.id = id;
		this.name = name;
		if(arguments.length == 3 && typeof(value) != "string") {
			option = value;
			value = $("#"+this.id).attr("value");
		}
		this.value = value;
		this.option = $n.overed({
			onchange : function() {},
			onclick : function() {},
			notitle : "&nbsp;",
			overflow : false
		}, option || {});
		this.select = $("#"+this.id).addClass("selectForm");
		this.selectList = this.select.find(" > div:last").hide();
		this.selected = this.select.find(" > div:first").addClass("selectTitle")
			.bind("click", this.selectList, this.clickSelected);

		if(this.option.overflow == false) { 
			this.selectList.addClass("selectLayer");
		} else {
			this.selectList.addClass("selectLayerWrap");
			this.selectList.find("ul").addClass("selectLayer");
		}
		
		if(this.option.width) {
			this.selected.css("width", this.option.width);
			this.selectList.css("width", this.option.width);
		}
		

		this.selectOptions = this.initOption(this.select.find(" > div:last li"));
		var __inp = this.select.find(" > input[name="+this.name+"]:hidden");
		if(__inp.length > 0) {
			this.select.find(" > input:hidden").attr("value", this.value);
			this.hiddenObject = __inp;
		} else {
			this.hiddenObject = $("<input type=\"hidden\"/>").attr("name", this.name).attr("value", this.value).appendTo(this.select);
		}
		this.setValue(this.value);
	},
	initOption : function(_opt) {
		if(_opt) 
			_opt.hover(function(e) { $(this).addClass("over");}, function(e) { $(this).removeClass("over");})
				.bind("click", this, this.clickOption);
		return _opt;
	},
	clickOption : function(e) {
		var _new = $(this).attr("value");
		var _old = e.data.getValue();
		if(_new != _old) {
			e.data.setValue(_new);
			e.data.option.onchange(_old, _new);
		}
		e.data.selectList.hide();
		e.data.option.onclick(_old, _new);
	},
	clickSelected :	function(e) {
		if($n.visible(e.data)) e.data.hide();
		else {
			e.data.show();
			e.data.children().show();
		}
	},
	getValue : function() {
		return this.hiddenObject.attr("value");
	},
 	setValue : function(value) {
		if(typeof(value) == "undefined") {
			this.selected.find("> a").html(this.option.notitle);
		}
		this.value = value;
		var selectedOption = this.selectOptions.removeClass("selected")
					.filter("[value="+value+"]");
		if(selectedOption.length == 0) {
			this.selected.find("> a").html(this.option.notitle);
		} else {
			this.selected.find("> a").html(selectedOption.addClass("selected").text());
		}
		this.hiddenObject.attr("value", value);
	},
	getText : function(key) {
		if(typeof key == "undefined") key = this.getValue();
		return this.select.find(" > div:last li[value="+key + "] a").text();
	},
	appendOption : function(value, text) {
		this.selectOptions = this.initOption(
				$("<li></li>").attr("value", value).html(text).appendTo(this.selectOptions.parent())
			).parent().find("li");
	},
	prependOption : function(value, text) {
		this.selectOptions = this.initOption(
				$("<li></li>").attr("value", value).html(text).prependTo(this.selectOptions.parent())
			).parent().find("li");
	},
	onchange : function(f) {
		var old = this.option.onchange; 
		this.option.onchange = function(o, n) { old(o, n); f(o, n); }.bind(this);
	},
	onclick : function(f) {
		var old = this.option.onclick;
		this.option.onclick = function(o, n) { old(o, n); f(o, n); }.bind(this);
	},
	hide : function(speed) {
		if(speed) this.select.hide(speed);
		else this.select.hide();
	},
	show : function(speed) {
		if(speed) this.select.show(speed);
		else this.select.show();
	}

}

// ---------------
//    commbar 
//   : copy from rose
// ---------------
$n.properties = {
	commbar : {
		service : "sayclub",
		urlFriendList : _baseUrl + "?act=friendList",
		urlFriendCnt : _baseUrl + "?act=friendCount",
		urlFriendRand : _baseUrl + "?act=friendRand",
		urlCjList : _baseUrl + "?act=cjList",
		urlMemoList : _baseUrl + "?act=memoList",
		urlMemoCnt : _baseUrl + "?act=memoCount",
		urlMemoDel : _baseUrl + "?act=memoDel",
		urlNoticeList : _baseUrl + "?act=noticeList",
		urlNoticeCnt : _baseUrl + "?act=noticeCount",
		urlNoticeRead : _baseUrl + "?act=readNotice",
		urlNoticeDel : _baseUrl + "?act=delNotice"
	}
}



$n.commbar = {
	commbar : $('#commbar'),
	sayalert : null,
	PAGE_ROW : 30,
	ready : function(option) {
	//	$n.commbar.option = $n.overed({firstlogon : false}, option);
    $n.commbar.option = $n.overed({firstlogon : false, actionNewPage : false}, option);
		$n.commbar.alerts = new $n.commbar.sayalerts();
		$n.commbar.init();
		$n.commbar.setInitData();
	},
	init : function() {
		$n.commbar.commbar = $('#commbar');		
		if ($("#commbarWrap").css("position") != "fixed") {
			$n.commbar.locMove();
			$(window).scroll($n.commbar.locMove);
			$(window).resize($n.commbar.locMove);
		}		
		$n.commbar.listboxList =new $n.commbar.listboxes();    
		$n.commbar.listNotice = new $n.commbar.listbox($('#commNoticeBox, #menuNotice'), {
			positionRight : 0, listClass : "feedNoticeList", 
			loadData : $n.commbar.loadNoticeData, success : $n.commbar.loadNoticeDataSuccess
		});
		$n.commbar.listMsg = new $n.commbar.listbox($('#commNewMsgBox, #menuMemo'), {
			positionRight : 60, 
			loadData : $n.commbar.loadMemoData, success : $n.commbar.loadMemoDataSuccess
		});
		$n.commbar.listFriend = new $n.commbar.listbox($('#commFriendBox, #menuFriend'), {
			positionRight : 131, listClass : "friendList", 
			loadData : $n.commbar.loadFriendData, success : $n.commbar.loadFriendDataSuccess
		});
		
		$n.commbar.listboxList.add($n.commbar.listNotice);
		$n.commbar.listboxList.add($n.commbar.listMsg);
		$n.commbar.listboxList.add($n.commbar.listFriend);
		
		// menuº° hover ¼³Á¤
		$("#commbar .menu li div").hover(this.menuOver, this.menuOut);
		
		// page°¡ º¯°æµÇ¾îµµ notify Áö¼Ó
		if($n.commbar.isCookieFriend()) $n.commbar.alertMenu("friend"); 
		if($n.commbar.isCookieMemo()) $n.commbar.alertMenu("msg");
		if($n.commbar.isCookieNotice()) $n.commbar.alertMenu("notice");
		
		if($n.commbar.option.firstlogon) {
			$n.commbar.initNoticeCnt();
		}
		
		$n.commbar.initFriendRand();

    if($n.commbar.option.actionNewPage) {
      $n.commbar.setNewPage();
    }
		
	},
	locMove : function() {
		var y = $(document).scrollTop() + $(window).height() - 29;
		$("#commbarWrap").css("top",y);
	},
  setNewPage : function() {
    $n.commbar.commbar.find(".friendState ul li > a").attr("target", "_blank");
    $("#commFriendBox .commLayerBtm .more a").attr("target", "_blank");
    $("#commFriendBox li a.nameLink").attr("target", "_blank");
    $("#commNoticeBox .commLayerBtm .more a").attr("target", "_blank");
  },
	initNoticeCnt : function() {
		var url = $n.properties.commbar.urlNoticeCnt;
		//if(!$("#commbar .menu li.notice div").hasClass("newOut")) { 
			$.getJSON(url, function(data){
				if(data == null) data = 0;
				if(data > 0) {
					$n.commbar.alertMenu("notice");
				}
			});
		//}
	},
	menuOver : function(e) {
		var _menu = $(this);
		var _over = "over", _out = "default";
		$(this).addClass(_over).removeClass(_out); 
	},
	menuOut : function(e) {
		var _menu = $(this);
		var _over = "over", _out = "default";
		$(this).addClass(_out).removeClass(_over); 
	},
	loadMemoData : function(box, page, success, error) {
		if(typeof page == "undefined") page = 1;
		$n.commbar.defaultMenu("msg");
		
		var _url = $n.properties.commbar.urlMemoList;
		if ($n.properties.commbar.service == "rose")
			_url += "/"+page + "/" + $n.commbar.PAGE_ROW;
		else
			_url += "&page="+page+"&rowCnt="+$n.commbar.PAGE_ROW;
		
		$.getJSON(_url, success.bind($n.commbar.listMsg, box, page));
		//cookie
		$n.commbar.removeCookieMemo();
		// when document is clicked, will hide list layer
		$(document).bind("click", $n.commbar.hideListWhenDocumentClick);

	},
	loadMemoDataSuccess : function(box, page, data) {
		if(data == null) data = {cnt:0,newCnt:0,list:[]};
		box.find("#commNewMsgBoxCount").html(data.newCnt);
		
		data.page = page;
		var _tmp = new $n.template($n.commbar.tmpmsglist, data);
		$n.commbar.listMsg.addList($(_tmp.html()));
		$n.commbar.listMsg.list.find("li").hover(
			function(e) { $(this).find("span.deleteBtn").fadeIn("fast"); },
			function(e) { $(this).find("span.deleteBtn").fadeOut("fast"); }
		);
		
		$n.commbar.loadPageLayer(box.find(".commLayerBtm"), page, data.cnt, "$n.commbar.loadMemoPage");
	},
	loadMemoPage : function(page) {
		$n.commbar.listMsg.loadList({page:page});
	},
	tmpmsglist : '<%if(!$n.commbar.emptylist(obj)){ %>' + 
		'<% for(var i=0;i < obj.list.length;i++) { var item = obj.list[i];  %>' +
		'<li>' +
		'<p><a href="javascript:void(0);" onclick="$n.commbar.openMemoPop(\'<%=item.link%>\')"><%=$n.utils.cutstring1(item.content, 20)%></a></p>' +
		'<span class="deleteBtn" style="display:none;"><a href="javascript:$n.commbar.deleteMemo(\'<%=item.srl%>\', <%=obj.page%>);"><img src="<%=_staticImgUrl%>/common/commbar/bc_deleteOff.gif" onmouseover="imgOver(this)" onmouseout="imgOut(this)" alt="»èÁ¦" /></a></span>' +
		'<span class="time"><%=item.stime%></span> <span class="from"><a href="http://me.sayclub.com/profile/r/msrl/<%=item.senderMsrl%>" class="nameLink" onClick="namePop.open(\'<%=item.senderMsrl%>\',\'nick\',this); return false;"><%=item.senderid%></a></span>' +
		'</li><% } %>' +
		'<% } else { %>' + 
		'<li class="noList">»õ ÂÊÁö°¡ ¾ø½À´Ï´Ù.</li>' +
		'<% } %>' + 
		'',
	deleteMemo : function(srl, page) {
		if(typeof srl == "undefiend") return;
		if(!confirm("»õÂÊÁö ¸ñ·Ï¿¡¼­ Á¦¿ÜÇÏ½Ã°Ú½À´Ï±î?")) return;
		if(typeof page == "undefined") page = 1;
		var _url = $n.properties.commbar.urlMemoDel;
		if ($n.properties.commbar.service == "rose")
			_url += "/"+srl;
		else
			_url += "&srl="+srl;
		$.getJSON(_url, function(data){
			if(data == true) {
				//$n.commbar.listMsg.hide();
				$n.commbar.listMsg.loadList(page);
				$n.commbar.memoCount();
			}
		});
	},
	openMemoPop : function(url) {
		open_win_noresizable(url,'',364,290);
		setTimeout("$n.commbar.memoCount(); $n.commbar.listMsg.show();",2000);
	},
	loadNoticeData : function(box, page, success, error) {
		if(typeof page == "undefined") page = 1;
		$n.commbar.defaultMenu("notice");
		
		var url_list = $n.properties.commbar.urlNoticeList;
		if ($n.properties.commbar.service == "rose")
			url_list += "/"+page + "/" + $n.commbar.PAGE_ROW;
		else
			url_list += "&page="+page+"&rowCnt="+$n.commbar.PAGE_ROW;
		$.getJSON(url_list, success.bind($n.commbar.listNotice, box, page));
		//cookie
		$n.commbar.removeCookieNotice();
		// when document is clicked, list layer will be hidden
		$(document).bind("click", $n.commbar.hideListWhenDocumentClick);
	},
	loadNoticeDataSuccess : function(box, page, data) {
		
		if(data == null) data = {cnt:0,newCnt:0,list:[]};
		box.find("#commNoticeBoxCount").html(data.newCnt);
		data.page = page;
		
		var _tmp = new $n.template($n.commbar.tmpnoticelist, data);
		$n.commbar.listNotice.addList($(_tmp.html()));
		$n.commbar.listNotice.list.find("li").hover(
			function(e) { $(this).find("span.deleteBtn").fadeIn("fast"); },
			function(e) { $(this).find("span.deleteBtn").fadeOut("fast"); }
		);
		$n.commbar.loadPageLayer(box.find(".commLayerBtm"), page, data.cnt, "$n.commbar.loadNoticePage");
	},
	loadNoticePage : function(page) {
		$n.commbar.listNotice.loadList({page:page});
	},
	tmpnoticelist : '<%if(!$n.object.empty(obj)){ %>' +
	'<% for(var key in obj.list) { var item = obj.list[key];  %>' +
	'<li id="__notice_item_<%=item.notice_id%>" class="<%=item.readClass%> <%=item.className%>">' +
	'<p><%=item.MESSAGE%> '+
	'<span class="time"><%=item.noticeDate%></span> '+
	'<%=item.MESSAGE2%></p> '+
	'<span class="deleteBtn" style="display:none;"><a href="javascript:$n.commbar.deleteNotice(\'<%=item.notice_id%>\', <%=obj.page%>);"><img src="<%=_staticImgUrl%>/common/commbar/bc_deleteOff.gif" onmouseover="imgOver(this)" onmouseout="imgOut(this)" alt="»èÁ¦" /></a></span>'+
	'</li>' +
	'<% } %>'+
	'<% } else {  %>' + 
	'<li class="noList">»õ ¾Ë¸²ÀÌ ¾ø½À´Ï´Ù.</li>' +
	'<% } %>' + 
	'',
	deleteNotice : function(notice_id, page) {
		if(typeof notice_id == "undefiend") return;
		if(typeof page == "undefined") page = 1;
		var _url = $n.properties.commbar.urlNoticeDel;
		if ($n.properties.commbar.service == "rose")
			_url += "/"+notice_id;
		else
			_url += "&noticeId="+notice_id;
		$.getJSON(_url, function(data){
			if(data == 1) {
				//$n.commbar.listNotice.hide();
				$n.commbar.listNotice.loadList(page);
				//$n.commbar.noticeCount();
			}
		});
	},
	clickFriendChkBox : function() {
		$n.commbar.listFriend.loadList();
	},
	loadFriendData : function(box, page, success, error) {
		if(typeof page == "undefined") page = 1;
		
		$n.commbar.defaultMenu("friend");
		// ÀüÃ¼ º¸±â ¸µÅ©¸¦ º¯È¯
		box.find(".commLayerBtm .more a").attr("href", _staticUrl + "/admin/friends/view");
		
		box.find(".chkCjList, #idChkOnlineCj").hide();
		box.find(".chkFriendList, #idChkOnlineFriend").show();
		
		
		var _url = $n.properties.commbar.urlFriendList;
		var _checked = $('#commOnlyFrOnline').get(0).checked?'Y':'N';
		if ($n.properties.commbar.service == "rose")
			_url += "/" + _checked + "/" + page + "/" + $n.commbar.PAGE_ROW;
		else
			_url += "&page="+page+"&rowCnt="+$n.commbar.PAGE_ROW+"&online="+_checked;
			
		$.getJSON(_url, success.bind($n.commbar.listFriend, box, page));
		//cookie
		$n.commbar.removeCookieFriend();
		// when document is clicked, will hide list layer
		$(document).bind("click", $n.commbar.hideListWhenDocumentClick);

	},
	loadFriendDataSuccess : function(box, page, data) {
		if(data == null) data = {cnt:0,list:[]};
		box.find(".chkFriendList em:first").text(data.onlineCnt);
		box.find(".chkFriendList em:last").text(data.onlineCjCnt);
		var _tmp = new $n.template($n.commbar.tmpflist, data.list);
		$n.commbar.listFriend.addList($(_tmp.html()))
		
		$n.commbar.loadPageLayer(box.find(".commLayerBtm"), page, data.cnt, "$n.commbar.loadFriendPage");
		
		$n.commbar._friendDataToList(data.list);
	},
	loadFriendPage : function(page) {
		$n.commbar.listFriend.loadList({page:page});
	},
	clickCjChkBox : function() {
		$n.commbar.listFriend.loadList({
			load:$n.commbar.loadCjData, success:$n.commbar.loadCjDataSuccess
		});
	},
	_friendDataToList : function(friends) {
		if($n.object.empty(friends)) return;
		$n.commbar.friendList = []; 
		for (var key in friends) { 
			var item = friends[key];
			$n.commbar.friendList.push({
				msrl :  key,
				usrid : item.MEMBER_ID,
				nickname : item.MEMBER_NICKNAME,
				user_feeling : item.user_feeling 
			});
		}
	},
	loadCjData : function(box, page, success, error) {
		if(typeof page == "undefined") page = 1;
		// ÀüÃ¼ º¸±â ¸µÅ©¸¦ º¯È¯
		box.find(".commLayerBtm .more a").attr("href", _staticUrl + "/admin/starcj/cjlist");
		box.find(".chkFriendList, #idChkOnlineFriend").hide();
		box.find(".chkCjList, #idChkOnlineCj").show();
		
		var _url = $n.properties.commbar.urlCjList;
		var _checked = $('#commOnlyCjOnline').get(0).checked?'Y':'N';
		if ($n.properties.commbar.service == "rose")
			_url += "/" + _checked + "/" + page + "/" + $n.commbar.PAGE_ROW;
		else
			_url += "&page="+page+"&rowCnt="+$n.commbar.PAGE_ROW+"&online="+_checked;
		
		$.getJSON(_url, success.bind($n.commbar.listFriend, box, page));
	},
	loadCjDataSuccess : function(box, page, data) {
		if(data == null) data = {cnt:0,list:[]};
		box.find(".chkCjList em:first").text(data.onlineFrCnt);
		box.find(".chkCjList em:last").text(data.onlineCnt);
		var _tmp = new $n.template($n.commbar.tmpcjlist, data.list);
		$n.commbar.listFriend.addList($(_tmp.html()));
		$n.commbar.loadPageLayer(box.find(".commLayerBtm"), page, data.cnt, "$n.commbar.loadCjPage");
	},
	loadCjPage : function(page) {
		$n.commbar.listFriend.loadList({
			page:page, load:$n.commbar.loadCjData, success:$n.commbar.loadCjDataSuccess
		});
	},
	tmpflist : '<%if(!$n.object.empty(obj)){ %>' + 
	'<% for (var key in obj) { var item = obj[key];  %>' +
	'<li <%if(item.COMM_ONLINE) {%>class="online"<% } %> ><dl>' +
	'<dt><%=item.iconimg%></dt>'+
	'<dd class="msg">'+
	'<div><a href="http://me.sayclub.com/profile/r/msrl/<%=key%>" class="nameLink"><%=item.MEMBER_NICKNAME%></a> <% if(item.onair){ %><span><img src="<%=_staticImgUrl%>/common/ic_onairS.gif" class="onair" alt="ON AIR" /> <a href="<%=item.onair.listenUrl%>" title="¹æ¼Ûµè±â"><img src="<%=_staticImgUrl%>/common/button/bc_listenSOff.gif" onmouseover="imgOver(this)" onmouseout="imgOut(this)" alt="¹æ¼Ûµè±â" /></a></span><% } %></div>'+
	'<p><%if(item.user_feeling && item.user_feeling != null) {%><%=$n.utils.cutbytestring1(item.user_feeling.feeling, 28)%><%}%></p>' +
	'</dd>' +
	'<dd class="goProfile"><a href="<%=_staticUrl%>/profile/home/view/<%=item.MEMBER_ID%>" title="ÇÑ¸¶µð">ÇÑ¸¶µð</a></dd>' +
	'</dl>' +
	'</li>' +
	'<% } %>'+
	'<% } else { %>' + 
	'<li class="noList">Á¢¼Ó ÁßÀÎ ¼­·Î Ä£±¸°¡ ¾ø½À´Ï´Ù.</li>' +
	'<% } %>', 
tmpcjlist : '<%if(!$n.object.empty(obj)){ %>' + 
	'<% for(var key in obj) { var item = obj[key];  %>' +
	'<li <%if(item.COMM_ONLINE) {%>class="online"<% } %>><dl>' +
	'<dt><%=item.iconimg%></dt>'+
	'<dd class="msg">'+
	'<div><a href="http://me.sayclub.com/profile/r/msrl/<%=key%>" class="nameLink"><%=item.userInfo.MEMBER_NICKNAME%></a> <% if(item.onair){ %><span><img src="<%=_staticImgUrl%>/common/ic_onairS.gif" class="onair" alt="ON AIR" /> <a href="<%=item.onair.listenUrl%>" title="¹æ¼Ûµè±â"><img src="<%=_staticImgUrl%>/common/button/bc_listenSOff.gif" onmouseover="imgOver(this)" onmouseout="imgOut(this)" alt="¹æ¼Ûµè±â" /></a></span><% } %></div>'+
//	'<p><%=$n.utils.cutstring1(item.cjInfo.cjment, 15)%></p>' +
	'<p><%if(item.user_feeling && item.user_feeling != null) {%><%=$n.utils.cutbytestring1(item.user_feeling.feeling, 28)%><%}%></p>'+
	'</dd>' +
	'<dd class="goProfile"><a href="<%=_staticUrl%>/profile/home/view/<%=item.userInfo.MEMBER_ID%>" title="ÇÑ¸¶µð">ÇÑ¸¶µð</a></dd>' +
	'</dl>' +
	'</li>' +
	'<% } %>'+
	'<% } else { %>' + 
	'<li class="noList">Á¢¼Ó ÁßÀÎ ½ºÅ¸CJ°¡ ¾ø½À´Ï´Ù.</li>' +
	'<% } %>' + 
	'',
	loadPageLayer : function(pageLayer, page, totalCnt, funcName) {
		var row = $n.commbar.PAGE_ROW, pageCnt = 5; 
		var totalPage = $n.math.ceil(totalCnt/row);
		var startPage = $n.math.floor((page - 1) / pageCnt)*pageCnt+1;
		var endPage = ($n.math.floor((page - 1) / pageCnt) + 1)*pageCnt;
		if(endPage > totalPage) endPage = totalPage;
				
		var _pageTmp = new $n.template($n.commbar.tmppage, {
			page: page, 
			row: row, 
			cnt: totalCnt,
			pageCnt : pageCnt,
			startPage : startPage,
			endPage : endPage,
			totalPage:totalPage,
			funcName : funcName
		});
		if(_pageTmp.html() != "")
			pageLayer.append($(_pageTmp.html()));
			
	},
	tmppage : '<%if(obj.cnt > 0) {%><div class="layerPager">' +
		'<%if(obj.page > obj.pageCnt){%><a href="javascript:<%=obj.funcName%>(1);" title="Ã³À½"><img src="<%=_staticImgUrl%>/common/button/bp_layerFirst.gif" alt="Ã³À½" class="first" /></a><%}%>' +
		'<%if(obj.page > obj.pageCnt){%><a href="javascript:<%=obj.funcName%>(<%=(obj.startPage - obj.pageCnt)%>);" class="prev"><img src="<%=_staticImgUrl%>/common/button/bp_layerPrev.gif" alt="ÀÌÀü" class="prev" /></a><%}%>'+
		'<% for(var ii=obj.startPage;ii<obj.endPage+1;ii++) { %>' +
		'<% if(obj.page == ii) { %>' +
		'<a href="javascript:<%=obj.funcName%>(<%=ii%>);" class="selected"><span><%=ii%></span></a>' +
		'<% } else { %>' +
		'<a href="javascript:<%=obj.funcName%>(<%=ii%>);" class="number"><span><%=ii%></span></a>'+
		'<% } %>' +
		'<%if(obj.endPage != ii){%> | <%}%>' +
		'<% } %>' +
		'<%if(obj.endPage < obj.totalPage){%><a href="javascript:<%=obj.funcName%>(<%=obj.endPage+1%>);" class="next" title="´ÙÀ½"><img src="<%=_staticImgUrl%>/common/button/bp_layerNext.gif" alt="´ÙÀ½" class="next" /></a><%}%>' +
		'<%if(obj.endPage < obj.totalPage){%><a href="javascript:<%=obj.funcName%>(<%=obj.totalPage%>);" class="last" title="¸¶Áö¸·"><img src="<%=_staticImgUrl%>/common/button/bp_layerLast.gif" alt="¸¶Áö¸·" class="last" /></a><%}%>' +
		'</div><% } %>',
	setInitData : function() {
		//$n.commbar.friendCount();
		//$n.commbar.memoCount();
		//$n.commbar.noticeCount();
	}, 
	friendCount : function() {
		var _url = $n.properties.commbar.urlFriendCnt;
		$.getJSON(_url, function(data){
			$n.commbar.friendCountPanel(data); 	
			$('#numFriend').fadeIn();
		});
	}, 
	memoCount : function() {
		var _url = $n.properties.commbar.urlMemoCnt;
		$.getJSON(_url, function(data){
			$n.commbar.memoCountPanel(data);
			$('#numMemo').fadeIn();
		});
	}, 
	noticeCount : function() {
		var _url = $n.properties.commbar.urlNoticeCnt;
		$.getJSON(_url, function(data){
			$n.commbar.noticeCountPanel(data);
			$('#numNotice').fadeIn();
	});		
		
	},
	memoCountPanel : function(cnt) {
		$('#numMemo .number').text(cnt);
	},
	friendCountPanel : function(cnt) {
		$('#numFriend .number').text(cnt);
	},
	noticeCountPanel : function(cnt) {
		$('#numNotice .number').text(cnt);
	},
	friendList : [],
	timeoutFriendRand : null,
	intervalFriendRand : null,
	initFriendRand : function() {
		$n.commbar.friendRandState = $n.commbar.commbar.find(".friendState");
		$n.commbar.loadInitFriendRand();
		$n.commbar.intervalFriendRand = setInterval($n.commbar.loadInitFriendRand, 1000*60*3);
		setTimeout(function() {
			if($n.commbar.intervalFriendRand != null) {
				clearInterval($n.commbar.intervalFriendRand);
			}
		}, 1000*60*10);
	},
	loadInitFriendRand : function() {
		var url = $n.properties.commbar.urlFriendRand;
		$.ajax({
			url : url, dataType : "json", type : "GET",
			success : function(data){
				if(data && data.friend && data.friend != null && !$n.object.empty(data.friend)) {
					$n.commbar.commbar.find(".friendState").show();
					$n.commbar.friendList = []; 
					for (var key in data.friend) {
						$n.commbar.friendList.push(data.friend[key]);
					}
					$n.commbar.loadFriendRand();
				}
			},
			error : function(req, status, err) {
				//alert(status);
			}
		});
	},
	loadFriendRand : function() {
		var len = $n.commbar.friendList.length;
		if(len == 0) {
			$n.commbar.commbar.find(".friendState").hide();
			return;
		}
		var user = $n.commbar.friendList[$n.math.random(len-1)];
		$n.commbar.commbar.find(".friendState").show();
		$n.commbar.setViewFriendRand({cnt:1,friend:user});
	},
	setViewFriendRand : function(data) {
		if(!data || !data.friend) return;
		var ul = $n.commbar.friendRandState.find("ul");
		//ul.css("position", "absolute");
		var _callback = function() {
			var feeling = "";
			if(data.friend.user_feeling && data.friend.user_feeling.feeling) {
				var nickSize = $n.utils.byteSize(data.friend.nickname, 1.8);
				feeling = " " + $n.utils.cutbytestring1(data.friend.user_feeling.feeling, 34-nickSize, 1.8);
			}
			ul.find("li a").
				attr("href", _staticUrl + "/profile/home/view/"+data.friend.usrid)
				.html("<strong>"+data.friend.nickname+"</strong>"+feeling);
			ul.fadeIn("normal", function() {
				$n.commbar.setViewFriendRandAfter(data);
			});
		};
		if($n.visible(ul)) ul.fadeOut("normal", _callback);
		else _callback(); 
	},	
	setViewFriendRandAfter : function(data) {
		if($n.commbar.timeoutFriendRand != null) {
			clearTimeout($n.commbar.timeoutFriendRand);
			$n.commbar.timeoutFriendRand = null;
		}
		$n.commbar.timeoutFriendRand = setTimeout(function() {
			$n.commbar.loadFriendRand(data.friend.msrl);
		} ,5000);
	},
	callNoticeBox: function() {
		$n.commbar.showMsgBox();
	}, 
	hideListWhenDocumentClick : function(e) {
		if($(".commLayer *, #commbarWrap .menu *, #commbarWrap .menuSelect *").index(e.target) < 0) {
			$n.commbar.listNotice.hide();
			$n.commbar.listMsg.hide();
			$n.commbar.listFriend.hide();
			$(document).unbind("click", $n.commbar.hideListWhenDocumentClick);
		}
	},
	visible : function(jE) {
		var _is_display = true;
		jE.each(function() {if(this.style.display == "none") _is_display = false;} )
		return _is_display;
		 
	},
	_setCommbarCount : function(name, cnt) {
		if(typeof(name) == "undefined" || typeof(cnt) == "undefined") return null;
		return $n.commbar.commbar.find("ul li."+name+" span").html(cnt);
	}, 
	alertMenu : function(menuClass) {
		if(menuClass == "friend") $n.commbar.friendCount();
		else if(menuClass == "msg") $n.commbar.memoCount();
		else if(menuClass == "notice") $n.commbar.noticeCount();		
	},
	defaultMenu : function(menuClass) {
		$("#commbar .menu li."+menuClass+" div").removeClass().addClass("default");
		if(menuClass == "friend") $("#numFriend").hide();
		else if(menuClass == "msg") $("#numMemo").hide();
		else if(menuClass == "notice") $("#numNotice").hide();
	},
	setCookieFriend : function() { $n.cookie.set("_cbnF", "Y", null, "/", "sayclub.com"); },
	setCookieMemo : function() { $n.cookie.set("_cbnM", "Y", null, "/", "sayclub.com"); },
	setCookieNotice : function() { $n.cookie.set("_cbnN", "Y", null, "/", "sayclub.com"); },
	setCookieFriendCnt : function(cnt) { 
		$n.cookie.set("_cbnFC", "Y", null, "/", "sayclub.com"); 
	},
	setCookieMemoCnt : function(cnt) { 
		$n.cookie.set("_cbnMC", "Y", null, "/", "sayclub.com"); 
	},
	removeCookieFriend : function() { $n.cookie.set("_cbnF", "", null, "/", "sayclub.com"); },
	removeCookieMemo : function() { $n.cookie.set("_cbnM", "", null, "/", "sayclub.com"); },
	removeCookieNotice : function() { $n.cookie.set("_cbnN", "", null, "/", "sayclub.com"); },
	removeCookieFriendCnt : function() { $n.cookie.set("_cbnFC", "", null, "/", "sayclub.com"); },
	removeCookieMemoCnt : function() { $n.cookie.set("_cbnMC", "", null, "/", "sayclub.com"); },
	isCookieFriend : function() {
		var _ck = $n.cookie.get("_cbnF");
		return (_ck && typeof _ck != "undefined" && _ck == "Y");
	},
	isCookieMemo : function() {
		var _ck = $n.cookie.get("_cbnM");
		return (_ck && typeof _ck != "undefined" && _ck == "Y");
	},
	isCookieNotice : function() {
		var _ck = $n.cookie.get("_cbnN");
		return (_ck && typeof _ck != "undefined" && _ck == "Y");
	},
	getCookieFriendCnt : function() {
		var _cnt = $n.cookie.get("_cbnFC");
		if(typeof _cnt != "undefined" && _cnt != "" && $n.valid.num(_cnt))
			return _cnt;
//		else throw("no value");
		else return "";
	},
	notifyFriend : {
		login :	function() {
			$n.commbar.alertMenu("friend");
			$n.commbar.friendCount();
			$n.commbar.setCookieFriend();
		},
		logout : function() {
			$n.commbar.friendCount();
		}
	},
	notifyNotice : function() {
		$n.commbar.alertMenu("notice");
		$n.commbar.noticeCount();
		$n.commbar.soundNotice();
		$n.commbar.setCookieNotice();
	},
	notifyMsg : function() {
		$n.commbar.alertMenu("msg");
		$n.commbar.memoCount();
		$n.commbar.setCookieMemo();
	},
	notifySayAlert : {
		ad : function(imgSrc, link) {
			$n.commbar.alerts.addad(imgSrc, link);
			$n.commbar.soundSayAlert();

		},
		cast : function(filestr, mood, html, link) {
			$n.commbar.alerts.addcast(filestr, mood, html, link);
			$n.commbar.soundSayAlert();
		},
		feed : function(bodyClass, html, link) {
      bodyClass += " line3";
			$n.commbar.alerts.addfeed(bodyClass, html, link);
			$n.commbar.soundSayAlert();

		},
		friend : function(html, link) {
			$n.commbar.notifySayAlert.feed("friend", html, link);
			$n.commbar.soundSayAlert();

		},
		hompy : function(html, link) {
			
			$n.commbar.notifySayAlert.feed("hompy", html, link);
			$n.commbar.soundSayAlert();
		},
    chat : function(html, link, layer_type) {
      if(layer_type == "vi") {
        bodyClass = "bang line4";
      } else if(layer_type == "zi") {
        bodyClass = "zzim line4";
      } else {
        bodyClass = "memo line4";
      }
      $n.commbar.alerts.addchat(bodyClass, html, link);
      $n.commbar.soundSayAlert();
    },
		recommendCast : function(nickname, title, link, url) {
			$n.commbar.alerts.addrecommendcast(nickname, title, link, url);
			$n.commbar.soundSayAlert();
		}
	},
	emptylist : function(obj) {
		if($n.object.empty(obj)) return true;
		if(obj.list && obj.list[0] && obj.list.length > 0) return false;
		return true;
	},
	soundSayAlert : function() {
//		var player = document.getElementById("CommbarSoundEffect");
//		if(player && player.controls)
//			player.controls.play();
	},
	soundNotice : function() {
//		var player = document.getElementById("CommbarSoundNotice");
//		if(player && player.controls)
//			player.controls.play();
	},
	noticeRead : function(notice_id, readYN) {
		if(!notice_id) return;
		if(!readYN) readYN = "N";
		if(readYN == "Y") return;
		
		var _url = $n.properties.commbar.urlNoticeRead +"/"+notice_id;
		$.getJSON(_url);
	},
	noticeToFriend : function(to_friend_id, readYN) {
		if(!to_friend_id) return;
		if(!readYN) readYN = "N";
		if(readYN == "Y") return;
		
		var _url = $n.properties.commbar.urlFriendRead +"/"+to_friend_id;
		$.getJSON(_url);
	},	
	temp : function() {}
};

$n.commbar.sayalerts = $n.create();
$n.commbar.sayalerts.prototype = {
	boxes : [],
	initialize : function() {},
	getOption : function() {
		return {
			positionBottom : $("#commbarWrap").height(), 
			startHeight : this.height(), 
			alerts : this
		};
	},
	addfeed : function(bodyClass, html, link) {
		this._add(new $n.commbar.feedalert(
			{bodyClass : bodyClass, html : html, link : link}, this.getOption()
		));
	},
  addchat : function(bodyClass, html, link) {
    if(inChatSite=='chat2say'){
      this._add(new $n.commbar.feedalertchat(
        {bodyClass : bodyClass, html : html, link : link}, this.getOption()
      ));
    }
  },
	addad : function(imgSrc, link) {
		this._add(new $n.commbar.adalert(
			{imgSrc : imgSrc, link : link}, this.getOption()
		));
	},
	addcast : function(filestr,mood, html, link) {
		var character = ItemHandler.getAvatarFromFilestr(filestr,mood,60,60);
		this._add(new $n.commbar.castalert(
			{character : character, html : html, link : link}, this.getOption()
		));
	},
	addrecommendcast : function(nickname, title, link, url) {
		this._add(new $n.commbar.recommendcastalert(
				{nickname : nickname, title : title, link : link, ajaxUrl : url}, 
				$n.overed( this.getOption(), {colseDelayTime : 8000})
		));
	},
	_add : function(service) {
		service.load();
		this.boxes.push(service);
	},
	height : function() {
		var _height = $("#commbarWrap").height();
		for(var i=0;i<this.boxes.length;i++) {
			if(this.boxes[i].visible()) _height += this.boxes[i].height();
		}
		return _height;
	},
	movePosition : function() {
		var _bt = $("#commbarWrap").height();
		for(var k=0;k<this.boxes.length;k++) {
			this.boxes[k]._wrapper.animate({"bottom":_bt});
			_bt += this.boxes[k].height();
		}
	},
	_temp : null
}


$n.commbar.sayalert = $n.create();
$n.commbar.sayalert.prototype = {
	initialize : function(value, option) {
		this.value = value;
		this.option = $n.overed({
			positionRight : 0,
			positionBottom : 0,
			colseDelayTime : 3000,
			holdMouseOver : true,
			speed : 800
		}, option || {});
		if(this.makeitem)
			this.makeitem();
		this.initItem();
	}, 
	initItem : function() {
		if(this.option.holdMouseOver) {
			this._wrapper.mouseover( function(e) {
				if(this.hideTimeout != null) {
					clearTimeout(this.hideTimeout);
					this.hideTimeout = null;
				}
			}.bind(this));
			this._wrapper.mouseout( function(event) {
				if(this.option.colseDelayTime > 0) {
					this.hideTimeout = setTimeout(this.hide.bind(this), this.option.colseDelayTime);
				}
			}.bind(this));
		}
		$(window).resize(this.hold.bind(this));
		if($.browser.msie && $.browser.version < 7) {
			$(window).scroll(this.holdIe6.bind(this));
		}
		
	},
	load : function() {
		if(this.loaditem)
			this.loaditem();
		$("#commbarWrap").parent().append(this._wrapper);
		if($.browser.msie && $.browser.version < 7) {
			this._wrapper.css({"position": "absolute", "left": this.rightPosition(), "top":this.topPositionForIe6()});
		} else {
			this._wrapper.css({"left": this.rightPosition(), "bottom":this.option.startHeight});
		}
		this.show();
	},
	height : function() { return this._wrapper.height(); },
	show : function() {
		
		this._wrapper.fadeIn(this.option.speed, function() {
			if(this.option.colseDelayTime > 0) {
				this.hideTimeout = setTimeout( this.hide.bind(this), this.option.colseDelayTime);
			}
		}.bind(this));
		$n.commbar.soundSayAlert();
	},
	hide : function(__afterRemove) {
		var _callback = function() {
			if(this.option.alerts) {
				var _temp = [];
				for(var i=0;i<this.option.alerts.boxes.length;i++) {
					if(this != this.option.alerts.boxes[i]) _temp.push(this.option.alerts.boxes[i]);
				}
				this.option.alerts.boxes = _temp;
				this.option.alerts.movePosition();
			}
			this.remove();
			if(__afterRemove && typeof __afterRemove == "function") {
				__afterRemove();
			}
		}
		this._wrapper.fadeOut(this.option.speed, _callback.bind(this));
	},
	hold : function() {
		if(this._wrapper) {
			var right = this.rightPosition();
			this._wrapper.stop();
			this._wrapper.animate({"left": right });
			if($.browser.msie && $.browser.version < 7) {
				this.holdIe6();
			}
		}
	},
	holdIe6 : function() {
		this._wrapper.css({
			"position": "absolute", 
			"top":this.topPositionForIe6()}
		);
	},
	remove : function() { this._wrapper.remove(); },
	visible : function() { return $n.commbar.visible(this._wrapper); },
	topPositionForIe6 : function() {
		return $(document).scrollTop() + $(window).height() - this.height() - this.option.startHeight;
		
	},
	rightPosition : function() {
		var _commbar = $n.commbar.commbar;
		var _gap = 0;
		return _commbar.position().left + _commbar.width() - this._wrapper.width() - this.option.positionRight;
	},
	_temp : null
	
}

$n.commbar.feedalert = $n.create();
$n.commbar.feedalert.prototype = {
	makeitem : function() {
		this._wrapper = $("<div></div>").addClass("doongFeed").css({"position":"fixed"}).hide();
		this._bg = $("<div></div>").addClass("bg").appendTo(this._wrapper);
		this._body = $("<div></div>").addClass(this.value.bodyClass);
		this._del = $('<a href="javascript:void(0);"><img onmouseover="imgOver(this)" onmouseout="imgOut(this)" alt="´Ý±â" /></a>').addClass("close").click(this.hide.bind(this));
		//this._del = $('<a href="javascript:void(0);"><img alt="´Ý±â" /></a>').addClass("close").click(this.hide.bind(this));
		this._del.find("img").attr("src", $n.commbar.option.sayAlertCloseImg);
		this._bg.append(this._body).append(this._del);
	}, 
	loaditem : function() {
		var _link = $("<a></a>").html(this.value.html).attr("href", this.value.link);
		this._body.append(_link);
	},
	height : function() {
		return 88;
	}
};
$n.extend($n.commbar.feedalert, $n.commbar.sayalert);

$n.commbar.feedalertchat = $n.create();
$n.commbar.feedalertchat.prototype = {
  makeitem : function() {
    this._del = $('<a href="javascript:void(0);"><img onmouseover="imgOver(this)" onmouseout="imgOut(this)" alt="´Ý±â" /></a>').addClass("close").click(this.hide.bind(this));
    if(this.value.bodyClass == "bang line4")
      this._tit = "¹æ¹®ÀÚ ¾Ë¸²!";
    if(this.value.bodyClass == "zzim line4")
      this._tit = "Âò ¾Ë¸²!";
    if(this.value.bodyClass == "memo line4")
      this._tit = "»õ±Û ¾Ë¸²!";
    this._wrapper = $("<div></div>").addClass("doongFeed2").css({"position":"fixed"}).hide();
    this._bg = $("<div></div>").addClass("bg").appendTo(this._wrapper);
    this._title = $("<div></div>").append(this._tit).addClass("btitle").append(this._del);
    this._body = $("<div></div>").addClass(this.value.bodyClass);
    this._del.find("img").attr("src", $n.commbar.option.sayAlertCloseImg);
    this._bg.append(this._title).append(this._body);
  },
  loaditem : function() {
    var _link = $("<a></a>").html(this.value.html).attr("href", this.value.link);
    this._body.append(_link);
    this._title.html(this.value.title);
  },
  height : function() {
    return 125;
  }
};
$n.extend($n.commbar.feedalertchat, $n.commbar.sayalert);


$n.commbar.castalert = $n.create();
$n.commbar.castalert.prototype = {
	makeitem : function() {
		this._wrapper = $("<div></div>").addClass("doongCast").css({"position":"fixed"}).hide();
		this._bg = $("<div></div>").addClass("bg").appendTo(this._wrapper);
		this._character = $("<div></div>").addClass("character62");
		this._body = $("<div></div>").addClass("desc");
		this._del = $('<a href="javascript:void(0);"><img alt="´Ý±â" /></a>').addClass("close").click(this.hide.bind(this));
		this._del.find("img").attr("src", $n.commbar.option.sayAlertCloseImg);
		this._bg.append(this._character).append(this._body).append(this._del);
	}, 
	loaditem : function() {
		var _link = $("<a></a>").html(this.value.html).attr("href", this.value.link);
		this._body.append(_link);
		this._character.html(this.value.character);
	},
	height : function() {
		return 88;
	}
};
$n.extend($n.commbar.castalert, $n.commbar.sayalert);

$n.commbar.recommendcastalert = $n.create();
$n.commbar.recommendcastalert.prototype = {
	makeitem : function() {
		var _tmp = new $n.template(this.tmpsource, this.value);
		this._wrapper = $("<div></div>").addClass("doongRecommCast").css({"position":"fixed"}).hide();
		this._bg = $("<div></div>").addClass("bg").appendTo(this._wrapper);
		this._body = $(_tmp.html());
		this._del = $('<div><a href="javascript:void(0);"><img alt="´Ý±â" /></a></div>').addClass("close").click(this.hide.bind(this));
		this._del.find("img").attr("src", $n.commbar.option.sayAlertCloseImg);
		this._bg.append(this._body).append(this._del);
	}, 
	loaditem : function() {
		this._wrapper.find(".otherLink a").click(this.anotherMusic.bind(this));
	},
	anotherMusic : function() {
		try {
			$.getJSON(this.value.ajaxUrl, this.anotherMusicCallback.bind(this));
		} catch(ex) {}
	},
	anotherMusicCallback : function(data) {
		this._wrapper.find(".music span a, .btn a").attr("href", data.link);
		this._wrapper.find(".music span a").text($n.utils.cutstring1(data.title, 14));
	},
	tmpsource : '<p><strong><%=obj.nickname%></strong>´Ô~<br/>ÀÌ À½¾Ç ÇÑ¹ø µé¾îº¸½Ã°Ú¾î¿ä?</p>'+
		'<div class="music"><span><a href="<%=obj.link%>" title="¹æ¼Ûµè±â"><%=$n.utils.cutstring1(obj.title, 14)%></a></span>'+
		'<div class="btn"><a href="<%=obj.link%>" title="¹æ¼Ûµè±â"><img src="http://filei.sayclub.kr/rose/common/commbar/i_doongPlay.gif" alt="¹æ¼Ûµè±â"/></a></div></div>'+
		'<div class="otherLink"><a href="javascript:void(0);" title="´Ù¸¥ À½¾Ç ¾ø³ª¿ä?">´Ù¸¥ À½¾Ç ¾ø³ª¿ä?</a></div>'+
		'',
	height : function() {
		return 88;
	}
};
$n.extend($n.commbar.recommendcastalert, $n.commbar.sayalert);

$n.commbar.adalert = $n.create();
$n.commbar.adalert.prototype = {
	makeitem : function() {
		this._wrapper = $("<div></div>").addClass("doongAD").css({"position":"fixed"}).hide();
		this._bg = $("<div></div>").addClass("bg").appendTo(this._wrapper);
		this._body = $("<a></a>").addClass(this.value.bodyClass);
		this._bg.append(this._body);
	}, 
	loaditem : function() {
		var _link = $("<a></a>").append($("<img/>").attr("src", this.value.imgSrc)).attr("href", this.value.link);
		this._body.append(_link)
	},
	height : function() {
		return 190;
	}
};
$n.extend($n.commbar.adalert, $n.commbar.sayalert);


$n.commbar.listboxes = $n.create();
$n.commbar.listboxes.prototype = {
	boxes : [],
	initialize : function() {},
	add : function(box) { this.boxes.push(box);	},
	_temp : null
}


$n.commbar.listbox = $n.create();
$n.commbar.listbox.prototype = {
	hideTimeout : null,
	overClass : "over",
	outClass : "default",
	newOverClass : "newOver",
	newOutClass : "newOut",
	initialize : function(box, option) {
		this.box = box;
		this.option = $n.overed({
			positionRight : 0, positionBottom : 31, colseDelayTime : 0, holdMouseOver : false, 
			loadData : function() {}, success : function() {}, error : function() {},
			listClass : null
		}, option || {});
		this.list = $("<ul/>").appendTo(this.box.eq(0).find(".commLayerBg"));
		if(this.option.listClass != null)
			this.list.addClass(this.option.listClass);
		
		this.load();
	},
	load : function() {
		if(this.option.holdMouseOver) {
			this.initBox();
		}
		this.box.eq(0).css("left", this.rightPosition());
//		this.box.eq(1).css("left", this.menuRightPosition());
		$(window).resize(this.hold.bind(this));
	},
	loadList : function(_opt) {
		this.reset();
//		var _prc = $('<p class="loading">·Îµù Áß ÀÔ´Ï´Ù.</p>').appendTo(this.box.eq(0).find(".commLayerBg"));
		var _prc = $('<li class="loading" style="margin-top:142px;border:0px;"><img src="http://filei.sayclub.kr/rose/common/ia_loading.gif"/> ·Îµù Áß ÀÔ´Ï´Ù.</li>').appendTo(this.list);
		var opt = $n.overed(
			{page:1, load : this.option.loadData, success : this.option.success, error : this.option.error }, _opt
		);
		opt.load(this.box, opt.page,
			function() { _prc.remove(); opt.success.apply(this, arguments); },	
			function() { _prc.remove(); opt.error.apply(this, arguments); }
		);
	},
	show : function() {
		this.loadList();
		
		this.box.eq(0).css({"bottom":this.option.positionBottom});
		var ll = $n.commbar.listboxList.boxes;
		for(var i=0;i<ll.length;i++) {
			if(ll[i].visible()) { ll[i].hide(); }
		}
		this.box.fadeIn("fast", function() {
			if(this.option.colseDelayTime > 0) {
				this.hideTimeout = setTimeout( this.hide.bind(this), this.option.colseDelayTime);
			}
		}.bind(this)); 
	},
	hide : function() { this.box.fadeOut("fast"); },
	hold : function() {
		if(this.box) {
			var right = this.rightPosition();
			this.box.eq(0).stop();
			this.box.eq(0).animate({"left": right });
//			this.box.eq(1).animate({"left": this.menuRightPosition() });
		}
		
	},
	height : function() { this.box.height(); },
	rightPosition : function() {
		var _commbar = $n.commbar.commbar;
		var _gap = 0;
		return _commbar.position().left + _commbar.width() - this.box.eq(0).width() - this.option.positionRight + 2;
	},
	menuRightPosition : function() {
		return $n.commbar.commbar.width() - this.box.eq(1).width() - this.option.positionRight + 2;
	},
	initBox : function() {
		this.box.mouseover( function(e) {
			if(this.hideTimeout != null) {
				clearTimeout(this.hideTimeout);
				this.hideTimeout = null;
			}
		}.bind(this));
		this.box.mouseout( function(event) {
			if(this.option.colseDelayTime > 0) {
				this.hideTimeout = setTimeout(this.hide.bind(this), this.option.colseDelayTime);
			}
		}.bind(this));
		
	},
	reset : function() {
		this.box.eq(0).find("ul li, p, .layerPager").remove();
	}, 
	addList : function(resultList) {
		if(this.option.listClass != null) resultList.hide();
		this.list.append(resultList);
		if(this.option.listClass != null) resultList.fadeIn("fast");
	},
	visible : function() { return $n.commbar.visible(this.box); },
	getPositionBottom : function() { return 0; },
	_tmp : null
};


