
$(function(){
	layoutAdjust();
	sideBanner();
});


function layoutAdjust(){
	/* topic-path > */
	if($('ul#topic-path')){
		$('<span>&nbsp;&gt;</span>').appendTo('ul#topic-path li a');
	}
	
	bodyID = $('body').attr('id');
	$('li#nv-' +bodyID+ ' img').css('visibility','hidden');
	
	bodyCls = $('body').attr('class');
	$('li#nv-' +bodyCls+ ' a').css('background','url("/images/common/left_navi.gif") center right no-repeat #c6dcfa');
	$('li#nv-' +bodyCls+ '.second a').css('background','url("/images/common/left_navi.gif") center right no-repeat #ebf3fd');
	
	if($('body').attr('id') == 'glossary'){
		xURL = window.location.pathname;
		nvID = xURL.split('/')[2].split('/')[0];
		$('li#nv-' +nvID+ ' a').css('background','url("/images/common/left_navi.gif") center right no-repeat #c6dcfa');
		$('li#nv-' +nvID+ '.second a').css('background','url("/images/common/left_navi.gif") center right no-repeat #ebf3fd');
	}
}





/* 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.'));
					}
				);
			}
		});
	})
});


/* pop up movieWindow */
jQuery.fn.extend({
	movieWin: $(document).ready(function(){
		return $('a.movieWin').click(function(){
			xHref = $(this).attr('href');
			window.open(xHref,'SubWin','resizable=no,scrollbars=yes,menubar=no,directories=no,status=no,location=no,width=690,height=580');
			return false;
		});
	})
});


/* 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;
		});
	})
});


/*-- Right Side Banner --*/

function sideBanner(){
	if($('#rightBnr')){
		$(function(){  
		    $.ajax({  
		    url: '/banner/side_banner.xml',  
		    type: 'GET',  
		    dataType: 'xml',
			cache: false,
		    timeout: 1000,  
		    error: function(){
		    	alert('error!');
		    },  
		    success: function(xml){  
		        $(xml).find('bannerDisplay').each(function(){  
					var display = $(this).find('display:first').text();
			        if(display == 1){
			        	$("#rightBnr").load('/banner/sidebanner.html');
			        }else{
			        	$("#rightBnr").remove();
			        }
		        });

		    }
		    });
		}); 
		
	}
}