var Navigation = {
	win : {},

	goPage : function (code, option) {
		switch (code) {
			case 0  : // 회원
				switch (option) {
					case 1 : // 로그인
						Navigation.Layer.open(G_SVR_SSL + '/src/member/login.php?m=login&goUrl=' + escape(this.goUrl()), 243, 203, 'login');
						break;
					case 2 : // 아이디 찾기
						Navigation.Layer.open(G_SVR_SSL + '/src/member/login.php?m=find&a=id&goUrl=' + escape(this.goUrl()), 243, 203, 'login');
						break;
					case 3 : // 패스워드 찾기
						Navigation.Layer.open(G_SVR_SSL + '/src/member/login.php?m=find&a=pass&goUrl=' + escape(this.goUrl()), 243, 203, 'login');
						break;
					case 4 : // 회원가입
						Navigation.Layer.open(G_SVR_SSL + '/src/member/join.php?m=join', 383, 473, 'signup');
						break;
					case 5 : // 정보수정
						Navigation.Layer.open(G_SVR_SSL + '/src/member/user.php?m=edit', 383, 483, 'change');
						break;
					case 6 : // 로그아웃
						location.href = G_SVR_SSL + '/src/member/login.php?m=logout&goUrl=' + escape(this.goUrl());
						break;
					case 7 : // Connect SNS
					case 8 : // Disconnect SNS
						new Ajax.Request(G_TOP_DIR + '/common/src/sns.php', {
							method : 'post',
							asynchronous : false,
							contentType : 'application/x-www-form-urlencoded',
							encoding : 'utf-8',
							parameters : {'m' : option == 7 ? 'on' : 'off'},
							onSuccess : function (xmlHttp) {
								var msg = xmlHttp.responseText.evalJSON();

								if (msg.result == 'SUCCESS') {
									this.goPage(43);
								} else if (msg.result == 'FAIL') {
									window.alert(decodeURIComponent(msg.message));
								} else {
									window.alert("유효하지 않은 결과코드입니다.");
								}
							}.bind(this)
						});

						break;
					case 9 : // SCRAP
						Navigation.Layer.open(G_SVR_BOARD + '/src/scrap.php', 383, 483, 'scrap');
						break;
				}

				break;
			case 1  : // 푸터
				switch (option) {
					case 1 : // ABOUT
						location.href = G_SVR_MAIN + '/src/rhythmer/about.php?__anchor__=about1';
						break;
					case 2 : // Advertising
						location.href = G_SVR_MAIN + '/src/rhythmer/about.php?__anchor__=about2';
						break;
					case 3 : // To Editors
						location.href = G_SVR_MAIN + '/src/rhythmer/about.php?__anchor__=about3';
						break;
					case 4 : // Music Business
						location.href = G_SVR_MAIN + '/src/rhythmer/about.php?__anchor__=about4';
						break;
					case 5 : // Partnership
						location.href = G_SVR_MAIN + '/src/rhythmer/about.php?__anchor__=about5';
						break;
					case 6 : // Notice
						location.href = G_SVR_BOARD + '/src/rhythmer/notice/list.php';
						break;
					default :
						this.goPage(1, 1);
				}

				break;
			case 10 : // 매거진
				location.href = G_SVR_BOARD + '/src/magazine/main.php';
				break;
			case 11 :
				location.href = G_SVR_BOARD + '/src/magazine/feature/list.php';
				break;
			case 12 :
				location.href = G_SVR_BOARD + '/src/magazine/interview/list.php';
				break;
			case 13 :
				location.href = G_SVR_BOARD + '/src/magazine/review/list.php';
				break;
			case 14 :
				location.href = G_SVR_BOARD + '/src/magazine/news/list.php';
				break;
			case 20 : // TV & Radio
				location.href = G_SVR_BOARD + '/src/TVnRadio/main.php';
				break;
			case 21 :
				location.href = G_SVR_BOARD + '/src/TVnRadio/tv/list.php';
				break;
			case 22 :
				location.href = G_SVR_BOARD + '/src/TVnRadio/radio/list.php';
				break;
			case 23 :
				location.href = G_SVR_BOARD + '/src/TVnRadio/rhytube/list.php';
				break;
			case 24 :
				location.href = G_SVR_BOARD + '/src/TVnRadio/remix/list.php';
				break;
			case 30  : // Diggin
				window.alert('준비중입니다.');
				break;
			case 40 : // 커뮤니티
				location.href = G_SVR_BOARD + '/src/community/main.php';
				break;
			case 41 :
				location.href = G_SVR_BOARD + '/src/community/common/list.php';
				break;
			case 42 :
				location.href = G_SVR_BOARD + '/src/community/music/list.php';
				break;
			case 43 :
				location.href = G_SVR_BOARD + '/src/community/twitter/list.php';
				break;
			case 44 :
				location.href = G_SVR_BOARD + '/src/community/gallery/list.php';
				break;
			case 45 :
				location.href = G_SVR_BOARD + '/src/community/qna/list.php';
				break;
			case 46 :
				location.href = G_SVR_BOARD + '/src/community/market/list.php';
				break;
			case 50 : // 이벤트
				location.href = G_SVR_BOARD + '/src/event/notice/list.php';
				break;
			case 51 :
				location.href = G_SVR_BOARD + '/src/event/notice/list.php?f=ing';
				break;
			case 52 :
				location.href = G_SVR_BOARD + '/src/event/notice/list.php?f=end';
				break;
			case 53 :
				location.href = G_SVR_BOARD + '/src/event/winner/list.php';
				break;
			case 60 : // Music Studio
				location.href = G_SVR_BOARD + '/src/studio/main.php';
				break;
			case 61 :
				location.href = G_SVR_BOARD + '/src/studio/remix/list.php?c=5';
				break;
			case 62 :
				location.href = G_SVR_BOARD + '/src/studio/remix/list.php?c=6';
				break;
			case 63 :
				location.href = G_SVR_BOARD + '/src/studio/remix/list.php?c=10';
				break;
			case 64 :
				location.href = G_SVR_BOARD + '/src/studio/competition/list.php?s=competition-daewoong';
				break;
			default : // 메인
				location.href = G_SVR_MAIN + '/src/main.php';
		}
	},

	changeLayer : function (code) {
		var o = $('navi_');

		o.getElementsBySelector('a').findAll(function (s) {
			s.setAttribute('href', 'javascript:Navigation.goPage(' + s.getAttribute('n') + ');');

			if (parseInt(s.getAttribute('n')) == code && s.getElementsByTagName("img")) {
				s.getElementsByTagName("img")[0].src = s.getElementsByTagName("img")[0].src.replace('_off.gif', '_on.gif');
			}
		}.bind(this));

		o.getElementsBySelector('li.m').findAll(function (s) {
			Event.observe(s, 'mouseover', function (event) {
				if (s.getElementsByTagName("img") && parseInt(s.getAttribute('n')) != code) {
					s.getElementsByTagName("img")[0].src = s.getElementsByTagName("img")[0].src.replace('_off.gif', '_on.gif');
				}

				o.getElementsBySelector('ol').findAll(function (_s) {
					if (s.getAttribute('n') == _s.getAttribute('n')) {
						$(_s).show();
					} else {
						$(_s).hide();
					}
				}.bind(this));
			}.bind(this));

			Event.observe(s, 'mouseout', function (event) {
				if (s.getElementsByTagName("img") && parseInt(s.getAttribute('n')) != code) {
					s.getElementsByTagName("img")[0].src = s.getElementsByTagName("img")[0].src.replace('_on.gif', '_off.gif');
				}

				$(s).getElementsBySelector('ol').findAll(function (_s) {
					$(_s).hide();
				}.bind(this));
			}.bind(this));
		}.bind(this));
	},

	goUrl : function () {
		var url = G_SVR_MAIN;
		var tmp = location.search.substr(1, location.search.length).split("&");

		if (location.pathname.indexOf('/src/member/') == -1) {
			url = location.protocol + '//' + location.host + location.pathname + location.search;

			for (var i = 0; i < tmp.length; i++) {
				var v = tmp[i].split("=");

				if (v[0] == "goUrl") {
					url = unescape(v[1]);
					break;
				}
			}
		}

		return url;
	}
}

