// JavaScript Document
//■■20070805■ブラウザ判別CSS■■■
function envSet() {
	// ブラウザ判別
	var ua = navigator.userAgent;
	this.NN4  = (document.layers);
	this.FFx = (ua.indexOf("Firefox") != -1);
	this.SFR = (ua.indexOf("Safari") != -1);
	this.IE5 = (ua.indexOf("MSIE 5") != -1);
	this.IE50 = (ua.indexOf("MSIE 5.0") != -1);
	this.IE55 = (ua.indexOf("MSIE 5.5") != -1);
	this.IE6 = (ua.indexOf("MSIE 6") != -1);
	this.IE7 = (ua.indexOf("MSIE 7") != -1);
	this.IE70 = (ua.indexOf("MSIE 7.0") != -1);
	this.IE8 = (ua.indexOf("MSIE 8") != -1);
	this.IE80 = (ua.indexOf("MSIE 8.0") != -1);
	this.IE9 = (ua.indexOf("MSIE 9") != -1);
	this.IE90 = (ua.indexOf("MSIE 9.0") != -1);
	this.IE4  = (ua.indexOf("MSIE 4") != -1);
	this.IE   = (ua.indexOf("MSIE") != -1);
	this.Moz  = (ua.indexOf("Gecko") != -1);
	this.Op6  = (ua.match(/Opera.6/) != null); // Opera "6" only
	this.Omn  = (ua.indexOf("OmniWeb") != -1);
	this.Win  = (ua.indexOf("Windows") != -1);
	this.Mac  = (ua.indexOf("Mac") != -1);
	if (this.Op6) this.IE50 = this.IE = false; // WinIE を騙っていた時の対策
	if (this.Omn) this.NN4            = false; // document.layers に反応してるので

	// CSS ファイルのあるディレクトリ（絶対パス）
	this.cssDir = "../include/script/";
	
	// 各ブラウザ用補正 CSS のファイル名
	if (this.FFx && this.Win)  this.patchCSS = "ec_ff_win.css";
	if (this.FFx && this.Mac)  this.patchCSS = "ec_ff_mac.css";
	if (this.SFR)              this.patchCSS = "ec_sf.css";
	if (this.IE50 && this.Win) this.patchCSS = "ec_ie6.css";
	if (this.IE55 && this.Win) this.patchCSS = "ec_ie6.css";
	if (this.IE6 && this.Win)  this.patchCSS = "ec_ie6.css";
	if (this.IE7 && this.Win)  this.patchCSS = "ec_ie7.css";
	if (this.IE70 && this.Win) this.patchCSS = "ec_ie7.css";
	if (this.IE8 && this.Win)  this.patchCSS = "ec_ie7.css";
	if (this.IE80 && this.Win) this.patchCSS = "ec_ie7.css";
	if (this.IE9 && this.Win)  this.patchCSS = "ec_ie7.css";
	if (this.IE90 && this.Win) this.patchCSS = "ec_ie7.css";
	if (this.IE4 && this.Win)  this.patchCSS = "ec.css";
	if (this.NN4)              this.patchCSS = "ec.css";
	if (this.IE5 && this.Mac)  this.patchCSS = "ec.css";
	if (this.IE5 && this.Mac)  this.patchCSS = "ec.css";
	if (this.IE5 && this.Mac)  this.patchCSS = "ec.css";
	if (this.Op6)              this.patchCSS = "ec.css";
	if (this.Omn)              this.patchCSS = "ec.css";

	// DOM 処理関係
	this.DOMenabled =  (document.getElementsByTagName) ? true : false;
	this.firstLoad = n2.isFirstLoad;

	return this;
}

function nyan2Func() {}

nyan2Func.prototype = {
	getAfter : function(_str, _word) {
		// 文字列 _str 中から _word 以降の残りを抽出する\
		var offset = _str.indexOf(_word)
		if (offset == -1) return _str;
			else return _str.substring(offset + _word.length, _str.length);
	},

	makeTag : function() {
		// makeTag( tagName, [attr=value, ... ] , content|null )
		var me = this.makeTag;
		var n = me.arguments.length;
		var tag = "<" + me.arguments[0];

		for (var i=1; i<n-1; i++) {
			if (!me.arguments[i]) continue;
			var attrs = me.arguments[i].split("=");
			var attr = attrs[0];
			var value = attrs.slice(1, attrs.length).join("=");
			tag += ' ' + attr + '="' + value + '"';
		}
		if (me.arguments[n-1]) tag += ">" + me.arguments[n-1] + "</" + me.arguments[0] + ">";
			else tag += " />";
		return tag;
	},

	loadCSS : function(_file) {
		var ua = navigator.userAgent;

		// NN4, Opera6 は document.styleSheets を理解しない。
		var title = (document.styleSheets && document.styleSheets.length > 0) ? document.styleSheets[0].title : null;
		title = (title) ? "title=" + title : null;
		var media = (!env.NN4) ? "media=screen,tv" : null;

		var cLINK = this.makeTag(
			"link",
			"rel=styleSheet",
			"type=text/css",
			"href=" + env.cssDir + _file,
			media,
			title,
			null
		);
		document.write(cLINK);
	}
}

var n2 = new nyan2Func();
var env = new envSet();
n2.loadCSS(env.patchCSS);



