var max_zIndex=100000;
var _anchors = [];

/*************************************************************
// ie6의 백그라운드 이미지 없어지는 문제 해결책
*************************************************************/
if($.browser.msie) {
   var head = document.getElementsByTagName("head")[0];
   var css = document.createElement("link");

   css.setAttribute("rel", "stylesheet");
   css.setAttribute("type", "text/css");
   css.setAttribute("href","/_common/ie6.css");
   head.appendChild(css);
}


/*************************************************************
// 공통 함수
*************************************************************/
var getAllChildren = function(obj, arr) {
	/*
	for(var i=0;i<obj.children.length;i++) {
		if(obj.children[i].tagName != "!")
			arr.push(obj.children[i]);
		getAllChildren(obj.children[i], arr);
	}
	*/

	var ccc = $(obj).children();
	for(var i=0;i<ccc.length;i++) {
		if(ccc.get(i).tagName != "!")
			arr.push(ccc.get(i));
		getAllChildren(ccc.get(i), arr);
	}
}


// String prototype -------------------------------------------
String.prototype.encodeURI = function( url ) {
	return encodeURIComponent(this);
}

String.prototype.test = function(regex, params){
	return ((typeof regex == 'string') ? new RegExp(regex, params) : regex).test(this);
}

String.prototype.contains= function(string, separator){
	return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : this.indexOf(string) > -1;
}

String.prototype.trim= function(){
	return this.replace(/^\s+|\s+$/g, '');
}

String.prototype.clean= function(){
	return this.replace(/\s+/g, ' ').trim();
}

String.prototype.camelCase= function(){
	return this.replace(/-\D/g, function(match){
		return match.charAt(1).toUpperCase();
	});
}

String.prototype.hyphenate= function(){
	return this.replace(/[A-Z]/g, function(match){
		return ('-' + match.charAt(0).toLowerCase());
	});
}

String.prototype.capitalize= function(){
	return this.replace(/\b[a-z]/g, function(match){
		return match.toUpperCase();
	});
}

String.prototype.escapeRegExp= function(){
	return this.replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1');
}

String.prototype.toInt= function(base){
		return parseInt(this, base || 10);
	}

String.prototype.toFloat= function(){
	return parseFloat(this);
}

String.prototype.hexToRgb= function(array){
	var hex = this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
	return (hex) ? hex.slice(1).hexToRgb(array) : null;
}

String.prototype.rgbToHex= function(array){
	var rgb = this.match(/\d{1,3}/g);
	return (rgb) ? rgb.rgbToHex(array) : null;
}

String.prototype.stripScripts= function(option){
	var scripts = '';
	var text = this.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(){
		scripts += arguments[1] + '\n';
		return '';
	});
	if (option === true) $exec(scripts);
	else if ($type(option) == 'function') option(scripts, text);
	return text;
}

String.prototype.htmlEncode = function(){
	return this.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");
}

String.prototype.htmlDecode = function(){
  return this.replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
}


String.prototype.substitute= function(object, regexp){
	return this.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
		if (match.charAt(0) == '\\') return match.slice(1);
		return (object[name] != undefined) ? object[name] : '';
	});
}


String.prototype.replaceAll = function(FindString, ReplaceString) {
	var SearchIndex = 0;
	var NewString = "";
	while (this.indexOf(FindString,SearchIndex) != -1)    {
  	NewString += this.substring(SearchIndex,this.indexOf(FindString,SearchIndex));
  	NewString += ReplaceString;
  	SearchIndex = (this.indexOf(FindString,SearchIndex) + FindString.length);
 	}
	NewString += this.substring(SearchIndex,this.length);
	return NewString;
}


//*************************************************************
// 배경이미지 오버/아웃
// id, sson_url, sson_over_bg, sson_out_bg, sson_sel_over_bg, sson_sel_out_bg,
// ssoff_url, ssoff_over_bg, ssoff_out_bg, ssoff_sel_over_bg, ssoff_sel_out_bg,
//*************************************************************
function jwxe_changeBgCss(obj,url) {

	//$(obj).css('display','none');
	obj.css('background-image','url('+url+')');
	//$(obj).fadeIn('fast');
}

