/*********************************************************************
 *
 *  </common/js/common.js>
 *
*********************************************************************/

var kikkomanCommon = function () {
	var test = /(soy|desktop|202|132|marx3|staging)/.test (location.hostname);
	var path = {
		link: location.protocol == "https:" || !test ? "http://www.kikkoman.co.jp" : "",
		resource: location.protocol == "https:" ? "https://www.kikkoman.co.jp" : (!test ? "http://www.kikkoman.co.jp" : "")
	};
	return {
		path: path
	};
} ();
document.write ("<script type='text/javascript' src='" + kikkomanCommon.path.resource + "/common/js/swfobject.js'></script>");
document.write ("<script type='text/javascript' src='" + kikkomanCommon.path.resource + "/common/js/scrollto.js'></script>");

$ (function () {
	if ($.browser.mozilla) {
		$ ("body").addClass ("mozilla");
	} else if ($.browser.msie) {
		$ ("body").addClass ("msie");
		if ($.browser.version < 7) {
			$ (":first-child").addClass ("first-child");
		}
		if ($.browser.version < 8) {
			$ (":last-child").addClass ("last-child");
		}
	} else if ($.browser.safari) {
		$ ("body").addClass ("safari");
	}

	$ ("a[href$=.pdf]").after ("<img class='icon-a-1' src='" + kikkomanCommon.path.resource + "/common/image/icon_pdf_01.gif' width='16' height='16' alt='PDF' />");
	$ ("a[href$=.xls]").after ("<img class='icon-a-1' src='" + kikkomanCommon.path.resource + "/common/image/icon_excel_01.gif' width='16' height='16' alt='Excel' />");
	if ($.browser.msie) {
		$ ("div#content img.eudc, div#content img.icon-a-1, div#content img.icon-a-2, div#content img.icon-a-3").each (function () {
			var margin = Math.max (0, (parseInt ($ (this).css ("line-height")) - $ (this).height ()) / 2);
			$ (this).css ({ marginBottom : Math.ceil (margin) + "px", marginTop : Math.floor (margin) + "px" });
		});
	}

	$ ("div#content ul.definition-list-a-1 li span.term").each (function () {
		var width = $ (this).css ("display", "inline").width ("auto").width ();
		$ (this).width (width).parent ().css ("padding-left", width);
		$ (this).css ("margin-left", "-" + width + "px");
	});

	$ ("div#content span.marker").parent ().parent ().each (function () {
		var marker = $ (this).children ().children ("span.marker");
		var width = 0;
		marker.each (function () {
			width = Math.max (width, $ (this).css ("display", "inline").width ("auto").width () - parseInt ($ (this).css ("text-indent")));
		});
		$ (this).css ("margin-left", width);
		marker.width (width).css ("margin-left", "-" + width + "px");
	});

	$ ("div#content div.float-block-a-1 div.content-1, div#content div.float-block-a-1 div.content-2").each (function () {
		var image = $ ("img", this);
		var width = 0;
		image.each (function () {
			width = Math.max (width, $ (this).width ());
		});
		$ (this).css ("width", width);
		if ($ (this).height () < $ (this).parent ().height ()) {
			$ (this).css ("margin-bottom", Math.min ($ (this).parent ().height () - $ (this).height (), 6) + "px");
		}
	});

	for (var i = 1; $ ("div#content .equal-bottom-" + i).length; i++) {
		var block = $ ("div#content .equal-bottom-" + i);
		var height = 0;
		block.each (function () {
			height = Math.max ($ (this).offset ().top + $ (this).height ("auto").height (), height);
		});
		block.each (function () {
			$ (this).css (($.browser.msie && ($.browser.version < 7)) ? "height" : "min-height", height - $ (this).offset ().top);
		});
	}
});

/* scroll */
$ (function () {
	$ ("a[href^=#]").click (function () {
		$.scrollTo ($ (this).attr ("href"), 500);
		return false;	});
});

/* menu */
$ (function () {
	$ ("div#local-navigation p, div.homecook-localnav p.moremenu, div.homecook-lnav p.homecook-lnav-list-open").click (function () {
		$ ("div#menu").show ();
		$ ("#homecook-right-content select").css ({ visibility: "hidden" });
	});
	$ ("div#menu p").click (function () {
		$ (this).parent ().hide ();
		$ ("#homecook-right-content select").css ({ visibility: "visible" });
	});
});

/* toggle */
$ (function () {
	$ ("div#content .toggle").next ().css ({ position: "static", display: "none" });
	$ ("div#content .toggle").click (function () {
		$ (this).next ().slideToggle (200);
	});
});

/* rollover */
$ (function () {
	$ ("img[src*=_off.]").each (function () {
		$ ("<img />").attr ("src", this.src.replace (/_off\./, "_on."));
	});
	$ ("a:has(img[src*=_off.])").hover (function () {
		$ ("img[src*=_off.]", this).each (function () {
			this.src = this.src.replace (/_off\./, "_on.");
		});
	}, function () {
		$ ("img[src*=_on.]", this).each (function () {
			this.src = this.src.replace (/_on\./, "_off.");
		});
	});
});

/* window */
window._close = window.close;
window.close = function () {
	(window.open ("", "_top").opener = top)._close ()
};
$ (function () {
	$ ("a[target='_opener']").click (function () {
		try {
			top.opener.location.href = this.href;
			top.opener.focus ();
		} catch (e) {
			window.open (this.href, "_opener").focus ();
		}
		return false;
	});
});


window.name = 'kikkomanBase';
window.focus();
