﻿
$(function(){
	bodyCl = $('body').attr('class');
	

	
/*------------------------
  Header Link
------------------------*/
	if($('body').is(':has("ul#langNav")')){
		$('ul#langNav li').hover(function(){
			var hvrImg = $(this).find('img').attr('src').split('.gif')[0] + '_on.gif';
			$(this).find('img').attr('lowsrc',$(this).find('img').attr('src'));
			$(this).find('img').attr('src',hvrImg);
		},
		function(){
			$(this).find('img').attr('src',$(this).find('img').attr('lowsrc'));
		});
	}
/*------------------------
  topic path
------------------------*/
	if($('body').is(':has("ul#topicPath")')){
		$('<span>&nbsp;&gt;</span>').appendTo('ul#topicPath li a');
	}
	
/*------------------------
  SNavi Anime
------------------------*/
	if($('body').is(':has("#accordion div")')){
		//fast slide
		$('#accordion div').each(function(){
			bodyCl = bodyCl.split(' ')[0];
			if(bodyCl == $(this).attr('id')){
				$(this).attr('class','open');
				//$(this).next().slideDown();
				$(this).next().css('display','block');
			}
		});
		
		//click slide
		$('#accordion div').click(function(){
			toggleID =$(this).attr('id');
			$('#accordion ul').each(function(){
				childID = $(this).attr('id').split('-child')[0];
				if(toggleID != childID){
					$(this).prev().attr('class','close');
					$(this).slideUp();
				}else{
					if($(this).prev().attr('class') == 'open'){
						$(this).prev().attr('class','close');
						$(this).slideUp();
					}else{
						$(this).prev().attr('class','open');
						$(this).slideDown();
					}
				}
			});
		});
	}

/*------------------------
  SNavi move
------------------------*/
	setInterval(move,700);
	function move(){
		var defaultNavTop = $('#accordion.scroll').offsetTop;
		var scrollSize = $('body').scrollTop  || document.documentElement.scrollTop;
		$('#accordion.scroll').animate({marginTop : scrollSize+'px'},'normal');
	};

/*------------------------
  Foreign
------------------------*/
/*
	$('ul#foreign-child li a').click(function(){
			$('ul#foreign-child li a').each(function(){
				$(this).css()
			});
	});
*/
/*------------------------
  SNavi active
------------------------*/

	if($('body').is(':has("ul#sNav")')){
		if($('body').attr('id') == 'recruit'){
			$('ul#sNav li a').each(function(){
				var active = $(this).attr('id').split('-')[1];
				var bodyID = $('body').attr('id');
				if(bodyCl == active){
					$(this).find('img').css('visibility','hidden');
/*
					var actvImg = $(this).find('img').attr('src').split('.gif')[0] + '_active.gif';
					$(this).find('img').attr('src',actvImg);
					if(bodyID == 'recruit'){
						$(this).find('img').attr('width',194);
					}
*/
				}
			});
		}
	}

	if($('body').is(':has("ul#sNav")')){
		if($('body').attr('id') != 'recruit'){
			$('ul#sNav li a').each(function(){
				var active = $(this).attr('id').split('-')[1];
				if(bodyCl == active){
					$(this).css('border-left','5px solid #ff002a');
				}
			});
		}
	}
	
	if($('body').is(':has("ul#sNav")')){
		if($('body').attr('id') == 'topics' || $('body').attr('id') == 'news'){
			$('ul#sNav li a').each(function(){
				var active = $(this).attr('id').split('snav-')[1];
				if(bodyCl.split('y')[1] == active){
					$(this).css('border-left','5px solid #ff002a');
				}
			});
		}
	}
	
	
	if($('body').is(':has("#accordion")')){
		bdCl = $('body').attr('class').split(' ')[0];
		if(bdCl == 'japan'){
			$('ul#japan-child li').each(function(){
				japanCl = $('body').attr('class').split(' ')[1];
				liID = $(this).attr('id').split('snav-')[1];
				if(japanCl == liID){
					$(this).find('a img')
						.css('border-left','5px solid #ff002a')
						.css('background','#ccd7ea');
				}
			});
		}
		
		if(bdCl == 'foreign'){
			url = location.href.split('#')[1];
			$('ul#foreign-child li#snav-' + url).attr('class','active');
			
			$('ul#foreign-child li').click(function(){
				$('ul#foreign-child li').attr('class','normal');
				$(this).attr('class','active');
				
			});
		}
	}
/*------------------------
  GNavi Anime
------------------------*/
	bodyID = $('body').attr('id');
	$('ul#grovalNav li a img').each(function(){
		naviID = $(this).attr('id').split('nv-')[1];

		if(bodyID == naviID){
			$(this).attr('lowsrc',$(this).attr('src'));
			$(this).css('background','url("/images/common/navi_bg.gif") bottom left repeat-x');
			$(this).css('padding-bottom','6px');
			$(this).css('padding-top',0);
			$(this).attr('src',$(this).attr('src').split('.gif')[0] + '_on.gif');
			
		}else{
			$(this).hover(
				function(){
					$(this).attr('lowsrc',$(this).attr('src'));
					$(this).css('background','url("/images/common/navi_bg.gif") bottom left repeat-x');
					$(this).attr('src',$(this).attr('src').split('.gif')[0] + '_on.gif');
					$(this).animate({paddingBottom : '6px',paddingTop:0},100);
				},
				function(){
					$(this).attr('src',$(this).attr('lowsrc'));
					$(this).css('background','url("/images/common/navi_bg2.gif") bottom left repeat-x');
					$(this).animate({paddingBottom :0,paddingTop:'6px'},100);
				}
			);
		}
	});

});




/* target="_blank" */
jQuery.fn.extend({
	tBlank:  $(document).ready(function(){
		return $('a._blank').click(function(){
			this.target = '_blank';
		});
	})
});

/*-- PopUP Window --*/
jQuery.fn.extend({
	opw:  $(document).ready(function(){
		return $('a.opw').click(function(){
			wh = $(this).attr('class').split(' ')[1];
			xHref = $(this).attr('href');
			xHeight = wh.split('h')[1];
			xWidth = wh.split('h')[0].split('w')[1];
			window.open(xHref,'SubWin','resizable=no,scrollbars=yes,menubar=no,directories=no,status=no,location=no,width='+xWidth+',height='+xHeight+'');
			return false;
		});
	})
});

/* swapImg */
jQuery.fn.extend({
	swapImg: $(document).ready(function(){
		return $('.swapImg').each(function(){
			if($(this).attr('class').match('swapImg change')){
				//ImgPreLoad
				swapObj = new Image();
				preLoad = $(this).attr('class').split('swapImg change(')[1].split(')')[0];
				swapObj.src = preLoad;
				imgNm = $(this).attr('name',preLoad);
				
				//MouseOver
				$(this).hover(
					function(){
						$(this).attr('lowsrc',$(this).attr('src'));
						$(this).attr('src',$(this).attr('name'));
					},
					function(){
						$(this).attr('src',$(this).attr('lowsrc'));
					}
				);
			}else if($(this).attr('src').match('_no.')){
				//ImgPreLoad
				swapObj = new Image();
				imgpath = $(this).attr('src');
				preLoad = imgpath.replace('_no.','_ro.');
				swapObj.src = preLoad;
				
				$(this).hover(
					function(){
						$(this).attr('src',$(this).attr('src').replace('_no.','_ro.'));
					},
					function(){
						$(this).attr('src',$(this).attr('src').replace('_ro.','_no.'));
					}
				);
			}
		});
	})
});
