(function($){
	$.ixcore = {};
	// print
	$.ixcore.print = function(e){
		if(e.type == 'click' || (e.type == 'keydown' && e.which == 13)){
			e.preventDefault();
			window.print();
			/* //미리보기 처리
			if(jQuery.support.cssFloat == true){
				window.print();
			}else{
				var _wb = new ActiveXObject("InternetExplorer.Application");
				_wb.Visible = false;
				_wb.Navigate(window.location);
				_wb.ExecWB(7, 1);
				_wb = null;
			}
			*/
		}
	};
	// slide sitemap popup
	$.ixcore.isLoadedSitemapPopup = false;
	$.ixcore.isShowedSitemapPopup = 0; //0:hide, 1:showing or hidding, 2:showed
	$.ixcore.showSitemapPopup = function(sel){
		$(sel).click(function(e){
			e.preventDefault();
			$.ixcore.showSitemapPopup.active(/*$(this).attr('href')*/);
		});
	};
	$.ixcore.showSitemapPopup.active = function(url){
		//if(url == undefined){url = '/open_content/site_helper/sitemap.jsp';}
		if(url == undefined){url = '/sitemap.jsp';}
		if($.ixcore.isShowedSitemapPopup == 0){
			$.ixcore.isShowedSitemapPopup = 1;
			$('body').append('<div id="showSitemapPopupLoading">Loading...</div>');
			if($.ixcore.isLoadedSitemapPopup == false){
				$('#sitemapPopup').load(url + ' #sitemapWrapper > ul', $.ixcore.showSitemapPopupSuccessed);
			}else{
				$.ixcore.showSitemapPopupSuccessed();
			}
			//alert($('#sitemapPopup').html());
		}else if($.ixcore.isShowedSitemapPopup == 2){
			$.ixcore.isShowedSitemapPopup = 1;
			$('#sitemapPopup').slideUp('slow', function(){
				$.ixcore.isShowedSitemapPopup = 0;
			});		
		}
	};
	$.ixcore.showSitemapPopupSuccessed = function(){
		$('#sitemapPopup').slideDown('slow', function(){
			$('#showSitemapPopupLoading').remove();
			$.ixcore.isLoadedSitemapPopup = true;
			$.ixcore.isShowedSitemapPopup = 2;
		});		
	};
	// main menu
	$.ixcore.onFocusedMainMenus = function(){
		$('#headWrapper #mainMenuWrapper ul.main li.main').hover(
			$.ixcore.onFocusedMainMenus.over,
			$.ixcore.onFocusedMainMenus.out);		
		$('#headWrapper #mainMenuWrapper ul.main li.main a').focus($.ixcore.onFocusedMainMenus.over);		
	};
	$.ixcore.onFocusedMainMenus.over = function(){
		var $this = (this.tagName.toLowerCase() == 'a')?$(this).parent():$(this);	
		if($this.hasClass('main') == false) return; 
		$('#headWrapper #mainMenuWrapper ul.main li.main a img.mainmenu').each(function(i,e){var $this1 = $(this); $this1.attr('src',$this1.attr('src').replace('on_', 'off_'));});
		var $img = $this.find('a img.mainmenu');
		var $subli = $this.find('ul');
		$img.attr('src',$img.attr('src').replace('off_', 'on_'));
		$('#headWrapper #mainMenuWrapper ul.main li.main ul.sub').removeClass('selected');
		$subli.addClass('selected');
	};
	$.ixcore.onFocusedMainMenus.out = function(){
	};

	// side sub menu
	$.ixcore.onFocusedSideSubMenus = function(){
		$('#sideSubMenus li.depth1:not(.selected) ul.depth2').hide();
		$('#sideSubMenus li.depth1').hover(
			$.ixcore.onFocusedSideSubMenus.over,
			$.ixcore.onFocusedSideSubMenus.out);
		$('#sideSubMenus li.depth1 > a').focus($.ixcore.onFocusedSideSubMenus.over);
		$('#sideSubMenus li.depth1:has(ul) > a').click($.ixcore.onFocusedSideSubMenus.click);
		//$('#sideSubMenus li.depth1:has(ul) > a').focus($.ixcore.onFocusedSideSubMenus.click);
	};
	$.ixcore.onFocusedSideSubMenus.over = function(){
		var $this = (this.tagName.toLowerCase() == 'a')?$(this).parent():$(this);	
		if($this.hasClass('depth1') == false) return; 
		$('#sideSubMenus li.depth1:not(.selected) a img').each(function(i,e){var $this1 = $(this); $this1.attr('src',$this1.attr('src').replace('on_', 'off_'));});
		var $img = $this.find('a img');
		$img.attr('src',$img.attr('src').replace('off_', 'on_'));
	};
	$.ixcore.onFocusedSideSubMenus.out = function(){
		$('#sideSubMenus li.depth1:not(.selected) a img').each(function(i,e){var $this1 = $(this); $this1.attr('src',$this1.attr('src').replace('on_', 'off_'));});
		//$('#sideSubMenus li.depth1:not(.selected) ul.depth2').slideUp('slow');
	};
	$.ixcore.onFocusedSideSubMenus.click = function(e){
		var $this = (this.tagName.toLowerCase() == 'a')?$(this).parent():$(this);	
		if($this.hasClass('depth1') == false) return; 
		e.preventDefault();
		var $subli = $this.find('ul.depth2');
		$('#sideSubMenus li.depth1:not(.selected) ul.depth2').each(
			function(i,e){
				var $this2 = $(this); 
				if($subli.parent().attr('id') != $this2.parent().attr('id')){
					$this2.slideUp('slow');
				}
			}
		);
		$subli.slideToggle('slow');
	};

})(jQuery);
(function($){ 
	 $.fn.emptySelect = function(){
		return this.each(function(){
			if(this.tagName == 'SELECT') this.options.length = 0;
		});
	 };
	 $.fn.loadSelect = function(optionsDataArray){
		return this.emptySelect().each(function(){
			if(this.tagName == 'SELECT'){
				var selectElement = this;
				$.each(optionsDataArray, function(index, optionData){
					var option = new Option(optionData.name, optionData.value);
					//$.support.noCloneEvent (is currently false in IE). 
					if(!($.support.noCloneEvent)){ selectElement.add(option); }else{ selectElement.add(option, null); }
				});
			}
		});
	 };     
})(jQuery); 
$(document).ready(function(){
	try {doument.execCommand("BackgroundImageCache", false, true);}catch(ignored) {}
	$('#linkPrint').click($.ixcore.print).keydown($.ixcore.print);
	$.ixcore.showSitemapPopup('#sitemapPopupIndex a');
	$.ixcore.onFocusedMainMenus();
	$.ixcore.onFocusedSideSubMenus();
	
});