function jwxe_setMouseOverOut(obj, over_bg, out_bg){

	$(
		function() {
			obj.hover(function(){
		  		jwxe_changeBgCss($(this),over_bg);
		  });
			obj.focus(function(){
		  		jwxe_changeBgCss($(this),over_bg);
		  })
		}
	)

	$(
		function() {
			obj.mouseout(function(){
		  		jwxe_changeBgCss($(this),out_bg);
		  });
			obj.blur(function(){
		  		jwxe_changeBgCss($(this),out_bg);
		  });
		}
	)


}

function jwxe_clearMouseOverOut(obj){

	obj.unbind('hover');
	obj.unbind('focus');
	obj.unbind('blur');
	obj.unbind('mouseout');

}


function jwxe_changeBg(obj){
	_anchors.push(obj);
}

function jwxe_bubble_select(el) {

	var j, parent = el.parent().parent(), tagName = parent.attr('tagName'), a;

	while (tagName && tagName.toLowerCase() == "ul" && parent.css("display") == "none") {
	//if (next && (tagName = next.attr("tagName")) != null && (tagName.toLowerCase() == "ul") && next.css("display") == "none") {
		parent.css("display", "block");
		a = parent.prev();
		if(a && (tag = a.attr('tagName')) && tag.toLowerCase() == 'a' ) {
			j = a.get(0);
			if(j && j.bgObj) {
				//console.log(j.bgObj);
				j.bgObj.select = true;
				jwxe_clearMouseOverOut(a);
				jwxe_changeBGProc(j.bgObj);
				//jwxe_changeBgCss(a, j.selectBg);

			}
		}
		parent = a.parent().parent();
		tagName = parent.attr('tagName');

	}

}


function jwxe_set_select(id) {
	var a = $('#'+id);
	var j = a.get(0);
	j.bgObj.select = true;
	jwxe_clearMouseOverOut(a);
	jwxe_changeBGProc(j.bgObj);

}


function jwxe_changeBGProc(obj) {
try{
	var sson_url = obj.sson_url?obj.sson_url:obj.ssoff_url;
	var ssoff_url = obj.ssoff_url;
	var el = $('#'+obj.id);
	el.get(0).bgObj = obj;
	//var _uIndex = sson_url.indexOf("?");
	//if(_uIndex>-1) sson_url = sson_url.substring(0,_uIndex);
	//_uIndex = ssoff_url.indexOf("?");
	//if(_uIndex>-1) ssoff_url = ssoff_url.substring(0,_uIndex);

	if(_isSessionOn) {


		//if(_thisUrl.indexOf(sson_url) > -1 ) { // session on, selected
		//el.get(0).selectBg = obj.sson_sel_out_bg;
		if(obj.select == true) { // session on, selected
			//var sson_sel_over_bg = obj.sson_sel_over_bg ? obj.sson_sel_over_bg : (obj.ssoff_sel_over_bg?obj.ssoff_sel_over_bg:obj.ssoff_over_bg);
			$( function() { jwxe_bubble_select(el); } );
			if(obj.sson_sel_out_bg) {
				$( function(){
						jwxe_changeBgCss(el, obj.sson_sel_out_bg);
					}
				);
				if(obj.sson_sel_over_bg ) {
					jwxe_setMouseOverOut(el,obj.sson_sel_over_bg,obj.sson_sel_out_bg);
				}
			} else {
				if(obj.sson_out_bg) {
					if(obj.sson_over_bg ) {
						jwxe_setMouseOverOut(el,obj.sson_over_bg,obj.sson_out_bg);
					}
				} else {
					if(obj.ssoff_sel_out_bg) {
						if(obj.ssoff_sel_over_bg) {
							jwxe_setMouseOverOut(el,obj.ssoff_sel_over_bg,obj.ssoff_sel_out_bg);
						}
					} else {
						if(obj.ssoff_over_bg && obj.ssoff_out_bg) {
							jwxe_setMouseOverOut(el,obj.ssoff_over_bg,obj.ssoff_out_bg);
						}
					}

				}
			}

		}	else {
			if(obj.sson_out_bg) {
				if(obj.sson_over_bg) {
					jwxe_setMouseOverOut(el,obj.sson_over_bg,obj.sson_out_bg);
				}
			} else {
				if(obj.ssoff_over_bg && obj.ssoff_out_bg) {
					jwxe_setMouseOverOut(el,obj.ssoff_over_bg,obj.ssoff_out_bg);
				}
			}
		}

	} else {

		//if(_thisUrl == _thisHost+ssoff_url ) { // session off, selected
		//if(_thisUrl.indexOf(ssoff_url) > -1) {
		//el.get(0).selectBg = obj.ssoff_sel_out_bg;

		if(obj.select == true) { // session on, selected
			$( function() { jwxe_bubble_select(el); } );
			if(obj.ssoff_sel_out_bg) {
				$( function() {
						jwxe_changeBgCss(el,obj.ssoff_sel_out_bg);
					}
				)
				if(obj.ssoff_sel_over_bg) {
					jwxe_setMouseOverOut(el,obj.ssoff_sel_over_bg,obj.ssoff_sel_out_bg);
				}
			} else {
				if(obj.ssoff_over_bg && obj.ssoff_out_bg) {
					jwxe_setMouseOverOut(el,obj.ssoff_over_bg,obj.ssoff_out_bg);
				}
			}

		}	else {
			if(obj.ssoff_over_bg && obj.ssoff_out_bg) {
				jwxe_setMouseOverOut(el,obj.ssoff_over_bg,obj.ssoff_out_bg);
			}
		}

	}
}catch(E){}
}

