$n.properties = {
	commbar : {
		service : "rose",
		urlFriendList : _staticUrl + "/commbar/common/friends_list",
		urlFriendCnt : _staticUrl + "/commbar/common/friends_cnt",
		urlFriendRead : _staticUrl + "/commbar/common/friends_read",
		urlFriendRand : _staticUrl + "/commbar/common/friend_rand",
		urlFriendDel : _staticUrl + "/commbar/common/friend_del",
		urlCjList : _staticUrl + "/commbar/common/cj_list",
		urlMemoList : _staticUrl + "/commbar/common/memo_list",
		urlMemoCnt : _staticUrl + "/commbar/common/memo_cnt",
		urlMemoDel : _staticUrl + "/commbar/common/memo_del",
		urlNoticeList : _staticUrl + "/commbar/common/notice_list",
		urlNoticeCnt : _staticUrl + "/commbar/common/notice_cnt",
		urlNoticeRead : _staticUrl + "/commbar/common/notice_read",
		urlNoticeDel : _staticUrl + "/commbar/common/notice_del"
	}
}   
 


$n.commbar = {
	commbar : $('#commbar'),
	sayalert : null,
	PAGE_ROW : 30,
	ready : function(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.option.firstlogon) 
			$n.commbar.alertMenu("msg");
		if($n.commbar.isCookieNotice() || $n.commbar.option.firstlogon) 
			$n.commbar.alertMenu("notice");
		
		$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");
				}
			});
		//}
	},
	initMemoCnt : function() {
		var url = $n.properties.commbar.urlMemoCnt;
			$.getJSON(url, function(data){
				if(data == null) data = 0;
				if(data > 0) {
					$n.commbar.alertMenu("msg");
				}
			});
	},	
	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").text(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");
		
		if($n.commbar.option.actionNewPage) {
			$("#commNewMsgBox li .from a.nameLink").attr("target", "_blank");
		}

		
	},
	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"><%=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");
		
		if($n.commbar.option.actionNewPage) {
			$("#commNoticeBox li a:not([href^='javascript:'])").attr("target", "_blank");
			//$("#commNoticeBox li a.nameLink").attr("target", "_blank");
			//$("#commNoticeBox li .actionLink a:not([href^='javascript:'])").attr("target", "_blank");
		}
		
	},
	loadNoticePage : function(page) {
		$n.commbar.listNotice.loadList({page:page});
	},
	tmpnoticelist : '<%if(!$n.object.empty(obj) && !$n.object.empty(obj.list)){ %>' +
//	tmpnoticelist : '<%if(!$n.commbar.emptylist(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");
		
		if($n.commbar.option.actionNewPage) {
			$("#commFriendBox li .msg div a.nameLink").attr("target", "_blank");
			$("#commFriendBox li .goProfile a").attr("target", "_blank");
		}

		$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");
		
		if($n.commbar.option.actionNewPage) {
			$("#commFriendBox li .msg div a.nameLink").attr("target", "_blank");
			$("#commFriendBox li .goProfile a").attr("target", "_blank");
		}
	},
	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><% if(item.onair.broadcast){ %><img src="<%=_staticImgUrl%>/common/ic_onairS.gif" class="onair" alt="ON AIR" /><% }else{ %> <img src="<%=_staticImgUrl%>/common/ic_listenerB.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, 30)%><%}%></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, 30)%><%}%></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){
			if(data == null || data == "0") data = 0;
			if(data > 0) {
				$n.commbar.friendCountPanel(data); 	
				$('#numFriend').fadeIn();
			}
		});
	}, 
	memoCount : function() {
		var _url = $n.properties.commbar.urlMemoCnt;
		$.getJSON(_url, function(data){
			if(data == null || data == "0") data = 0;
			if(data > 0) {
				$n.commbar.memoCountPanel(data);
				$('#numMemo').fadeIn();
			}
		});
	}, 
	noticeCount : function() {
		var _url = $n.properties.commbar.urlNoticeCnt;
		$.getJSON(_url, function(data){
			if(data == null || data == "0") data = 0;
			if(data > 0) {
				$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();
		},
		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;
		var _url = $n.properties.commbar.urlNoticeDel +"/"+notice_id;
		$.getJSON(_url);
	},
	noticeToFriend : function(to_friend_id, readYN) {
		if(!to_friend_id) return;
		if(!readYN) readYN = "N";
		if(readYN == "Y") return;
		//alert('hi');
		var _url = $n.properties.commbar.urlFriendRead +"/"+to_friend_id;
		//var _url = $n.properties.commbar.urlFriendDel +"/"+to_friend_id;
		$.getJSON(_url);
	},	
	noticeToFriendBirth : function(to_friend_id, readYN) {
		if(!to_friend_id) return;
		if(!readYN) readYN = "N";
		if(readYN == "Y") return;
		//alert('hi');
		var _url = $n.properties.commbar.urlFriendRead +"/"+to_friend_id+"/Y";
		//var _url = $n.properties.commbar.urlFriendDel +"/"+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()
		));
	},
	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(doong) {
		doong.load();
		this.boxes.push(doong);
	},
	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.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 : 28, 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
};

