// (C) 2011 SEKI (belong to enn ltd.)

(function($) {

var isIE = function(v) {
	return $.browser.msie && $.browser.version <= v;
};

// jquery.swapimg
$.fn.swapimg = function(option) {
	var op = {
		suffix: "_o",
		preload: true,
		swapped_file: null
	};
	$.extend(true, op, option);
	this.each(function() {
		var t = this.src.match(/(.*)\.(\w+)$/);
		// get file name
		var src = op.swapped_file || t[1] + op.suffix + "." + t[2];
		// preload
		if (op.preload)
			(new Image()).src = src;
		// register event
		$(this).hover(
			function() { this.src = src; },
			function() { this.src = t[0]; }
		);
	});
};

$(function() {
	//-----------------------------------------
	// 画像置換
	//-----------------------------------------
	//$("#header h1 a img, #otoiawase img").swapimg();
	if (!isIE(6)) {
		$("a:not(.opacity) img").swapimg();
		$("a.opacity img").hover(function() {
			$(this).css("opacity", "0.7");
		}, function() {
			$(this).css("opacity", "1.0");
		});
	}

	//-----------------------------------------
	// IE fix
	//-----------------------------------------
	if (isIE(7)) {
		$("#side-content li a").prepend("<span class='mark'></span>");
		$("*:first-child").addClass("first-child");
	}
	if (!isIE(6))
		$("#ie6caution").hide();
	
	//-----------------------------------------
	// noscript
	//-----------------------------------------
	$("noscript").hide();

	//-----------------------------------------
	// フォントサイズ
	//-----------------------------------------
	var cookieOptions = { path: '/' };
	var updateFontSize = function() {
		var fontsize = $.cookie("fontsize");
		if (fontsize === "normal") {
			$("body").css("font-size", "smaller");
			var nn = $("#fontsize-normal").addClass("active");
			var nl = $("#fontsize-large").removeClass("active");
			if (isIE(8)) {
				nn[0].style.backgroundPositionX = "-110px";
				nl[0].style.backgroundPositionX = "-10px";
			}
		} else if (fontsize === "large") {
			$("body").css("font-size", "100%");
			var ln = $("#fontsize-normal").removeClass("active");
			var ll = $("#fontsize-large").addClass("active");
			if (isIE(8)) {
				ln[0].style.backgroundPositionX = "-10px";
				ll[0].style.backgroundPositionX = "-110px";
			}
		} else {
			$.cookie("fontsize", "normal", cookieOptions);
			updateFontSize();
		}
	};
	$("#fontsize-normal").click(function() {
		$.cookie("fontsize", "normal", cookieOptions);
		updateFontSize();
		return false;
	});
	$("#fontsize-large").click(function() {
		$.cookie("fontsize", "large", cookieOptions);
		updateFontSize();
		return false;
	});
	updateFontSize();
	
	//-----------------------------------------
	// グローバルナビプルダウン
	//-----------------------------------------
	$("#gn-about-ge, #gn-products, #gn-reading, #gn-company").hover(
		function() {
			if (!this.isSliding) {
				$(this).children("ul").slideDown(200);
			}
		},
		function() {
			var me = this;
			me.isSliding = true;
			$(me).children("ul").slideUp(200, function() {
				me.isSliding = false;
			});
		}
	);
	
	//-----------------------------------------
	// ページ内スムーズスクロール
	//-----------------------------------------
	$(".goto-top a, .move-page a, a.scroll").click(function() {
		var to = $(this).attr("href");
		if (to.charAt(0) === "#") {
			to = (to === "#") ? 0 : $(to).offset().top;
			$("html, body").animate({scrollTop: to}, 300, "easeOutQuint");
			return false;
		}
		return true;
	});
	
	//-----------------------------------------
	// ポップアップ設定
	//-----------------------------------------
	$(".popup").popupwindow({
		popup700: {
			height: 600,
			width: 720,
			status: 0,
			scrollbars: 1,
			resizable: 0,
			location: 0,
			menubar: 0
		}
	});
});


}(jQuery));