/*************************************************************
// 엥커 마우스 오버/아웃/셀렉트
*************************************************************/
$(
	function() {

		var key, i, obj, url, objs = [], curUrl = document.location.href, found = false;

		//셀렉트를 판단
		for(i=0; i<_anchors.length; i++) {

			obj = _anchors[i];

			url = obj.ssoff_url;

			if(url == '' || url == '#') continue;

			if (_isSessionOn) {
				url = obj.sson_url ? obj.sson_url : obj.ssoff_url;
			}
			url = _thisHost + url.trim().replace(_thisHost,'');

			obj.select = false;
			if(curUrl == url) {
				obj.select = true;
				found = true;
			} else if(curUrl.indexOf(url) > -1) {
				obj.length = url.length;
				objs.push( obj );
			}

		}
		var length = 0;
		if(!found) {
			//부분 일치하는 도메인중 길이가 큰 검색
			var index = -1, max = 0;
			for(i=0; i<objs.length; i++) {
				if(objs[i].length >= max) {
						max = objs[i].length;
						index = i;
				}
			}

			if(index != -1) {
				length = objs[index].length;
				//objs[index].select = true;
			}
		}

		for(i=0;i<objs.length;i++) {
			if(length == objs[i].length)
				objs[i].select = true;
		}


		for (i = 0; i < _anchors.length; i++) {
			jwxe_changeBGProc(_anchors[i]);
		}


	}
)

/*************************************************************
// 메인 관련
*************************************************************/
/*
$(
	function() {
		var jwxe_menu_boxs = $("ul[class=jwxe_menu_box0]");
		for(var i=0;i<jwxe_menu_boxs.length;i++) {
			var children = new Array();
			getAllChildren(jwxe_menu_boxs.get(i), children);
			for(var j=0;j<children.length;j++) {
				var emt = $(children[j]);
				if(emt.attr("tagName").toLowerCase() == "ul") {
					emt.css("display", "none");
				}
			}
		}
	}
)
*/

var func_jwxe_menu_box0 = function() {
	var next = $(this).next();
	var tagName = "";

	next.attr("display", "block");
	var parent = $(this);
	do {
		parent.attr("display", "block");
		parent = parent.parent();
	} while(parent.attr("class") != "jwxe_menu_box0");

	parent = $(this);
	do {
		parent = parent.parent();
	} while(parent.attr("class") != "jwxe_menu_box0");

	var tmp_parent = parent;
	do {
		tmp_parent = tmp_parent.parent();
	} while(tmp_parent.attr("class").indexOf("lo_") == -1);
	tmp_parent.css("z-index", max_zIndex);

	var children = new Array();
	getAllChildren(parent.get(0), children);
	for(var j=0;j<children.length;j++) {
		var emt = $(children[j]);
		if(emt.attr("tagName").toLowerCase() == "ul") {
			if(emt.attr("display") == "block") {
				emt.css("display", "block");
				emt.css("z-index", max_zIndex);
			} else {
				emt.css("display", "none");
				emt.css("z-index", "");
			}
		}
		emt.attr("display", "none");
	}
}

