/*
 * since 2008.10.11. by lks
 * prototype-1.6.0.4.js or scriptaculous-1.8.1 or higher required.
 */

var WGN_lib_common = Class.create();

WGN_lib_common.prototype =
{
	initialize: function(){


	},

	//-----------------------------------------------------------------------------
	// DOM객체 내의 텍스트노드의 값 추출
	// Element, tagName, 중복순서(유일할 경우 생략)
	// @return : String
	//-----------------------------------------------------------------------------
	getTextNode: function( domObj, strTag, seq ){
		try{
			var arr = domObj.getElementsByTagName( strTag );

			if( arr.length <= 0 ) alert( "getTextNode 오류: 찾으시는(" + strTag + ") DOM객체가 없습니다." );
			else if( arr[ ( seq != null ? seq : 0 ) ].childNodes.length > 0 )
				return arr[ ( seq != null ? seq : 0 ) ].firstChild.nodeValue;

			return "";
		}catch( ex ){
			alert( "getTextNode 예외오류: " + ex.name + " (" + ex.number + ")\n\n[" + ex.message + "]\n[" + ex.description + "]" );
			return "";
		}
	},

	//-----------------------------------------------------------------------------
	// 경고메시지 띄우고 해당 객체에 포커싱 하면서 해당 객체의 값 전체 블럭 설정
	// Element, 경고메시지
	// @return : void
	//-----------------------------------------------------------------------------
	alertActivate: function( obj, noticeMsg ){
		alert( noticeMsg );

		try{
			Field.activate( obj );
		}catch( e ){

		}
	},

	//-----------------------------------------------------------------------------
	// 해당 객체의 값 전체의 whitespace 제거
	// Element
	// @return : void
	//-----------------------------------------------------------------------------
	onlyChar: function( obj ){
		try{
			obj.value = obj.value.onlyChar();

		}catch( e ){

		}
	},

	//-----------------------------------------------------------------------------
	// 해당 객체의 값 양 옆의 whitespace 제거
	// Element
	// @return : void
	//-----------------------------------------------------------------------------
	trim: function( obj ){
		try{
			obj.value = obj.value.trim();
		}catch( e ){

		}
	},

	//-----------------------------------------------------------------------------
	// 자동 탭 ( usage: INPUT의 onkeyup="wgn.autoTab(this);" )
	// 영문이나 숫자만 사용해야 합니다. 한글은 조합입력방식때문에 사용할 수 없습니다.
	// Element
	// @return : void
	//-----------------------------------------------------------------------------
	autoTab: function( obj, obj_next ){
		try{
			if( obj.value.length >= obj.maxLength ){

				if( obj_next == null ) Field.focus( $( obj ).next( "INPUT" ) );
				else                   Field.focus( $( obj_next )            );
			}
		}catch( e ){

		}
	},

	//-----------------------------------------------------------------------------
	// 바이트 계산과 cropping
	// @사용법 : <textarea onkeyup="wgn.cutByte(this);" maxlength="4000">......
	// Element
	// @return : void
	//-----------------------------------------------------------------------------
	cutByte: function( obj_content, obj_display, typeDisplay ){
		var max_bytes = parseInt( obj_content.getAttribute( "maxlength" ) != null ? obj_content.getAttribute( "maxlength" ) : 0 );
		var tmpStr = new String( obj_content.value );;
		var tcount = tmpStr.lengthByte();

		if( tcount > max_bytes ){
			var tmpSeq = 0;
			var isCapture = false;

			tcount = 0;

			for( k = 0; k < tmpStr.length; k++ ){
				if( tmpStr.charCodeAt( k ) > 147 )    tcount += 4;
				else if( tmpStr.charAt( k ) != "\r" ) tcount++;

				if( !isCapture && tcount > max_bytes ){
					tmpSeq = k;
					isCapture = true;
				}
			}
			tmpStr = tmpStr.rtrim().substring( 0, tmpSeq );
			obj_content.blur();
			obj_content.value = tmpStr;

			alert( "메시지 내용은 " + max_bytes + "바이트 이상은 전송하실 수 없습니다.\r\n입력하신 메세지는 " + ( tcount - max_bytes ) + "바이트가 초과되었습니다.\r\n초과된 부분은 자동으로 삭제됩니다." );

			tcount = tmpStr.lengthByte();
		}

		if( obj_display != null ){
			if( typeDisplay != null ){
				if( typeDisplay == "left_kor" ){
/*
					if( obj_display.value ) obj_display.value     = Math.ceil( ( max_bytes - tcount ) / 4 );
					else                    obj_display.innerHTML = Math.ceil( ( max_bytes - tcount ) / 4 );
*/
					if( obj_display.value ) obj_display.value     = ( max_bytes - tcount ) / 4;
					else                    obj_display.innerHTML = ( max_bytes - tcount ) / 4;

				}else if( typeDisplay == "left" ){
					if( obj_display.value ) obj_display.value     = max_bytes - tcount;
					else                    obj_display.innerHTML = max_bytes - tcount;

				}
			}else{
				if( obj_display.value ) obj_display.value     = tcount;
				else                    obj_display.innerHTML = tcount;
			}
		}
		obj_content.focus();
	},

	//-----------------------------------------------------------------------------
	// 부드러운 스크롤
	// @사용법 : onclick="wgn.scrollToElement('id_element');return false;"
	// Element(id of Element), duration(단위:0.1초)
	// @return : void
	//-----------------------------------------------------------------------------
	scrollToElement: function( obj, speed ){
		var pos = obj == null ? null : $( obj ).cumulativeOffset(); // 문서에서의 top, left
		var dOffsets = document.viewport.getScrollOffsets();        // 보이는 영역의 스크롤 top, left

		clearInterval( this.timer_scroll );
		this.timer_scroll = null;

		this.duration_scroll = speed == null ? 500 : speed * 100;
		this.trans_from = dOffsets.top;
		this.trans_to = pos == null ? 0 : pos.top - 5;
		this.trans_time = new Date().getTime();
		this.timer_scroll = setInterval( this.transScroll.bind(this), Math.round( 1000 / 50 ) );
	},

	transScroll: function(){
		var time = new Date().getTime();

		if( time < this.trans_time + this.duration_scroll ){
			var t = time - this.trans_time;
			var b = this.trans_from;
			var c = this.trans_to - this.trans_from;
			var d = this.duration_scroll;

			//Fx.Transitions.sineInOut
			this.trans_now = -c/4 * (Math.cos(Math.PI*t/d) - 1) + b;

		}else{
			clearInterval( this.timer_scroll );
			this.timer_scroll = null;
			this.trans_now = this.trans_to;
		}
		window.scrollTo( 0, this.trans_now );
	},

	//-----------------------------------------------------------------------------
	// 부드러운 스크롤 (페이지 맨 위로)
	// @사용법 : onclick="wgn.scrollToTop();"
	// duration(단위:0.1초)
	// @return : void
	//-----------------------------------------------------------------------------
	scrollToTop: function( speed ){
		//var bodyHeight = $( 버튼 ).cumulativeOffset();
		//if( speed != null) var speed = bodyHeight.top/1500
		//Effect.ScrollTo( 목표 ,{ duration:speed }); // 페이지 상단 일 경우 $$( "BODY" )[0]
	},

	//-----------------------------------------------------------------------------
	// 팝업창 띄우기
	// @사용법 : wgn.openPopup( "", { width: 400, height: 500, scroll: 0, top: 100, left: 100, name: "name_popup" } );
	// 각 옵션의 기본값은 아래 참조
	// @return : 팝업창객체
	//-----------------------------------------------------------------------------
	openPopup: function( url, option ){
		var obj_option = option == null ? {} : option;

		if( url               == null ) url               = "";
		if( obj_option.width  == null ) obj_option.width  = screen.availWidth;
		if( obj_option.height == null ) obj_option.height = screen.availHeight;
		if( obj_option.scroll == null ) obj_option.scroll = 0;
		if( obj_option.top    == null ) obj_option.top    = ( screen.availHeight - obj_option.height ) / 4;
		if( obj_option.left   == null ) obj_option.left   = ( screen.availWidth  - obj_option.width  ) / 4;
		if( obj_option.name   == null ) obj_option.name   = "";
		if( obj_option.errMsg == null ) obj_option.errMsg = "Please disable popup blocking!";

		var newWindow = window.open( url, obj_option.name, "width=" + obj_option.width + ",height=" + obj_option.height + ",scrollbars=" + obj_option.scroll + ",toolbar=0,menubars=0,locationbar=0,historybar=0,statusbar=0,resizable=0,left=" + obj_option.left + ",top=" + obj_option.top + ",channelmode=no,titlebar=no", false );

		if( !newWindow ){
			alert( obj_option.errMsg );
			return false;
		}
		newWindow.focus();

		return newWindow;
	},

	//-----------------------------------------------------------------------------
	// 쿠키에 기한만료 값 셋팅(자식창)
	// @사용법 : wgn.setCookie( "name_project", "value_project", 3600 );
	// String(key), String(value), Number(분,minutes)
	// @return : void
	//-----------------------------------------------------------------------------
	setCookie: function( name, value, expireMinutes )
	{
		var todayDate = new Date();
		todayDate.setDate( todayDate.getMinutes() + expireMinutes );
		document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";";
	},

	//-----------------------------------------------------------------------------
	// 쿠키 값 추출(부모창)
	// @사용법 : wgn.getCookie( "name_project" );
	// 각 옵션의 기본값은 아래 참조
	// @return : String(입력된 key-만료되지 않은-에 해당하는 값)
	//-----------------------------------------------------------------------------
	getCookie: function( name ){
		var nameOfCookie = name + "=";
		var x = 0;
		while ( x <= document.cookie.length ){
			var y = (x+nameOfCookie.length);
			if( document.cookie.substring( x, y ) == nameOfCookie ){
				if( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
					endOfCookie = document.cookie.length;
				return unescape( document.cookie.substring( y, endOfCookie ) );
			}
			x = document.cookie.indexOf( " ", x ) + 1;
			if( x == 0 )
				break;
		}
		return "";
	}
}

var wgn = new WGN_lib_common();

//-----------------------------------------------------------------------------
//	flash object active
//	activeSwf( obj_id, obj_src, obj_width, obj_height, obj_transparent )
//-----------------------------------------------------------------------------
function activeSwf( o_id, o_src, o_width, o_height, o_transparent ){
	obj =  "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\""+ o_width +"\" height=\""+ o_height +"\" id=\""+ o_id +"\" align=\"middle\">"
		+  "<param name=\"allowScriptAccess\" value=\"always\" />"
		+  "<param name=\"allowFullScreen\" value=\"false\" />"
		+  "<param name=\"movie\" value=\""+ o_src +"\" />"
		+  "<param name=\"quality\" value=\"high\" />";

	if( o_transparent == "transparent" ) obj += "<param name=\"wmode\" value=\"transparent\" />";

	obj += "<param name=\"bgcolor\" value=\"#ffffff\" />"
		+  "<embed src=\""+ o_src +"\" quality=\"high\"";

	if( o_transparent == "transparent" ) obj += "wmode=\"transparent\"";

	obj += "bgcolor=\"#ffffff\" width=\""+ o_width +"\" height=\""+ o_height +"\" name=\""+ o_id +"\" align=\"middle\" allowScriptAccess=\"always\" allowFullScreen=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />"
		+  "</object>";

	document.writeln( obj );
}

//-----------------------------------------------------------------------------
// select skin 적용
//
// 사용법
//  new WGN_SD.Selectbox('element_id', {
//      fontSize      : 11,
//      lineSize      : 13
//  });
//-----------------------------------------------------------------------------
if( typeof WGN_SD == "undefined" ){
	var WGN_SD = new Object();

	WGN_SD.$  = function( id ){
		return document.getElementById( id );
	}
	WGN_SD.$$ = function(){
		var obj = function(){
			if( this.__const )
				this.__const.apply( this,arguments );
		}
		WGN_SD.extend( obj.prototype,arguments[0] );

		return obj;
	}
	WGN_SD.$c = function( tag ){
		return document.createElement( tag );
	}
	WGN_SD.extend = function( obj ){
		for( var i=0; i<arguments.length; i++ ){
			for( var x in arguments[i] )
				obj[x]=arguments[i][x];
		}

		return obj;
	}
	WGN_SD.lim = function( val,min,max ){
		return Math.max( Math.min( val,max ), min );
	}
}

WGN_SD.Selectbox = WGN_SD.$$({
	__const : function( id ){
		var t = this;
		var s = t._source = WGN_SD.$( id );
		var sd_width,
			sd_height,
			sd_fontSize,
			sd_lineSize,
			sd_FLPadding,
			sd_listSize,
			sd_skinActive,
			sd_skinFormat,
			sd_borderActive,
			sd_borderSet,
			sd_txtElColor,
			sd_txtElBgColor,
			sd_optTxtColor,
			sd_optBgColor,
			sd_optTxtHover,
			sd_optBgHover,
			sd_optTxtPadding;

		if( s.className.match("SD_STYLE01") ){
			sd_width         = 157;

		}
		if( s.className.match("SD_STYLE02") ){
			sd_width         = 178;
			sd_skinFormat    = "/image/btn/sd_style02.gif";
			sd_borderSet     = "1px solid #79074c";
			sd_txtElColor    = "#ffffff";
			sd_txtElBgColor  = "#af1e76";
			sd_optTxtColor   = "#d86dae";
			sd_optBgColor    = "#af1e76";
			sd_optTxtHover   = "#c38fae";
			sd_optBgHover    = "#79074c";

		}
		if( s.className.match("SD_STYLE03") ){
			sd_width         = 118;
			sd_height        = 15;
			sd_lineSize      = 11;
			sd_skinFormat    = "/image/btn/sd_style01.gif";
			sd_borderSet     = "1px solid #cccccc";
			sd_txtElColor    = "#909090";
			sd_txtElBgColor  = "#ffffff";
			sd_optTxtColor   = "#999999";
			sd_optBgColor    = "#ffffff";
			sd_optTxtHover   = "#ffffff";
			sd_optBgHover    = "#cccccc";
			sd_optTxtPadding = "4px 4px";

		}
		if( !sd_width )         sd_width         = s.offsetWidth -2;s
		if( !sd_height )        sd_height        = 17;
		if( !sd_fontSize )      sd_fontSize      = 11;
		if( !sd_lineSize )      sd_lineSize      = 13;
		if( !sd_FLPadding )     sd_FLPadding     = 2;
		if( !sd_listSize )      sd_listSize      = 100;
		if( !sd_skinActive )    sd_skinActive    = false;
		if( !sd_skinFormat )    sd_skinFormat    = "/image/btn/sd_style06.gif";
		if( !sd_borderActive )  sd_borderActive  = true;
		if( !sd_borderSet )     sd_borderSet     = "1px solid #e1e1e1";
		if( !sd_txtElColor )    sd_txtElColor    = "#909090";
		if( !sd_txtElBgColor )  sd_txtElBgColor  = "#ffffff";
		if( !sd_optTxtColor )   sd_optTxtColor   = "#999999";
		if( !sd_optBgColor )    sd_optBgColor    = "#ffffff";
		if( !sd_optTxtHover )   sd_optTxtHover   = "#ffffff";
		if( !sd_optBgHover )    sd_optBgHover    = "#cccccc";
		if( !sd_optTxtPadding ) sd_optTxtPadding = "2px 4px";

		t.options = WGN_SD.extend({
			width         : sd_width,           //s.offsetWidth;
			height        : sd_height,          //s.offsetHeight;
			fontSize      : sd_fontSize,
			lineSize      : sd_lineSize,
			FLPadding     : sd_FLPadding,       // FLPadding 2 = optTxtPadding 0 4px
			listSize      : sd_listSize,
			skinActive    : sd_skinActive,
			skinFormat    : sd_skinFormat,      //"./image/sbox_%s.gif";
			borderActive  : sd_borderActive,
			borderSet     : sd_borderSet,
			txtElColor    : sd_txtElColor,
			txtElBgColor  : sd_txtElBgColor,
			optTxtColor   : sd_optTxtColor,
			optBgColor    : sd_optBgColor,
			optTxtHover   : sd_optTxtHover,
			optBgHover    : sd_optBgHover,
			optTxtPadding : sd_optTxtPadding
		}, arguments[1] )

		var o = t.options;
		var e = t._element = WGN_SD.$c( "div" );
		var c = e.appendChild( WGN_SD.$c( "div" ) );
		var p = { left:0, top:0 };

		{
			var _o = t._source;
			do{
				p.left += _o.offsetLeft;
				p.top  += _o.offsetTop;
				_o     =  _o.offsetParent;
			}while( _o )
		}

		s.parentNode.insertBefore( e, s );
		s.style.display = "none";

		if( o.borderActive )
			e.style.border = o.borderSet;

		with( e.style ){
			top        = p.top + "px";
			left       = p.left + "px";
			width      = o.width + "px";
			height     = o.height + "px";       // height = ( o.height-2 ) + "px";
			background = o.txtElBgColor;
			lineHeight  = o.lineSize + "px";
		}

		with( c.style ){
			width    = o.width + "px";
			height   = o.height + "px";         // height   = ( o.height-2 ) + "px";
			fontSize = o.fontSize + "px";
			overflow = "hidden";
			cursor   = "pointer";
		}

		c.onmouseover = function(){
			if( !t._list_el.parentNode || !t._list_el.parentNode.tagName )
				document.body.appendChild( t._list_el );
		}
		c.onmousedown = function(e){
			t.onmousedown.call( t, e || window.event );
		}
		c.onmouseup = function(){
			t.onmouseup.apply( t, [] );
		}

		var b = c.appendChild( WGN_SD.$c( "div" ) );

		with( b.style ){
			background         = "no-repeat url( " + o.skinFormat.replace( '%s','bt' ) + " ) 50% 50%";
			b.style.cssFloat   = "right";
			b.style.styleFloat = "right";
			height             = "100%";
		}
		t._txt_el = c.appendChild( WGN_SD.$c( "div" ) );
		with( t._txt_el ) {
			appendChild( document.createTextNode( s.options[s.selectedIndex].text ) );

			// var tempPadding = Math.max( Math.floor( ( o.height-offsetHeight )/2 ),0 );
			// if( tempPadding > 5 ) tempPadding = 2;

			with( style ) {
				height      = o.fontSize + "px";
				lineHeight  = o.lineSize + "px";
				overflow    = "hidden";
				//marginTop   = Math.max( Math.floor( ( o.height-offsetHeight )/2 ),0 ) + "px";
				//marginTop   = tempPadding + "px";
				marginTop   = "3px";
				marginLeft  = marginTop;
				paddingLeft = o.FLPadding + "px";
				color       = o.txtElColor;
			}
		}
		c.appendChild( WGN_SD.$c( "div" ) ).style.clear = "both";

		var im;
		( im = WGN_SD.$c( "img" ) ).onload = function(){
			b.style.width = im.width + "px";
		}
		im.src = o.skinFormat.replace( "%s","bt" );
		t._list_el = WGN_SD.$c( "div" );

		with( t._list_el.style ){
			position   = "absolute";
			border     = o.borderSet;
			display    = "none";
			oveflow    = "auto";
			fontSize   = o.fontSize + "px";
			lineHeight = o.lineSize + "px";
		}
		t._list_el.onmousedown = function(e){
			t.onscrollbar.call( t, e || window.event );
		}
		t._event_onmousedown = function(e){
			t.onmousedown.call( t, e || window.event );
		}
		t.paint();
	},
	onmousedown : function(e){
		if( this._list_el.style.display == "none" ){
			var t = this;
			var p = { left:0, top:0 }

			{
				var o = t._element;
				while( o.offsetParent ){
					p.left   += o.offsetLeft;
					p.top    += o.offsetTop;
					o        =  o.offsetParent;
				}
			}

			this.paint();
			this._list_el.style.display = "";

			var pos_el_top;
			var pos_dm;

			pos_el_top = p.top + this._element.offsetHeight - 1;

			if( document.body.scrollHeight < document.body.offsetHeight ){
				pos_dm = document.body.offsetHeight - pos_el_top;
			} else{
				pos_dm = document.body.scrollHeight - pos_el_top;
			}

			if( pos_dm < this._list_el.offsetHeight ){
				pos_el_top = p.top - this._list_el.offsetHeight + 1;
			}

			if( this._list_el.offsetWidth < this._element.offsetWidth )
				this._list_el.style.width = this._element.offsetWidth + "px";

			with( this._list_el.style ){
				width  = this._element.offsetWidth - 2 + "px";      // 리스트 width
				top    = pos_el_top + "px";
				left   = p.left + "px";
				zIndex = 9999;
			}
		}else{
			this._list_el.style.display = "none";

			with( document ){
				try{
					detachEvent( "onmousedown", this._event_onmousedown );
				}catch(e){
					removeEventListener( "mousedown", this._event_onmousedown, false );
				}
			}
		}
		try{
			e.preventDefault();
			e.stopPropagation();
		}catch(e){
			e.returnValue = false;
			e.cancelBubble = true;
		}
	},
	onmouseup : function(){
		if( this._list_el.style.display != "none" ){
			with( document ){
				try{
					attachEvent( "onmousedown", this._event_onmousedown );
				}catch(e){
					addEventListener( "mousedown", this._event_onmousedown );
				}
			}
		}
	},
	onselect : function(e){
		var el = e.target || e.srcElement;
		var o  = this.options;
		var s  = this._source;

		s.selectedIndex = el._index;

		this._txt_el.firstChild.nodeValue = s.options[s.selectedIndex].text;
		this.onmousedown();
		if( this._source.onchange )
			this._source.onchange();
	},
	onover : function(e){
		var el = e.target || e.srcElement;
		var c  = el.parentNode.childNodes;
		var i  = el._index;
		var o = this.options;

		for( var _i = 0; _i<c.length; _i++ ){
			c[_i].style.color = o.optTxtColor;
			c[_i].style.background = o.optBgColor;
		}
		el.style.color = o.optTxtHover;
		el.style.background = o.optBgHover;
	},
	onscrollbar : function(e){
		try{
			e.preventDefault();
			e.stopPropagation();
		}catch(e){
			e.returnValue  = false;
			e.cancelBubble = true;
		}
	},
	paint : function(){
		var o = this.options;
		var s = this._source;
		var op;

		this._list_el.innerHTML = "";
		this._list_el.style.width = "";
		this._list_el.style.height = "";

		for( var i = 0; i < s.options.length; i++ ){
			( op = this._makeOption( s.options[i].value, s.options[i].text ) )._index = i;

			with( op.style ){
				padding = o.optTxtPadding;
				cursor = "pointer";
				color = ( i == this._source.selectedIndex ) ? o.optTxtHover : o.optTxtColor;
				background = ( i == this._source.selectedIndex ) ? o.optBgHover : o.optBgColor;
			}
			this._list_el.appendChild( op );
		}

		var old = this._list_el.style.display;

		this._list_el.style.display = "block";

		if( ( this._list_el.offsetHeight-2 ) > op.offsetHeight * o.listSize )
			this._list_el.style.height = op.offsetHeight*o.listSize;

		this._list_el.style.display = old;
	},
	_makeOption : function( value, text ){
		var o = WGN_SD.$c( "div" );
		var t = this;

		o._value = value;
		o.appendChild( document.createTextNode( text ) );
		o.onmouseover = function(e){
			t.onover.call( t, e || window.event )
		}
		o.onmousedown = function(e){
			t.onselect.call( t ,e || window.event )
		}

		return o;
	}
});



// ie6 png use : css class 선언 .png24{ tmp:expression(setPng24(this)); }
function setPng24( obj ){
	obj.width = obj.height = "1";
	obj.className = obj.className.replace( /\bpng24\b/i, "" );
	obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + obj.src + "',sizingMethod='image');";
	obj.src = "";
	return "";
}

// comm left menu
function snb( act ){
	var f_obj = $( "snb" );
	if( f_obj.menu ) clearTimeout( f_obj.menu );

	if( act == 1 )	f_obj.setStyle({ width: "167px" })
	else			f_obj.menu = setTimeout( "snbWidth( 'snb', 22 )", 1000 );
}

function snbWidth( obj, o_width ){
	$( obj ).setStyle({ width : o_width + "px" })
}

function layerControl( val ){
	var obj = $("top_menu");

	if( val == "0" ){
		obj.style.height = "50px";

	}else if( val == "1" ){
		obj.style.height = "20px";
	}
}

//-----------------------------------------------------------------------------
// 게이트메뉴 슬라이딩 체크
//-----------------------------------------------------------------------------
function initCheck(){
	if( wgn.getCookie( "gmMenu" ) != "done" ){
		window.document.GateMenu.jasCheck();
		wgn.setCookie( "gmMenu", "done", 30 );
	}
}

//-----------------------------------------------------------------------------
// TAB EVENT
//-----------------------------------------------------------------------------
function tabEvent( obj, obj_arr, classUse )
{
	var p_obj = obj.parentNode;
	var c_list = p_obj.getElementsByTagName( "LI" );
	var c_img  = p_obj.getElementsByTagName( "IMG" );

	for( var i=0; i<c_img.length; i++ ) {

		if( i == obj_arr ) {
			c_img[i].src = c_img[i].src.match( "on.gif" ) ? c_img[i].src : c_img[i].src.substr( 0, c_img[i].src.indexOf(".gif") ) + "on.gif";
			if( classUse == true ) c_list[i].className = "m_on";
			if( $(p_obj.id + "_" + i) != null ) $( p_obj.id + "_" + i ).show();

		} else {
			c_img[i].src = c_img[i].src.match( "on.gif" ) ? c_img[i].src.substr( 0, c_img[i].src.indexOf("on.gif") ) + ".gif" : c_img[i].src;
			if( classUse == true ) c_list[i].className = "m_out";
			if( $(p_obj.id + "_" + i) != null ) $( p_obj.id + "_" + i ).hide();
		}
	}
}


//-----------------------------------------------------------------------------
// 즐겨찾기 추가
//    bookmarksite( site title, url )
//-----------------------------------------------------------------------------
function bookmarkSite( title, url ){
	if( window.sidebar ){
		// firefox
		window.sidebar.addPanel(title, url, "");

	}else if( window.opera && window.print ){
		// opera
		var elem = document.createElement( 'a' );
		elem.setAttribute( 'href', url );
		elem.setAttribute( 'title', title );
		elem.setAttribute( 'rel', 'sidebar' );
		elem.click();
	}else if( document.all ){
		// ie
		window.external.AddFavorite( url, title );

	}
}
function enjoy(){
	bookmarkSite( '톡톡맘 - 아가방앤컴퍼니 커뮤니티', 'http://www.talktalkmom.com' );
}

function snbPosition(){
	if( !document.getElementById("snb") ) return false;
	var tmp_menu = $( "snb" );
	tmp_menu.setStyle({
		position:"absolute",
		left:"0",
		top:"156px",
		zIndex:"9999",
		overflow:"hidden",
		width:"22px",
		height:"775px"
	})
}
addLoadEventFunc( snbPosition );

function addLoadEventFunc( func ){
	var oldOnload = window.onload;

	if( typeof window.onload != 'function' ){
		window.onload = func;
	}else{
		window.onload = function(){
			oldOnload();
			func();
		}
	}
}

/* --------------------------------------------------- 090414 이후 추가 --------------------------------------------------- */
function sMenuActive(){
	if( !document.getElementById( "sMenu" ) ) return false;

	var sMenu = document.getElementById( "sMenu" );
	var item = sMenu.getElementsByTagName( "img" );

	for( var i=0; i<item.length; i++ ){
		item[i].onmouseover = function(){
			if(this.className != "on") this.src = this.src.substr( 0, this.src.indexOf("_out.gif")) + "_over.gif";
		}
		item[i].onmouseout = function(){
			if(this.className != "on") this.src = this.src.substr( 0, this.src.indexOf("_over.gif")) + "_out.gif";
		}
	}
}
addLoadEventFunc( sMenuActive );

function sliding(list_id, interval) {
	if (document.getElementById("'"+list_id+"'")){
		return false;
	}

	var obj = $(list_id);
	var item = $$("#"+ list_id + " li");
	var btnPrev = $(list_id + "Prev");
	var btnNext = $(list_id + "Next");
	var obj_width = item[0].getWidth() * item.length;

	obj.mouseEvent = interval;
	obj.setStyle({
		width: obj_width + "px"
	})

	if (!obj.style.top || !obj.style.left) {
		obj.setStyle({
			top:"0px",
			left:"0px"
		})
	}

	if (item.length == 1) {
		btnPrev.hide();
		btnNext.hide();
	} else {
		obj.rolling = setInterval( function () {
			if (parseInt(obj.style.left) == -item[0].getWidth() * (item.length-1)) {
				moveElement(list_id, '0', '0', 10)
			} else {
				var tmpLeft = parseInt(obj.style.left) - item[0].getWidth();
				if(tmpLeft >= -item[0].getWidth() * (item.length-1) && tmpLeft%item[0].getWidth() == 0) {
					moveElement(list_id, tmpLeft, '0', 10)
				}
			}
		}, obj.mouseEvent );

		obj.onmouseover = function () {
			clearInterval( obj.rolling );
		}
		obj.onmouseout = function () {
			obj.rolling = setInterval( function () {
				if (parseInt(obj.style.left) == -item[0].getWidth() * (item.length-1)) {
					moveElement(list_id, '0', '0', 10)
				} else {
					var tmpLeft = parseInt(obj.style.left) - item[0].getWidth();
					if(tmpLeft >= -item[0].getWidth() * (item.length-1) && tmpLeft%item[0].getWidth() == 0) {
						moveElement(list_id, tmpLeft, '0', 10)
					}
				}
			}, obj.mouseEvent );
		}

		btnPrev.onmouseover = function () {
			clearInterval( obj.rolling );

		}
		btnPrev.onmouseout = function () {
			obj.rolling = setInterval( function () {
				if (parseInt(obj.style.left) == -item[0].getWidth() * (item.length-1)) {
					moveElement(list_id, '0', '0', 10)
				} else {
					var tmpLeft = parseInt(obj.style.left) - item[0].getWidth();
					if(tmpLeft >= -item[0].getWidth() * (item.length-1) && tmpLeft%item[0].getWidth() == 0) {
						moveElement(list_id, tmpLeft, '0', 10)
					}
				}
			}, obj.mouseEvent );
			
		}
		btnPrev.onclick = function () {
			if (parseInt(obj.style.left) == 0) {
				return false;
			} else {
				var tmpLeft = parseInt(obj.style.left) + item[0].getWidth();
				if(tmpLeft <= 0 && tmpLeft % item[0].getWidth() == 0) {
					moveElement(list_id, tmpLeft, '0', 10)
				}
			}
		}

		btnNext.onmouseover = function () {
			clearInterval( obj.rolling );

		}
		btnNext.onmouseout = function () {
			obj.rolling = setInterval( function () {
				if (parseInt(obj.style.left) == -item[0].getWidth() * (item.length-1)) {
					moveElement(list_id, '0', '0', 10)
				} else {
					var tmpLeft = parseInt(obj.style.left) - item[0].getWidth();
					if(tmpLeft >= -item[0].getWidth() * (item.length-1) && tmpLeft%item[0].getWidth() == 0) {
						moveElement(list_id, tmpLeft, '0', 10)
					}
				}
			}, obj.mouseEvent );
			
		}
		btnNext.onclick = function () {
			if (parseInt(obj.style.left) == -item[0].getWidth() * (item.length-1)) {
				return false;
			} else {
				var tmpLeft = parseInt(obj.style.left) - item[0].getWidth();
				if(tmpLeft >= -item[0].getWidth() * (item.length-1) && tmpLeft%item[0].getWidth() == 0) {
					moveElement(list_id, tmpLeft, '0', 10)
				}
			}
		}
	}
}


function moveElement(elementID, final_x, final_y, interval){
	if( !document.getElementById ) return false;
	if( !document.getElementById( elementID ) ) return false;

	var elem = document.getElementById( elementID );

	if( elem.movement ) clearTimeout( elem.movement );

	if( !elem.style.left ) elem.style.left = "0px";
	if( !elem.style.top ) elem.style.top = "0px";

	var xpos = parseInt( elem.style.left );
	var ypos = parseInt( elem.style.top );

	if( xpos == final_x && ypos == final_y ){
		return true;
	}

	if( xpos < final_x ){
		var dist = Math.ceil( (final_x - xpos)/8 );
		xpos = xpos + dist;
	}
	if( xpos > final_x ){
		var dist = Math.ceil( (xpos - final_x)/8 );
		xpos = xpos - dist;
	}

	if( ypos < final_y ){
		var dist = Math.ceil( (final_y - ypos)/8 );
		ypos = ypos + dist;
	}
	if( ypos > final_y ){
		var dist = Math.ceil( (ypos - final_y)/8 );
		ypos = ypos - dist;
	}

	elem.style.left = xpos + "px";
	elem.style.top = ypos + "px";

	var repeat = "moveElement('" + elementID + "'," + final_x + "," + final_y + "," + interval + ")";
	elem.movement = setTimeout( repeat, interval );
}

function listRolling(list_id) {
	var obj = $(list_id);
	var item = $$("#"+ list_id +" li");

	if ( item.length < 4 ) return false;

	var moveLeft = 3;
	var obj_width = item[0].getWidth() * item.length;

	if (!obj.style.top || !obj.style.left) {
		obj.setStyle({
			top:"0px",
			left:"0px"
		})
	}
	
	obj.innerHTML = obj.innerHTML + obj.innerHTML;

	setInterval( function() {
		if (parseInt(obj.style.left) > -obj_width) {
			obj.setStyle({
				left: parseInt(obj.style.left) - moveLeft + "px"
			})
		} else {
			if(!obj.tmp) {
				var posLeftStart = obj_width % moveLeft;
				
			} else {
				var posLeftStart = (obj_width-obj.tmp) % moveLeft;
			}
			var x = moveLeft - posLeftStart;

			obj.setStyle({
				left: -x + "px"
			})
			
			obj.tmp = x;
		}
	}, 20 );
}