// 初期設定
////////////////////////////////////////////////////////////////////////////////
win                 = new Array();
img                 = new Array();
img_on              = '_on';
header_img          = new Array();
header_img[0]       = 'header_home';
header_img[1]       = 'header_event';
header_img[2]       = 'header_floor_guide';
header_img[3]       = 'header_shops';
header_img[4]       = 'header_access';
header_directory    = new Array();
header_directory[0] = ''
header_directory[1] = 'Event';
header_directory[2] = 'FloorGuide';
header_directory[3] = 'Shops';
header_directory[4] = 'Access';





// 自動処理
////////////////////////////////////////////////////////////////////////////////
LoadImage('/images/header_home.gif');
LoadImage('/images/header_event.gif');
LoadImage('/images/header_floor_guide.gif');
LoadImage('/images/header_shops.gif');
LoadImage('/images/header_access.gif');
window.onload = ChangeHeader;
PrintCSS();





// 画像読込み
////////////////////////////////////////////////////////////////////////////////
function LoadImage (img_src){
	var img_info = GetImageInfo(img_src);
	var img_path = img_info[0];
	var img_name = img_info[1];
	var img_ext  = img_info[2];
	
	img[img_name]              = new Image();
	img[img_name].src          = img_path + '/' + img_name + '.' + img_ext;
	img[img_name + img_on]     = new Image();
	img[img_name + img_on].src = img_path + '/' + img_name + img_on + '.' + img_ext;
}





// 画像変更
////////////////////////////////////////////////////////////////////////////////
function ChangeImage (obj){
	var img_info = GetImageInfo(obj.firstChild.src);
	var img_name = img_info[1];
	
	if (obj.firstChild.src.indexOf(img_on) >= 0){
		obj.firstChild.src = img[img_name.split(img_on)[0]].src;
	}
	else {
		obj.firstChild.src = img[img_name + img_on].src;
	}
}





// 画像情報取得
////////////////////////////////////////////////////////////////////////////////
function GetImageInfo (img_src){
	var img_src  = img_src.split('/');
	var img_path = img_src.slice(0,img_src.length - 1).join('/');
	var img_name = img_src[img_src.length - 1].split('.')[0]; 
	var img_ext  = img_src[img_src.length - 1].split('.')[1];
	var img_info = new Array(img_path,img_name,img_ext);
	
	return img_info;
}





// ヘッダー状態変更
////////////////////////////////////////////////////////////////////////////////
function ChangeHeader (){
	if (window.opener){
		window.focus();
		return;
	}
	
	var locations = location.href.split('/');
	
	if (locations[3] == 'EventReport'){
		locations[3] = header_directory[1];
	}
	
	for (var i = 0 ; i < header_directory.length ; i++){
		if (header_directory[i] == locations[3]){
			document.images[header_img[i]].src = img[header_img[i] + img_on].src;
			img[header_img[i]].src = img[header_img[i] + img_on].src;
		}
	}
}





// ウィンドウオープン
////////////////////////////////////////////////////////////////////////////////
function OpenWindow (url,width,height,option){
	var window_width  = 800;
	var window_height = 600;
	var window_option = new Array(0,0,0,1,1,0,0);
	
	window_option = arguments.length == 2 ? width.split(',')  : window_option;
	window_width  = arguments.length >= 3 ? width             : window_width;
	window_height = arguments.length >= 3 ? height            : window_height;
	window_option = arguments.length >= 4 ? option.split(',') : window_option;
	
	for (var i in window_option){
		window_option[i] = window_option[i] == true ? 'yes' : 'no';
	}
	
	var window_name = 'win_' + window_width + '_' + window_height;
	
	win[window_name] = window.open(
		url,
		window_name,
		'left'        + '=' + 10               + ',' +
		'top'         + '=' + 30               + ',' +
		'width'       + '=' + window_width     + ',' +
		'height'      + '=' + window_height    + ',' +
		'directories' + '=' + window_option[0] + ',' +
		'location'    + '=' + window_option[1] + ',' +
		'menubar'     + '=' + window_option[2] + ',' +
		'resizable'   + '=' + window_option[3] + ',' +
		'scrollbars'  + '=' + window_option[4] + ',' +
		'status'      + '=' + window_option[5] + ',' +
		'toolbar'     + '=' + window_option[6]
	);
}





// ウィンドウクローズ
////////////////////////////////////////////////////////////////////////////////
function CloseWindow (){
	window.close();
}





// ユーザーエージェント取得
////////////////////////////////////////////////////////////////////////////////
function GetUA (){
	var os      = navigator.userAgent.toUpperCase();
	var browser = navigator.appName.toUpperCase();
	var version = navigator.appVersion.toUpperCase();
	var ua      = '';
	
	if      (os.indexOf('WIN') >= 0){ ua += 'WIN'; }
	else if (os.indexOf('MAC') >= 0){ ua += 'MAC'; }
	
	if      (version.indexOf('SAFARI')   >= 0){ ua += '-SF'; }
	else if (browser.indexOf('EXPLORER') >= 0){ ua += '-IE'; }
	else if (document.layers                 ){ ua += '-N4'; }
	else if (browser.indexOf('NETSCAPE') >= 0){ ua += '-NN'; }
	
	return ua;
}





// CSS出力
////////////////////////////////////////////////////////////////////////////////
function PrintCSS (){
	document.write('<style type="text/css">');
	document.write('<!--');
	
	if (GetUA().indexOf('WIN') >= 0){
		document.write('body,th,td { font-size : x-small  }');
		document.write('.small     { font-size : xx-small }');
	}
	else if (GetUA().indexOf('MAC') >= 0){
		document.write('body,th,td { font-size : 12px }');
		document.write('.small     { font-size : 10px }');
	}
	
	document.write('-->');
	document.write('</style>');
}





// プルダウンメニュー
////////////////////////////////////////////////////////////////////////////////
function JumpMenu (obj){
	target_url = obj.options[obj.selectedIndex].value;
	if(target_url == ''){
		return;
	}
	location.href = target_url;
}