$(function(){
	// 스크롤, 우측 맨 위로 가기
	$(window).scroll(function(){
		$('div.rightWrap div.floater').animate({top: $(document).scrollTop()+350}, {queue: false, duration: 300});
	});
	$('div.rightWrap a').click(function(){
		window.scrollTo(0, 0);
		return false;
	});

	// IE 6 Background Fliker
	if($.browser.msie && parseInt($.browser.version) < 7 ) {
		try {
			document.execCommand("BackgroundImageCache", false, true);
		} catch(e){ }
	}

	// 즐겨찾기
	$('a.add-favorite').click(function(){
		var url = 'http://ableforum.com';
		var title = '한국장애인인권포럼';
		try {
			// FF
			if ($.browser.mozilla)
				window.sidebar.addPanel(title, url, "");
			// Opera
			else if($.browser.opera) {
				var elem = document.createElement('a');
				elem.setAttribute('href',url);
				elem.setAttribute('title',title);
				elem.setAttribute('rel','sidebar');
				elem.click();
			}
			// IE, Other
			else
				window.external.AddFavorite(url, title);
		} catch(e) {
			alert('죄송합니다. 브라우져에서 지원하지 않는기능입니다.');
		}

		return false;
	});

	// 하단 패밀리사이트
	$('#fsiteLinkFrm').submit(function(){
		if($('#fsiteLink').val())
			window.open($('#fsiteLink').val());
		return false;
	});

	// 알림판
	$('.l_notice a.banner').bind('click focus mouseenter', function(){
		var bannerId = $(this).attr('class').split(' ');
		$('.l_notice a.banner').removeClass('active');

		$('div.banner-image').hide();

		$(this).addClass('active');
		$('div.banner-image.'+bannerId[1]).show();
		return false;
	});
	rotateBanner(1);

	// 좌측 서브메뉴 컨트롤
	$('a.toggleDepth').click(function(){
		var depthId = $(this).attr('class').split(' ');
		$('dd.'+depthId[1]).show();
		return false;
	});

	// 새창 링크
	$('a.blank').click(function(){
		window.open($(this).attr('href'));
		return false;
	});

	// 네비게이션 컨트롤
	$('#navigation a.menu').bind('focus mouseenter', function() {
		var menuId = $(this).attr('class').split(' ');
		$('>a.menu, >ul.childs', '#navigation ul li').removeClass('active');
		$('>a.menu, >ul.childs', '#menu-'+menuId[1]).addClass('active').stop().animate({opacity: 0.65}, 1).animate({opacity: 1}, 200);
	});
	$('#navigation a.submenu').bind('focus blur mouseenter mouseout', function() {
		$(this).toggleClass('active').stop().animate({opacity: 0.55}, 1).animate({opacity: 1}, 300);
	});

	// onload 시 네비게이션/ 알림판 컨트롤
	set_location(current_url);
	$('div.banner-image.page1').show();
});

function set_location(url) {
	var url = url.split('/');
	$.each(url, function(i, item) {
		switch(i) {
			case 1:
				$('>a.menu, >ul.childs', '#menu-'+item).addClass('active');
			break;
			case 2:
				$('#navigation ul.childs li a.submenu.'+item).addClass('active');
			break;
			case 3:
				var depthId = $('#leftmenu dd ul li a.'+item).attr('class').split(' ');
				$('#leftmenu dd.'+depthId[0]).show();
			break;
		}
	});
}

function loginCheck(s) {
	if(!s.userid.value) {
		alert('아이디를 입력해주세요.');
		s.userid.focus();
		return false;
	}
	if(!s.passwd.value) {
		alert('패스워드를 입력해주세요.');
		s.passwd.focus();
		return false;
	}
	return true;
}


function moveReport() {
	location.href='/monitoring-report/report?it_Seq='+$("#commboReport").val()+'&it_SubSeq=0';
}

