// 基本機能の組込み
////////////////////////////////////////////////////////////////////////////////
if (document.getElementById) {
WING = new wingClass();
WING.setENV();
WING.includeJS('basic/image.js');
WING.includeJS('basic/window.js');
WING.includeJS('basic/flash.js');





// DOM未対応ブラウザ処理
////////////////////////////////////////////////////////////////////////////////
} else {
	WING = new Object();
}





// 標準クラス
////////////////////////////////////////////////////////////////////////////////
function wingClass () {
	
	
	
	// 環境変数を設定
	this.setENV = function () {
		this.ENV         = new Object();
		this.ENV.root    = this.getRootDir();
		this.ENV.shared  = this.getSharedDir();
		this.ENV.os      = this.getUser().os;
		this.ENV.ua      = this.getUser().ua;
		this.ENV.version = this.getUser().version;
	}
	
	
	
	// 外部JSを組込み
	this.includeJS = function (file, _module) {
		var script      = '<script type="text/javascript"';
		    script     += ' src="' + this.ENV.shared + 'js/' + file + '">';
		    script     += '</script>';
		
		document.write(script);
	}
	
	
	
	// ドキュメントルートを取得
	this.getRootDir = function () {
		var protocol  = location.href.split(':')[0] + ':';
		var locations = location.href.split(':')[1].split('/');
		
		for (var i = 0; i < locations.length; i++) {
			if (locations[i] != '') {
				return (protocol + locations[i] + '/');
			}
			protocol += '/';
		}
	}
	
	
	
	// 共有フォルダディレクトリを取得
	this.getSharedDir = function () {
		var script     = document.getElementsByTagName('script');
		var dir_shared = 'common/js/';
		
		for (var i = 0; i < script.length; i++) {
			if (script[i].src && script[i].src.indexOf(dir_shared) >= 0) {
				dir_shared = script[i].src.split(dir_shared)[0] + 'common/';
				break;
			}
		}
		
		return dir_shared;
	}
	
	
	
	// ユーザー情報を取得
	this.getUser = function () {
		var ua      = navigator.userAgent.toUpperCase();
		var profile = new Object();
		
		if      (ua.indexOf('WIN')      >= 0) { profile.os = 'WIN'; }
		else if (ua.indexOf('MAC')      >= 0) { profile.os = 'MAC'; }
		
		if      (ua.indexOf('OPERA')    >= 0) { profile.ua = 'OP';  }
		else if (ua.indexOf('MSIE')     >= 0) { profile.ua = 'IE';  }
		else if (document.layers            ) { profile.ua = 'N4';  }
		else if (ua.indexOf('NETSCAPE') >= 0) { profile.ua = 'NN';  }
		else if (ua.indexOf('SAFARI')   >= 0) { profile.ua = 'SF';  }
		else if (ua.indexOf('FIREFOX')  >= 0) { profile.ua = 'FF';  }
		else if (ua.indexOf('GECKO')    >= 0) { profile.ua = 'MZ';  }
		
		switch (profile.ua) {
			case 'OP' : profile.version = ua.substr(ua.indexOf('OPERA')    + 6,3);  break;
			case 'IE' : profile.version = ua.substr(ua.indexOf('MSIE')     + 5,3);  break;
			case 'N4' : profile.version = ua.substr(ua.indexOf('MOZILLA')  + 8,3);  profile.ua = 'NN'; break;
			case 'NN' : profile.version = ua.substr(ua.indexOf('NETSCAPE') + (ua.indexOf('6/6') >= 0 ? 10 : 9),3);  break;
			case 'SF' : profile.version = ua.substr(ua.indexOf('SAFARI')   + 7,3);  break;
			case 'FF' : profile.version = ua.substr(ua.indexOf('FIREFOX')  + 8,3);  break;
			case 'MZ' : profile.version = ua.substr(ua.indexOf('RV')       + 3,3);  break;
		}
		
		return profile;
	}
}