$(
	function() {
		$("ul[class=jwxe_menu_box0] a").hover(func_jwxe_menu_box0);
		$("ul[class=jwxe_menu_box0] a").focus(func_jwxe_menu_box0);
	}
)

/*************************************************************
// 탭 View 관련
*************************************************************/

$(
	function() {
		var jwxe_menu_boxs = $("ul[class=jwxe_menu_box2]");
		for(var i=0;i<jwxe_menu_boxs.length;i++) {
			var children = new Array();
			getAllChildren(jwxe_menu_boxs.get(i), children);
			var bFirst = true;
			for(var j=0;j<children.length;j++) {
				var emt = $(children[j]);
				if(emt.attr("tagName").toLowerCase() == "ul") {
					if(bFirst) {
						emt.css("display", "block");
						//emt.css("z-index", max_zIndex);
						bFirst = false;
					} else {
						emt.css("display", "none");
						//emt.css("z-index", "0");
					}
				} else if(emt.attr("tagName").toLowerCase() == "a") {
					emt.css("z-index", max_zIndex);

				}
			}
		}
	}
)

var func_jwxe_menu_box2 = function() {
	var next = $(this).next();
	var tagName = "";

	next.attr("display", "block");
	var parent = $(this);
	do {
		parent.attr("display", "block");
		parent = parent.parent();
	} while(parent.attr("class") != "jwxe_menu_box2");

	parent = $(this);
	do {
		parent = parent.parent();
	} while(parent.attr("class") != "jwxe_menu_box2");
	var children = new Array();
	getAllChildren(parent.get(0), children);
	for(var j=0;j<children.length;j++) {
		var emt = $(children[j]);
		if(emt.attr("tagName").toLowerCase() == "ul") {
			if(emt.attr("display") == "block") {
				emt.css("display", "block");
				//emt.css("z-index", max_zIndex);
				//emt.fadeIn();
			} else {
				emt.css("display", "none");
				//emt.css("z-index", "0");
				//emt.fadeOut();
			}
		}
		emt.attr("display", "none");
	}
}

$(
	function() {
		$("ul[class=jwxe_menu_box2] a").hover(func_jwxe_menu_box2);
		$("ul[class=jwxe_menu_box2] a").focus(func_jwxe_menu_box2);
	}
)


/*************************************************************
// 밑으로 늘어나는 서브 메뉴 관련
*************************************************************/
/*
$(
	function() {
		var tmp = $("*[class=jwxe_menu_box1] *");
		for(var i=0;i<tmp.length;i++) {
			var t = $(tmp.get(i));
			t.css("position", "static");
		}

		var menus = $("*[class=jwxe_menu_box1] a");
		for(var i=0;i<menus.length;i++) {
			var menu = $(menus.get(i));
			var w = menu.css("width");
			var next = menu.next();
			var tagName = "";
			if((tagName=next.attr("tagName")) != null && (tagName.toLowerCase() == "ul")) {
				//next.css("overflow", "hidden");
				//next.css("height", "0");
				//next.css("display", "none");
				//next.css("width", "200px");
			}
		}
	}
)
*/


/*
var func_jwxe_menu_box1 = function() {


	var next = $(this).next();
	var tagName = "";
	if((tagName=next.attr("tagName")) != null && (tagName.toLowerCase() == "ul")) {
		var of = next.css("overflow");
		if(of == "hidden") {
			next.css("overflow", "");
			next.css("height", "");
		} else {
			next.css("overflow", "hidden");
			next.css("height", "0");
		}
	}

}
*/
var jwxe_menu_box1_click = function() {


		var li = $(this).parent();
		var ul = li.parent();
		var objs = ul.children(), a;
		//console.log(li, objs);
		for(var i=0; i<objs.length; i++) {
			var obj = objs[i];
			if(li[0] != obj) {
				//console.log(obj);
				if(obj.children.length > 0 && obj.children[0])
					$(obj.children[0]).next().css("display", "none");
			}
		}



  	var next = $(this).next();
  	var tagName = "";
  	if ((tagName = next.attr("tagName")) != null && (tagName.toLowerCase() == "ul")) {

  		var dip = next.css("display");
  		if (dip == "none") {
	  		next.css('display','block');
  		} else {
	  		next.css('display','none');
			}
  	}

}


