// ロールオーバー
$(function () {
    $.rollover = {
        init: function () {
            $('a img,input[type="image"]').not('[src*="_on."]')
                .bind('mouseover', this.over)
                .bind('mouseout',  this.out)
                .each(this.preload);
        },

        over : function () {
            this.setAttribute('src', this.getAttribute('src').replace('_off.', '_on.'));
        },

        out : function () {
            this.setAttribute('src', this.getAttribute('src').replace('_on.', '_off.'));
        },

        preload : function () {
            new Image().src = this.getAttribute('src').replace('_off.', '_on.');
        }
    };

    $.rollover.init();
});


//flatheight
$(window).bind('load',function(){
    var sets = [], temp = [];
    $('div.gallery ul.gallery dl').each(function(i) {
        temp.push(this);
        if (i % 4 == 3) {
            sets.push(temp);
            temp = [];
        }
    });

    if (temp.length) sets.push(temp);
    $.each(sets, function() {
        $(this).flatHeights();
    });
});



//table
$(function() {
 $("tr:last-child th").addClass("last");
 $("dl dd:last-child").addClass("last");
});
$(function() {
 $("ul.topic_path li:first").addClass("first");
 $("ul.contents_navigation li:first").addClass("first");
 $("ul.tab li:first").addClass("first");
});



//nav
$(function() {
$("ul#navigation").hover(
  function () {
    $(this).addClass("hover");
  }
);
	$('ul#navigation li')
	//ボタンを0で配置
	.each(function(){
		$(this).css('margin-left', '0px')
	})
	.hover(
		function(){
			$(this).stop().animate({
				'marginLeft':'-60px'
			},'fast');
		},
		function () {
			$(this).stop().animate({
				'marginLeft':'0px'
			},'slow');
		}
	);
});


//search
$(function() {
	$("#iframe").fancybox({
			'width': 800,
			'height': 500
	});
});


//faq
$(document).ready(function() {
	$("dl.faq dt").hover(function(){
		$(this).css("cursor","pointer");
		$(this).css("text-decoration","underline"); 
	},function(){
		$(this).css("cursor","default");
		$(this).css("text-decoration","none");
		});
	$("dl.faq dd").css("display","none");
	$("dl.faq dt").click(function(){
		$(this).next().slideToggle("normal");
		});
});

//dic
$(document).ready(function(){
    $("div.dictionary ul.titlelist li:even").addClass("odd");
    $("div.dictionary ul.titlelist li:odd").addClass("even");
});


//Translate
$(function(){
	$("#languageSelect a").click(function(){
		if(location.href.match(/(.+?)#.*/)) location.href = RegExp.$1 + $(this).attr("href");
		location.href = location.href + $(this).attr("href");
		location.reload();
	});
});
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'ja',
    includedLanguages: 'en,ko,zh-CN,zh-TW'
  });
}

$(function(){
 $('ul.comment li').each(function(){
  random = Math.floor(Math.random()*5+1);
  $(this).addClass('comment'+random);
 });
});

