if (typeof(JQUERY_SITE_DEFAULT) == 'undefined') // 한번만 실행
{
	var JQUERY_SITE_DEFAULT = true;

	$(function(){
		// ajaxForm 을 사용하지 않는 form 일경우 Sumit 가로채서 검사
		$("form").not("form[name=Admin_Form_Update]").each(function(i) { 
			var $form = $(this); 
			var f = $form[0]; 

			if (f.onsubmit) f.old_submit = f.onsubmit; 
			f.onsubmit = wrest_submit; 
		}); 

		$("form[name=Admin_Form_Update]").each(function(i) { 
			var $form = $(this); 
			var f = $form[0]; 

			f.old_submit = f.onsubmit; 
			f.onsubmit = function(){ return false; };
		});

		/* 체크 박스 확인 */
		$("input[type=checkbox][name=chk_all]").click(
			function(){
				$('input[type=checkbox][name=chk[]]').attr("checked",$(this).attr("checked"));
			}
		);
	});

}

//게시물삭제
function SubmitCheck(f){
	var check_num = $('input:checked[name=chk[]]').size();
	if(check_num>0){
		if(confirm(' '+check_num+'건의 게시물을 정말로 삭제하시겠습니까? \n\n 게시물은 복구가 되지 않습니다. ')){
			f.submit();
		}else
			return false;
	}else{
		alert('한 개 이상의 게시물을 선택하셔야 합니다.');
		return false;
	}
}

/************* 쪽지관련 시작 *************/
var SetNoteTimer="";
function View_Note(){
	if($("#NoteImg").css("display")!="none")
		$("#NoteImg").css("display","none");
	else
		$("#NoteImg").css("display","");
}

var ReadNum = 0;
function Note_Ajax(){
	//쪽지 Ajax
	$.post(
		Home_Dir+"/_Script/PHP_Func/Note.Alarm.php",
		{},
		function(data){
			clearInterval(SetNoteTimer);

			if(data.ReadNote!=""){
				SetNoteTimer = setInterval(View_Note,300);
				if(ReadNum<data.ReadNote){
					NoteBox();
					ReadNum = data.ReadNote;
				}
			}
			else{
				if($("#NoteImg").css("display")=="none")
					$("#NoteImg").css("display","");

				NoteBoxControll = false;
			}
		},
		"json"
	);
}
	
function NoteStart(){
	Note_Ajax();
	var AutoNote = setInterval(Note_Ajax,5000);
	
	$(function(){
		$("#NoteOpen").click(function(){
			NoteBrowser();
		});
	});
}
	
function NoteBrowser(Code, mb_id){
	if(Code && mb_id)
		var parameter = "?Code="+Code+"&GetID="+mb_id;
	else
		var parameter = "";

	window.open(Home_Dir+"/Member/Note.php"+parameter,"WinNote","width=600, height=470");

	//clearTimeout(Note['timeout']);
	NoteAnimation(Note['nh']);
}

//쪽지 애니메이션 시작
var Note = Array();

Note['nw'] = "";
Note['nh'] = "";
Note['cw'] = "";
Note['ch'] = "";
Note['timeout'] = "";

function NoteBoxSizePosition(PositionKey){
	Note['nw'] = $("#NoteBox").width();
	Note['nh'] = $("#NoteBox").height();
	Note['cw'] = document.body.clientWidth;
	Note['ch'] = document.body.clientHeight;
	
	if(PositionKey=="resize"){
		$("#NoteBox").css("left",(Note['cw']-(Note['nw']+2))+"px");
		$("#NoteBox").css("top",(Note['ch']-(Note['nh']+2))+"px");
	}else{
		$("#NoteBox").css("left",($(window).scrollLeft()+Note['cw']-(Note['nw']+2))+"px");
		$("#NoteBox").css("top",($(window).scrollTop()+Note['ch']-(Note['nh']+2))+"px");
	}
}

function NoteAnimation(top){
	$("#NoteLayer").animate({
		"top":top
	},"slow",function(){
		if(top==0)
			setTimeout("NoteAnimation("+Note['nh']+")",5000);
		else
			$("#NoteBox").hide();
	});
}

function NoteBox(){
	if($("#NoteBox").css("display")=="none"){
		$("#NoteBox").show();
		NoteBoxSizePosition("resize");

		$(window).resize(function(){
			NoteBoxSizePosition("resize");
		});
		$(window).scroll(function(){
			NoteBoxSizePosition("scroll");
		});

		NoteAnimation(0);
	}
}
//쪽지 애니메이션 끝
/************* 쪽지관련 끝 *************/