$(
	function() {

		//$(".jwxe_menu_box1 a").css({'position':'relative','border':'1px solid blue', 'margin-top':'5px'});
		//$(".jwxe_menu_box1 ul").css({'position':'relative','border':'1px solid red', 'margin-top':'5px'});
		$(".jwxe_menu_box1 a").css('position','relative');
		$(".jwxe_menu_box1 ul").css('position','relative');

		$(".jwxe_menu_box1 a").each( function() {
			var next = $(this).next(), tagName;
			if(next) {
				tagName = next.attr("tagName");
				if(tagName && tagName.toLowerCase() == "ul") {
					$(this).attr("href","#");
				}
			}
		});

		//$(".jwxe_menu_box1 ul").css('position','relative');

		$(".jwxe_menu_box1 a").mousedown(jwxe_menu_box1_click);
		//$("[class=jwxe_menu_box1] a").mouseout(func_jwxe_menu_box1);
	}
)

/*************************************************************
// 플래시 삽입
*************************************************************/
$(
	function() {
		var objs = $("object[type=application/x-shockwave-flash]");
		for(var i=0;i<objs.length;i++) {
			obj = $(objs.get(i));
			var w = obj.attr("width");
			var h = obj.attr("height");
			var u = obj.attr("data");
			var str =
				"<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='" + w + "' height='" + h + "'>" +
				"<param name='wmode' value='transparent' />" +
				"<param name='allowScriptAccess' value='sameDomain' />" +
				"<param name='movie' value='" + u + "' />" +
				"<param name='quality' value='high' />" +
				//"<embed src='" + u + "' quality='high' width='" + w + "' height='" + h + "' name='flash' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' wmode='Transparent' pluginspage='http://www.macromedia.com/go/getflashplayer'>" +
				"</object>";
			obj.attr("outerHTML", str);
		}
	}
)

/*************************************************************
// IE 버그 수정
*************************************************************/
		/*
$(
	function() {
		$("img").css("behavior", "url(/_common/iepngfix/iepngfix.htc)");
		$("input").css("behavior", "url(/_common/iepngfix/iepngfix.htc)");
		$("ul").css("behavior", "url(/_common/iepngfix/iepngfix.htc)");
	}
)
		*/


/*************************************************************
// 탭처리
*************************************************************/



/*************************************************************
// 팝업코드 처리
*************************************************************/
$(
	function() {
		$("div[class=jwxe_popup]").css("z-index",max_zIndex+1);
	}
)

$(
	function() {
		var popups = $("div[class=jwxe_popup]");
		var _left = 10;
		var left = 10;
		var top = 150;
		for(var i=0;i<popups.length;i++) {
			var p = $(popups.get(i));
			if((left+p.width()) > 1024) {
				left = (_left+=50);
				top += 50;
			}
			p.css("left", left);
			p.css("top", top);
			left += (p.width() + 10);
		}
	}
)

$(
	function() {
		$("a[class=jwxe_popup_close]").click(
			function() {
				$(this).parent().css("display","none");
			}
		);
	}
)
$(
	function() {
		$("a[class=jwxe_popup_close_7]").click(
			function() {
				$(this).parent().css("display","none");
				var nm = $(this).attr("name");
				var idx = nm.indexOf("_");
				nm = "/" + nm.substring(0, idx) +"/_popup/" + nm.substring(idx+1);
				$.get(nm);
			}
		);
	}
)
$(
	function() {
		var popup_objs = $("a[class=jwxe_popup_close]");
		var popup7_objs = $("a[class=jwxe_popup_close_7]");
		for(var i=0;i<popup_objs.length;i++) {
			var pc = $(popup_objs.get(i));
			var pc7 = $(popup7_objs.get(i));
			var pt = pc.parent();
			var w = pt.width();
			var h = pt.height();
			pc.css("top", (h - 24) + "px");
			pc.css("left", (w - 54) + "px");
			pc7.css("top", (h - 24) + "px");
			pc7.css("left", (w - 168) + "px");
		}
	}
)
/*************************************************************
// 설문  처리
*************************************************************/
$(
	function() {
		var vote_objs = $("input[class=jwxe_survey_vote]");
		vote_objs.css("top", (vote_objs.parent().parent().parent().height() - 39) + "px");
		vote_objs.css("left", (vote_objs.parent().parent().parent().width() - 92) + "px");

		var q_objs = $("div[class=jwxe_survey_q]");
		q_objs.css("width", (q_objs.parent().parent().parent().parent().width() - 50) + "px");

		var r_objs = $("div[class=jwxe_survey_r]");
		r_objs.css("width", (r_objs.parent().width() - 50) + "px");
	}
)

