////////////////////////////////////////////////
//
// util.js[ver1.4 101027]
//
////////////////////////////////////////////////

var pageScrollTimer;
var nowOverSrc;
var util = {
	preloader: {
		loadedImages: [],
		load: function (url){
			var img = this.loadedImages;
			var l = img.length;
			img[l] = new Image();
			img[l].src = url;
		}
	}
};

$(function(){	   
$('.hover').each(function(){
	this.originalSrc = $(this).attr('src');
		if ((/\d\.(jpg|gif|png)/).test(this.originalSrc)){
			this.rolloverSrc = this.originalSrc.replace(/(\.)(jpg|gif|png)/,"hover.$2");	
		}else{
			this.rolloverSrc = this.originalSrc.replace(/(\.)(jpg|gif|png)/,"Hover.$2");
		}	
	util.preloader.load(this.rolloverSrc);
});

var h = $('.current').attr('src');
if(h){
h = h.replace(/(\.)(jpg|gif|png)/,"hover.$2");
$('.current').attr('src', h);
}

$(".hover").hover(function(){
	$(this).attr('src',this.rolloverSrc);
},function(){
		$(this).attr('src',this.originalSrc);
});

$(".fade").hover(function(){
	$(this).fadeTo(100, 0.7);
},
function(){
	$(this).fadeTo(100, 1.0);
});

//$("div.wrap").wrapInner('<div class="inner"></div>');			   
//$("h1.wrap,h2.wrap,h3.wrap,h4.wrap,li.wrap,dt.wrap,dd.wrap").wrapInner('<span class="inner"></span>');

$('a.bl').click(function(){window.open(this.href, '_blank');return false;});

$('.pageTop').click(function(){pageScroll(0,7);return false;});
$('.anchor').click(function(){
	var aim = $(this).attr('href');
	pageScroll(Math.floor($(aim).offset().top),7);
	return false;
});

$('#faq #contents .sectionH2 .faq dd').each(function(){
	$(this).css("display","none");
});

$('#faq #contents .sectionH2 .faq dt a').click(function(){
	$(this).closest("dt").toggleClass("plus");
	var ddCss = $(this).closest("dl").children("dd").css("display");
	if(ddCss == 'none'){
		$(this).closest("dl").children("dd").css("display","block");
	}else{
		$(this).closest("dl").children("dd").css("display","none");
	}
});

$('#catalog #contents .sectionH2 .serch .inner table.keyward th.ent select').each(function(){
	$(this).css("display","none");
});

$('#catalog #contents .sectionH2 .serch .inner table.keyward th.ent select').eq(0).css("display","block");

$('#catalog #contents .sectionH2 .serch .inner table.keyward th.cate select').bind('change', function(){
	var num = $("#catalog #contents .sectionH2 .serch .inner table.keyward th.cate select option:selected").index();
	$('#catalog #contents .sectionH2 .serch .inner table.keyward th.ent select').css("display","none");
	$('#catalog #contents .sectionH2 .serch .inner table.keyward th.ent select').eq(num).css("display","block");
});

$('#header .topicPath li:first').addClass("firstChild");
});

function pageScroll(toY,frms,cuY){
	if (pageScrollTimer) clearTimeout(pageScrollTimer);
	if (!toY || toY < 0) toY = 0;
	if (!cuY) cuY = 0 + $(window).scrollTop();
	if (!frms) frms = 6;
	if ((toY > cuY) && (toY > getContentsHeight() - $(window).height())){ toY = getContentsHeight() - $(window).height() +1 };
	cuY += (toY - $(window).scrollTop()) / frms;
	if (cuY < 0) cuY = 0;
	var posY = Math.floor(cuY);

	window.scrollTo(0, posY);
	if (posY != toY) {pageScrollTimer = setTimeout("pageScroll("+toY+","+frms+","+cuY+")",16);}
}

function getContentsHeight(){return ($.support.boxModel) ? $('body').height() : document.body.scrollHeight ;}