/************* 사이드메뉴 시작 **************/
function ShowSideMenu(e, mb_id, auth, type, url) {
	var divid = $("#SideMenuLayer");
	var x,y;

	x = e.clientX;
	y = e.clientY;

	/*
	if(navigator.appName=="Microsoft Internet Explorer"){
		//x = (document.layers)?loc.pageX:event.clientX;
		//y = (document.layers)?loc.pageY:event.clientY;
		//웹표준 방식
		x = event.clientX + document.documentElement.scrollLeft + 'px';
		y = event.clientY + document.documentElement.scrollTop + 'px';
	}else{
		x = e.clientX;
		y = e.clientY;
	}
	*/

	if(auth == "Admin" || auth == "Member"){

		//사이드메뉴가 열려있으면 닫기
		if(divid.attr("id")!=undefined)
			divid.remove();

		var AddElement = "<div id='SideMenuLayer' onMouseOut='HideSideMenu(2);' style='position:absolute; top:"+y+"; left:"+x+"; border:solid 1px #d5d5d5; background-color:#ffffff; width:100px; z-index:999;'>";

		AddElement += "<table cellpadding='0' cellspacing='0' border='0' width='100%'>";
		//닫기
		AddElement += "<tr><td height='10' align='right' style='background-color:#eeeeee;'><a href='javascript:HideSideMenu(1);' title='닫기'>x</a>&nbsp;</td></tr>";
		//쪽지보내기
		AddElement += "<tr><td height='20'>&nbsp;· <a href=\"javascript:NoteBrowser('Write','"+mb_id+"');\" title='쪽지보내기'>쪽지보내기</a></td></tr>";
		//메일보내기
		AddElement += "<tr><td height='20'>&nbsp;· <a href=\"javascript:win_open('"+Member_Dir+"/Mail.php?id="+mb_id+"','메일보내기','left=50,top=50,width=600,height=550,resizable=0,scrollbars=0');\" title='메일보내기'>메일보내기</a></td></tr>";

		if(auth == "Admin")//회원정보수정
			AddElement += "<tr><td height='20'>&nbsp;· <a href='"+Home_Dir+"/__Admin/Psw_Member/Member.Write.php?id="+mb_id+"' target='_blank' title='회원정보수정'>회원정보수정</a></td></tr>";

		if(type=="Board")//게시판일 경우 //아이디로 검색
			AddElement += "<tr><td height='20'>&nbsp;· <a href='"+url+"' title='아이디로 검색'>아이디로 검색</a></td></tr>";

		AddElement += "</table>";

		AddElement += "</div>";

		$("body").append(AddElement);
	}
}

//사이드메뉴 닫기
function HideSideMenu(sw){
	if(sw==1)
		$("#SideMenuLayer").remove();
	else{
		$("#SideMenuLayer").mouseleave(function(){
			$("#SideMenuLayer").remove();
		});
	}
}
/************* 사이드메뉴 끝 **************/




/************* 퀵메뉴 시작 **************/

function quick_scroll(quick_id, quick_top, quick_layer_top, quick_sw){
	$(window).scroll(function(){
		quick_move(quick_id, quick_top, quick_layer_top, quick_sw);
	});
}

function quick_move(quick_id, quick_top, quick_layer_top, quick_sw){
	var scrollvar = $(document).scrollTop() + quick_layer_top;

	if($(window).scrollTop() >= quick_top && !quick_sw){//quick_sw가 true일 때만
		scrollvar = quick_top;//특정 위치에서 계속 고정
	}

	quick_id.stop();//현재 박스를 멈추고

	//움직임
	quick_id.animate(
		{ "top": scrollvar },
		400
	);
}

/************* 퀵메뉴 끝 **************/



/************* 글 복사, 드래그 및 오른쪽 버튼 막기 *****************/

function crossMouse(selector){
	if(selector=="undefined") selector=document;

	$(function(){
		$(selector)
			.mousedown(function(){$(selector).mousemove(function(e){return false;});})  
			.bind('keydown', 'ctrl+a', function(){return false;}).bind('keydown', 'ctrl+c', function(){return false;})
			.bind("contextmenu",function(){ return false; })
			.bind("dragstart",function(){ return false; });
	});
}