/*************************************************************
// JWXE_A_MASTER인 경우 처리 Mouse Over, Focus에 반응하는 Layer 관련 Script
*************************************************************/
// 먼저 모두 숨겨준다.
$(
	function() {
		$("*[class=jwxe_a_master]").next().css("display","none");
	}
)

$(
	function() {
		$("*[class=jwxe_a_master]").focus(
			function() {
				$("*[class=jwxe_a_master]").next().css("display","none");
				$("*[class=jwxe_a_master]").next().css("z-index", "");
				$(this).next().css("z-index",max_zIndex);
				$(this).next().fadeIn();
			}
		)
	}
)
$(
	function() {
		$("*[class=jwxe_a_master]").mouseover(
			function() {
				$("*[class=jwxe_a_master]").next().css("display","none");
				$("*[class=jwxe_a_master]").next().css("z-index", "");
				$(this).next().css("z-index",max_zIndex);
				$(this).next().fadeIn();
			}
		)
	}
)

/**********************************************************************
// Banner1 타입 제자리에서 계속 배너가 변화하는 타입.
**********************************************************************/
// 최초 로드시 맨 앞에 배너가 처음에 보이도록 해야 한다.
$(
	function() {
		var banners = $("ul[class=jwxe_banner1]");
		for(var bi=0;bi<banners.length;bi++) {
			var siblings = $(banners[bi]).children();
			for(var i=0;i<siblings.length;i++) {
				$($(siblings[i]).children()[0]).css("z-index",0);
				$($(siblings[i]).children()[0]).css("left",0);
				$($(siblings[i]).children()[0]).css("top",0);
				$($(siblings[i]).children()[0]).attr("jwxe_isFocus", "false");
			}
			if(siblings.length > 0) {
				$($(siblings[0]).children()[0]).css("z-index",1);
			}
		}
	}
)

// 탭 선택시 선택된 Link가 최 상단에 나타나도록 처리되어야 한다.
$(
	function() {
		$("ul[class=jwxe_banner1] li a").focus(
			function() {
				// 자신의 부모중 모든 놈들의 z-Index를 0으로 만들고.. 자신의 z-Index만 1로 만든다.
				var siblings = $(this).parent().parent().children();
				for(var i=0;i<siblings.length;i++) {
					$($(siblings[i]).children()[0]).css("z-index",0);
					$($(siblings[i]).children()[0]).attr("jwxe_isFocus", "false");
				}
				$(this).css("z-index",1);
				$(this).attr("jwxe_isFocus", "true");
			}
		)
	}
)

$(
	function() {
		$("ul[class=jwxe_banner1] li a").blur(
			function() {
				$(this).attr("jwxe_isFocus", "false");
			}
		)
	}
)

$(
	function() {
		$("ul[class=jwxe_banner1] li a").mouseover(
			function() {
				$(this).attr("jwxe_isFocus", "true");
			}
		)
	}
)

$(
	function() {
		$("ul[class=jwxe_banner1] li a").mouseout(
			function() {
				$(this).attr("jwxe_isFocus", "false");
			}
		)
	}
)

