
/* popup */

function copyCafeRssChannel(server, grpid, grpname, rssurl) {
	var url = "http://cafe"+server+".daum.net/_c21_/founder_rss_board_management?grpid="+grpid+"&cmd=popCopyChannel&rssurl=" + rssurl + "&isCafeRss=Y";
	window.open(url, 'pop_rss', 'width=530,height=400,resizable=no,scrollbars=no');
}

var Daum = {
	ua: navigator.userAgent,
	isLayerShown: false,
	isLogin: false,
	
	resetLayer: function() {	// handler of Event::document.onclick
		if (this.isLayerShown) {
			this.isLayerShown = false;
		} else {
			this.Dom.removeOldDiv();
		}
	}
};

document.onclick = function() {
	Daum.resetLayer();
	var searchSug = document.getElementById('hFrame');
	if(searchSug) searchSug.style.display= 'none';
};

Daum.Dom = function() {
	var oldDiv = null;		// 마지막으로 block된 div의 id 속성 값
	return {
		setOldDiv: function(id) {
			oldDiv = id;
		},
		
		getOldDiv: function() {
			var id = oldDiv;
			return id;
		},
		
		removeOldDiv: function() {
			if (oldDiv) {
				document.getElementById(oldDiv).style.display = 'none';
			}
		},
		
		toggle: function(id, action, regist, delay) {
			Daum.isLayerShown = regist;
			var el = document.getElementById(id);
			
			if (oldDiv) {
				document.getElementById(oldDiv).style.display = 'none';
			}
			if (el) {
				if (delay) {
					setTimeout(function() {
						el.style.display = action;
					}, delay);
				} else {
					el.style.display = action;
				}
			}
			if (regist === true) {
				Daum.Dom.setOldDiv(id);
			}
		},
		
		// 단순하게 id를 block/none 처리
		simpleToggle: function(id) {
			var el = document.getElementById(id);
			
			if (el) {
				el.style.display = (el.style.display == 'block') ? 'none' : 'block'; 
			}
		}
	}
}();

Daum.Util = function() {	// common functions
	var pageInfo = {};
	return {
		addClassName: function(id, cls) {
			var target = document.getElementById(id);
			if (target) {
				target.className ? target.className + ' ' + cls : cls;
			}
		},
		
		rollingPage: function(key, direction, total) {
			var oldPage, curPage,
				flag = true;
			
			if (!pageInfo[key]) { pageInfo[key] = 1; }
			oldPage = pageInfo[key];
			
			if (direction == "next") {
				if(oldPage == total){
					flag = false;
				}else{
					curPage = parseInt(oldPage) + 1;
					if(curPage == total){
						document.getElementById(key + "_next").className = "no_next";
					}
					if(curPage != 1){
						document.getElementById(key + "_prev").className = "prev";
					}
				}
			} else {
				if(oldPage == "1"){
					flag = false;
				}else{
					curPage = parseInt(oldPage) - 1;
					if(curPage != total){
						document.getElementById(key + "_next").className = "next";
					}
					if(curPage == 1){
						document.getElementById(key + "_prev").className = "no_prev";
					}	
				}
			}

			if(flag){
				pageInfo[key] = curPage;

				Daum.Dom.toggle(key + "_" + oldPage, 'none');
				Daum.Dom.toggle(key + "_" + curPage, 'block');
			}
		}
	}
}();

Daum.Top = function() {
	var topImgs = {
		hotIssue: {
			on: [], off: []
		},
		subjectCafe: {
			on: [], off: []
		},
		targetArea: {
			hotIssue: {
				id: 'cafehotissue',
				cls: 'issue_'
			},
			subjectCafe: {
				id: 'subject_cafe',
				cls: 'subject_'
			}
		}
	};
	

	return {
		initTopImgs: function(on, off, type) {	// 핫이슈, 주제별 카페에 해당하는 배열에 on/off 이미지 등록
			topImgs[type].on.push(on);
			topImgs[type].off.push(off);
		},

		toggleTab: function(tabIdx, prefix, type, max) {
			var target = document.getElementById(prefix + tabIdx);
			if (target) {
				for (var i = 1; i <= max; i++ ) {
					if (i == tabIdx) {
						document.getElementById(prefix + i).src = topImgs[type].on[i - 1];	// 해당 탭만 on 이미지로
					} else {
						document.getElementById(prefix + i).src = topImgs[type].off[i - 1];
					}
				}
				document.getElementById(topImgs.targetArea[type].id).className = 'wrap_box ' + topImgs.targetArea[type].cls + tabIdx;
			}
		},
		
		toggleNewIcons: function(tabIdx) {
			var idx = tabIdx || (Daum.Top.focus_getActivatedTabIndex() + 1);
			document.getElementById('newMyCafeList').style.display	= idx==2 ? "none" : Daum.isNewCafeList ? 'block' : 'none';
			document.getElementById('newMyComment').style.display 	= idx==3 ? "none" : Daum.isNewMyComment ? 'block' : 'none'; 
			document.getElementById('newMyAlimi').style.display 	= idx==4 ? "none" : Daum.isNewMyAlimi ? 'block' : 'none';
		},
		
		focus_getActivatedTabIndex: function(){ // zero-based
			var focus_tab_class = ['focus', 'mycafelist', 'mycomment', 'myalimi'];
			var current_class = document.getElementById('focus_menu').className.split(/\s/)[1];
			var idx = -1;
			for(var i=0; i<focus_tab_class.length; i++){
				if( current_class == focus_tab_class[i] ) { idx = i; break; }
			}
			return idx;
		},
		
		toggleFocus: function(tabIdx) {
			var focus_tab = document.getElementById('focus_menu'),									// 개인화 영역 wrap element
				focus_tab_class = ['focus', 'mycafelist', 'mycomment', 'myalimi'],					// 개인화 영역 divs's classname
				focus_content = ['cC_focus_box', 'cC_mycafelist', 'cC_mycomment', 'cC_myalimi'],	// 개인화 영역 divs
				isLogin = Daum.isLogin,																// login 여부
				idx = parseInt(tabIdx) - 1;															// 열고자 하는 메뉴의 idx
			
			if(!oldFocus) {
				oldFocus = focus_content[ isLogin ? 1 : 0 ];
			}
			
			if (isLogin) {
				focus_tab.className = 'tab_focus ' + focus_tab_class[idx];
				Daum.Dom.toggle(oldFocus, 'none');
				Daum.Dom.toggle(focus_content[idx], 'block');
				oldFocus = focus_content[idx];
				Daum.Top.toggleNewIcons(tabIdx);
			} else {
				if (idx == 0) {
					focus_tab.className = 'tab_focus ' + focus_tab_class[idx];
					Daum.Dom.toggle(oldFocus, 'none');
					Daum.Dom.toggle(focus_content[idx], 'block');
					oldFocus = focus_content[idx];
				} else {
					Daum.Dom.toggle('loginMsgLayer', 'block', true, 300);
				}
			}
		}
	}
}();