function moveWebzine() {
	location.href='/webzine-prism/webzine?it_Seq='+$("#commboWebzine").val()+'&it_SubSeq=0';
}

function webzinePrint() {
	var W = 738;
	var H = document.getElementById("webzineView").offsetHeight;
	var features = "menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,width=" + W + ",height=" + H + ",left=0,top=0";
	var PrintPage = window.open("about:blank",document.getElementById("webzineView").id,features);
	PrintPage.document.open();
	var tag = '';
	tag += '<html>';
	tag += '<head>';
	tag += '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
	tag += '<title>인쇄 :: 한국장애인인권포럼</title>';
	tag += '<link rel="stylesheet" type="text/css" href="/styles/base.css" />';
	tag += '</head>';
	tag += '<body>';
	tag += '<div class="Container">';
	tag += '<div style="height:41px;"><img src="/images/board/title_print.gif" alt="프린트 하기" /></div>';
	tag += '<div style="padding:15px;margin-bottom:20px;"><a href="#" onclick="window.print();" style="float:right;"><img src="/images/btn/btn_print.gif" alt="프린트 시작" /></a></div>';
	tag += '<div style="width: 680px; margin:20px; clear:both;">';
	tag += document.getElementById("webzineView").innerHTML;
	tag += '</div>';
	tag += '<div style="margin-top:20px; padding:15px;text-align:right;background-color:#E3E3E3;"><a href="#" onclick="window.close();"><img src="/images/btn/btn_close.gif" alt="창닫기" /></a></div>';
	tag += '</div>';
	tag += '</body>';
	tag += '</html>';
	PrintPage.document.write(tag);
	PrintPage.document.title = '인쇄 :: 한국장애인인권포럼';
	PrintPage.document.close();
	PrintPage.print(PrintPage.location.reload());
}

// from naver.com TODO:jquery conversion 할것
function resizeIframe(name, userHtmlScroll)
{
	if (name == null || name == "")
	{
		name = "board_frame";
	}
	try
	{
		var oTarget;

		if ($.browser.msie && $.browser.version <= 7) {

			var oFrame = document.getElementById(name);

			var oFrameHtml = window.frames[name].document.getElementsByTagName('HTML')[0];
			var oFrameBody = window.frames[name].document.getElementsByTagName('BODY')[0];

			//IE5.5에서는 html의 scrollHeight 값이 다르다.
			if (userHtmlScroll && $.browser.version == 5.5)
				oTarget = oFrameHtml;
			else
				oTarget = oFrameBody;

			//oFrame.style.width = oTarget.scrollWidth + "px";
			oFrame.style.height = oTarget.scrollHeight + "px";
		} else {

			var oBody = document.getElementById(name).contentDocument.documentElement;
			var oIFrame = document.getElementById(name);

			var frmWidth  = oBody.scrollWidth;
			var frmHeight = oBody.scrollHeight;

			// IE8을 위한 지저분한 코드
			if($.browser.msie && $.browser.version == 8 && (frmHeight==parseInt(oIFrame.style.height) || !parseInt(oIFrame.style.height) || frmHeight==0) )
			{
				var s = oBody.getElementsByTagName("BODY")[0].appendChild(document.createElement('DIV'))
				s.style.clear = 'both';
				s.innerHTML="";
				s.innerHTML="";
				var nHeight = s.offsetTop;
				s.parentNode.removeChild(s);
				if(nHeight>0)
					frmHeight = nHeight;
			}

			oIFrame.style.height = frmHeight + "px";
			//oIFrame.style.width = frmWidth + "px";
		}
	}catch (e) { return null; }
}

function rotateBanner(page){
	if(page>4) page=1;

	$('.l_notice a.banner').removeClass('active');
	$('div.banner-image').hide();
	$('.l_notice a.banner.page'+page).addClass('active');
	$('div.banner-image.page'+page).show();

	//setTimeout("rotateBanner("+(page+1)+")", 5000);
}