// 자기 자식들에게 Focus가 없다면 2초 단위로 배너가 교체 되도록 한다.
$(
	function() {
		setInterval(
			function() {
				var banners = $("ul[class=jwxe_banner1]");
				for(var bi=0;bi<banners.length;bi++) {
					var siblings = $(banners[bi]).children();
					var focus_idx = -1;
					for(var i=0;i<siblings.length;i++) {
						if($($(siblings[i]).children()[0]).attr("jwxe_isFocus") == "true") {
							// 누군가 Focus를 가진 상태이므로 중지한다.
							focus_idx = -1;
							break;
						}
						if($($(siblings[i]).children()[0]).css("z-index") == 1) {
							focus_idx = i;
							break;
						}
					}
					if(focus_idx != -1) {
						for(var i=0;i<siblings.length;i++) {
							$($(siblings[i]).children()[0]).css("z-index", "0");
						}
						$($(siblings[((focus_idx+1)%siblings.length)]).children()[0]).css("z-index", "1");
					}
				}
			}
			,2000
		);
	}
)

/**********************************************************************
// Banner2 타입 배너가 우에서 좌로 흐르는 타입
**********************************************************************/
// 최초 모든 배너들이 잘 늘어서도록 처리해야 한다.
$(
	function() {
		var banners = $("ul[class=jwxe_banner2]");
		for(var bi=0;bi<banners.length;bi++) {
			$(banners[bi]).attr("jwxe_dir", "+");
			var siblings = $(banners[bi]).children();
			var x = 0;
			for(var i=0;i<siblings.length;i++) {
				$($(siblings[i]).children()[0]).css("left", x);
				$($(siblings[i]).children()[0]).css("top", 0);
				x += (parseInt($($(siblings[i]).children()[0]).css("width")) + 5);
				$($(siblings[i]).children()[0]).attr("jwxe_isFocus", "false");
			}
		}
	}
)

// focus를 가지거나 마우스가 올라오면 멈춘다.
$(
	function() {
		$("ul[class=jwxe_banner2] li a").focus(
			function() {
				$(this).attr("jwxe_isFocus", "true");
			}
		)
	}
)

$(
	function() {
		$("ul[class=jwxe_banner2] li a").blur(
			function() {
				$(this).attr("jwxe_isFocus", "false");
			}
		)
	}
)

$(
	function() {
		$("ul[class=jwxe_banner2] li a").mouseover(
			function() {
				$(this).attr("jwxe_isFocus", "true");
			}
		)
	}
)

$(
	function() {
		$("ul[class=jwxe_banner2] li a").mouseout(
			function() {
				$(this).attr("jwxe_isFocus", "false");
			}
		)
	}
)

// 흐르게 한다.
$(
	function() {
		setInterval(
			function() {
				var banners = $("ul[class=jwxe_banner2]");
				for(var bi=0;bi<banners.length;bi++) {
					var siblings = $(banners[bi]).children();
					var isFocus = false;
					for(var i=0;i<siblings.length;i++) {
						if($($(siblings[i]).children()[0]).attr("jwxe_isFocus") == "true") {
							isFocus = true;
							break;
						}
					}
					if(!isFocus) {
						var prev = $(banners[bi]).scrollLeft();
						if($(banners[bi]).attr("jwxe_dir") == "+") {
							$(banners[bi]).scrollLeft($(banners[bi]).scrollLeft()+2);
						} else {
							$(banners[bi]).scrollLeft($(banners[bi]).scrollLeft()-2);
						}
						if(prev == $(banners[bi]).scrollLeft()) {
							if($(banners[bi]).attr("jwxe_dir") == "+") {
								$(banners[bi]).attr("jwxe_dir", "-");
							} else {
								$(banners[bi]).attr("jwxe_dir", "+");
							}
						}
					}
				}
			}
			,50
		);
	}
)

/**********************************************************************
// 브라우저에 가로폭이 꽉차는 배경 처리 관련...
**********************************************************************/
// 시작시점에 layout용으로 설정된 DIV 태그에 대해 가상으로 자식 엘리먼트를 추가하고 Background를 설정한다.\
$(
	function() {
		var divs = $("div[class^=lo_]");
		for(var i=0;i<divs.length;i++) {
			var div = $(divs.get(i));
			var bg = div.css("background");
			if(bg != null && bg != "" && bg != undefined) {
				var vt = "<div class='JWXE_BG' style='visibility:hidden;display:none;position:absolute;left:0;top:0;height:0;width:0;background:" + bg + ";z-index:-1000;'>&nbsp;</div>";
				div.append(vt);
				div.css("background", "");
			}
		}
	}
)