/**
 * 회원 레이어
 *
 * 작성일 : 2010/08/11, 정원광 (wkwang@yedong.com)
 *
 */
Navigation.Layer = {
/**
 * 열기
 *
 * @return void
 * @access public
 *
 */
	open : function (src, w, h, css) {
		this.close();

		switch (css) {
			case 'login' :
				$('util_1').src = $('util_1').src.replace('_off.gif', '_on.gif');
				$('util_2').src = $('util_2').src.replace('_on.gif', '_off.gif');
				break;
			case 'signup' :
				$('util_1').src = $('util_1').src.replace('_on.gif', '_off.gif');
				$('util_2').src = $('util_2').src.replace('_off.gif', '_on.gif');
				break;
		}

		var size = Common.getPageSize();

		$$('body')[0].appendChild(Builder.node('div', {id : '_OVERS_', style : 'position:absolute; width:' + size.width + 'px; height:' + size.height + 'px; left:0; top:0; background-color:#000000; display:none; z-index:998;'}));

		new Effect.Appear('_OVERS_', {
			duration : 0.1,
			from : 0.0,
			to : 0.5,
			afterFinish : (function () {
				$('NavigationLayer').appendChild(Builder.node('div', {id : '_LAYER_', className : css, style : 'z-index:999;'}, [
					Builder.node('div', {id : '_LAYER_LOAD_', className : 'loading'},
						Builder.node('img', {src : G_TOP_DIR + '/common/module/lightbox/images/loading.gif'})
					),
					Builder.node('div', {id : '_LAYER_INIT_', style : 'padding:7px; background-color:#666; display:none;'},
						Builder.node('iframe', {id : '_LAYER_BODY_', src : src, frameBorder : 0, scrolling : 'no'})
					)
				]));

				var div = {over : $('_OVERS_'), body : $('_LAYER_BODY_'), load : $('_LAYER_LOAD_'), init : $('_LAYER_INIT_')};

				div.over.observe('click', function () { this.close(); }.bind(this));
				div.body.setStyle({
					background : '#fff',
					marginWidth : 0,
					marginHeight : 0,
					leftMargin : 0,
					topMargin : 0,
					width : w + 'px',
					height : h + 'px'
				});
				div.body.observe('load', function () {
					div.load.hide();
					div.init.show();

					div.body.contentWindow.document.oncontextmenu = new Function("return false");
					div.body.contentWindow.document.ondragstart = new Function("return false");
//					div.body.contentWindow.document.onselectstart = new Function("return false");
				}.bind(this));
			}.bind(this))
		});
	},
/**
 * 닫기
 *
 * @return void
 * @access public
 *
 */
	close : function () {
		try {
			$('_LAYER_').remove();
			$('_OVERS_').remove();
		} catch (e) {
		}
	}
}