var onWindowResize = function() {
	var divs = $("div[class=JWXE_BG]");
	for(var i=0;i<divs.length;i++) {
		var div = $(divs.get(i));
		div.css("left", "-" + div.parent().offset().left + "px");
		div.css("width", document.documentElement.clientWidth + "px");
		div.css("height", div.parent().height());
		//alert(div.parent().height());
		div.css("display", "block");
		div.css("visibility", "visible");
	}
}

// 브라우저 크기가 변할 경우 설정된 가상 엘리먼트들의 폭을 변경해준다.
$(
	function() {
		$(window).resize(onWindowResize);
		setTimeout(onWindowResize, 1);
	}
)

/**********************************************************************
// submit 버튼의 value 를 제거한다
**********************************************************************/
$(
	function() {
		$(".jwxe_input_submit").attr("value", "");
	}
)

/**********************************************************************
// flash wrapper div의  display:none 를 제거한다
**********************************************************************/
$(
	function() {
		$(".jwxe_flash").css("display", "block");
	}
)

/**********************************************************************
// 확대/축소/출력 스크립트
**********************************************************************/
var current_zoom = 100;
var jwxe_zoomIn = function() {
	current_zoom += 10;
  if($.browser.msie && $.browser.version == "6.0"){    // IE
  	$("body").children().css("zoom", current_zoom + "%");
    return;
	}
	alert("화면 확대: 키보드의 control키와 '+'를 동시에 누릅니다.\n화면 축소: 키보드의 control키와 '-'를 동시에 누릅니다.");
}
var jwxe_zoomDef = function() {
  if($.browser.msie && $.browser.version == "6.0"){    // IE
  	$("body").children().css("zoom", "100%");
    return;
	}
	alert("화면 확대: 키보드의 control키와 '+'를 동시에 누릅니다.\n화면 축소: 키보드의 control키와 '-'를 동시에 누릅니다.");
}
var jwxe_zoomOut = function() {
  if($.browser.msie && $.browser.version == "6.0"){    // IE
  	current_zoom -= 10;
  	$("body").children().css("zoom", current_zoom + "%");
    return;
	}
	alert("화면 확대: 키보드의 control키와 '+'를 동시에 누릅니다.\n화면 축소: 키보드의 control키와 '-'를 동시에 누릅니다.");
}

var jwxe_print = function() {
	// 먼저 부모를 찾아서 부모의 outerHTML을 다 넘겨준다.
	var arr = $("div[class=jwxe_root]");
	var max_div = null;
	var max_tb = 0;

	for(var i=0;i<arr.length;i++) {
		var emt = $(arr.get(i));
		var tmp_tb = emt.height() * emt.width();
		if(tmp_tb > max_tb) {
			max_tb = tmp_tb;
			max_div = emt;
		}
	}


	if(max_div != null) {
		var pf = document.getElementById("jwxe_print_form");
		//pf.contents.value = max_div.attr("innerHTML");

		var html = max_div.clone().wrapAll("<div/>").parent().html()


		pf.contents.value = html;
		//pf.contents.value = max_div.attr("outerHTML");
		pf.submit();
	}
}

$(
	function() {
		if($("#jwxe_print_form").length == 0) {
			var str = "<form id='jwxe_print_form' action='/_sys/page_template/print.jsp' method='post' target='_blank'>" +
			"<input type='hidden' name='contents' value='123'/>" +
			"</form>";
			$("body").append(str);
		}
		$("#jwxe_zoomIn").click(jwxe_zoomIn);
		$("#jwxe_zoomOut").click(jwxe_zoomOut);
		$("#jwxe_zoomDef").click(jwxe_zoomDef);
		$("#jwxe_print").click(jwxe_print);
	}
)





$(
	function() {
		var tmp_url = location.href;
		if((tmp_url.indexOf("-02.jsp?") > 0 && tmp_url.indexOf("/dgsisul/") > 0) || (tmp_url.indexOf("-01.jsp?") > 0 && tmp_url.indexOf("/dgsisul/") == -1)) {
			var tds = $("td");
			tds.css("border", "1px solid black");
		}
	}
);
