/*-------------------------------------------------
	共通化JSメニュー

	1.現在地の取得　※必ず変更する
	2.著作権表示　※必ず変更する
	3.アクセス解析
	4.ブラウザCSS振り分け
	5.ポップアップ
	6.ページトップへスクロール
	7.ページ印刷
	8.onload関数
	9.ロールオーバー背景変更
--------------------------------------------------*/



/*-------------------------------------------------
	1.現在地の取得
--------------------------------------------------*/
//例）http://www.abc.com/index.htmlならばドメイン国名（.com/）+数（5）
//例）http://www.abc.com/index.htmlならばドメイン国名（.jp/）+数（4）
var path = window.location.href;
var position = path.substring(path.lastIndexOf('com/',path.length)+4,path.length); //テスト

//document.write('<body>'+position);

//スラッシュの数を数える
var l = 0;
for ( i =0 ; i < position.length; i++ ) {
	if ( position.charAt(i) == "/") { l++;}
}

//4階層まで対応
switch (l) {
	case 0: dir = "./"; break;
	case 1: dir = "../"; break;
	case 2: dir = "../../"; break;
	case 3: dir = "../../../"; break;
	case 4: dir = "../../../../"; break;
	default: dir = "./"; break;
}
//document.write('<body>'+dir);


/*-------------------------------------------------
	2.著作権
--------------------------------------------------*/
function copyright() {
now = new Date();
document.write("&copy;Copyright ");
document.write(now.getFullYear());
document.write(" 便利屋かんきょう21. All rights reserved.");


/*-------------------------------------------------
	3.アクセス解析（上と一緒の関数）
--------------------------------------------------*/
document.write("<img src='"+dir+"cgi/acc/acclog.cgi?");
document.write("referrer="+document.referrer+"&");
document.write("width="+screen.width+"&");
document.write("height="+screen.height+"&");
document.write("color="+screen.colorDepth+"' width=5 height=5>");
}

/*-------------------------------------------------
	4.ブラウザCSS振り分け
--------------------------------------------------*/
if((navigator.userAgent.indexOf("Apple") > -1)){
	version="mac_safari";

}else if((navigator.userAgent.indexOf("Mac",0)!=-1)&&(navigator.userAgent.indexOf("Gecko") != -1)){
	version="mac_moz";

}else if((navigator.userAgent.indexOf("MSIE",0)!=-1)&&(navigator.userAgent.indexOf("Mac",0)!=-1)){
	version="mac_ie";

}else if((navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)>=5)){
	version="win_moz";
	
}else{
	version="win_ie";
}
	
document.write('<link rel="stylesheet" type="text/css" href="'+dir+'common/css/'+version+'.css">');
//document.write('<body>'+dir+'common/css/'+version+'.css');


/*-------------------------------------------------
	5.ポップアップ
--------------------------------------------------*/
//例) popup(HTML,横幅,縦幅,スクロールバー)
//    popup(index.html,300,150,yes) <- index.htmlが300px x 150px のスクロールバーありで開きます

function popup(wn,wh,ht,scb){
	var scriptwin = window.open(wn,"Sub","toolbar=no,status=yes,menubar=no,scrollbars="+scb+",resizable=yes,width="+wh+",height="+ht);
	scriptwin.focus();
}


/*-------------------------------------------------
	6.ページトップへスクロール
--------------------------------------------------*/
function PageTop() {
  var x1 = x2 = x3 = 0;
  var y1 = y2 = y3 = 0;
  if (document.documentElement) {
      x1 = document.documentElement.scrollLeft || 0;
      y1 = document.documentElement.scrollTop || 0;
  }
  if (document.body) {
      x2 = document.body.scrollLeft || 0;
      y2 = document.body.scrollTop || 0;
  }
  x3 = window.scrollX || 0;
  y3 = window.scrollY || 0;
  var x = Math.max(x1, Math.max(x2, x3));
  var y = Math.max(y1, Math.max(y2, y3));
  window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
  if (x > 0 || y > 0) {
      window.setTimeout("PageTop()", 100);
  }
}


/*-------------------------------------------------
	7.ページ印刷
--------------------------------------------------*/
function printit(){
if (window.print) {
		window.print() ;
	} else {
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = "";
	}
}


/*-------------------------------------------------
	8.onload関数
--------------------------------------------------*/
/*
*
* Copyright (c) 2007 Andrew Tetlaw
* 
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* * 
*
*
* FastInit
* http://tetlaw.id.au/view/javascript/fastinit
* Andrew Tetlaw
* Version 1.3 (2007-01-09)
* Based on:
* http://dean.edwards.name/weblog/2006/03/faster
* http://dean.edwards.name/weblog/2006/06/again/
* Help from:
* http://www.cherny.com/webdev/26/domloaded-object-literal-updated
* 
*/
var FastInit = {
	onload : function() {
		if (FastInit.done) { return; }
		FastInit.done = true;
		for(var x = 0, al = FastInit.f.length; x < al; x++) {
			FastInit.f[x]();
		}
	},
	addOnLoad : function() {
		var a = arguments;
		for(var x = 0, al = a.length; x < al; x++) {
			if(typeof a[x] === 'function') { FastInit.f.push(a[x]); }
		}
	},
	listen : function() {
		if (/WebKit|khtml/i.test(navigator.userAgent)) {
			FastInit.timer = setInterval(function() {
				if (/loaded|complete/.test(document.readyState)) {
					clearInterval(FastInit.timer);
					delete FastInit.timer;
					FastInit.onload();
				}}, 10);
		} else if (document.addEventListener) {
			document.addEventListener('DOMContentLoaded', FastInit.onload, false);
		} else if(!FastInit.iew32) {
			Event.observe(window, 'load', FastInit.onload);
		}
	},
	f:[],done:false,timer:null,iew32:false
};
/*@cc_on @*/
/*@if (@_win32)
FastInit.iew32 = true;
document.write('<script id="__ie_onload" defer src="' + ((location.protocol == 'https:') ? '//0' : 'javascript:void(0)') + '"><\/script>');
document.getElementById('__ie_onload').onreadystatechange = function(){if (this.readyState == 'complete') { FastInit.onload(); }};
/*@end @*/
FastInit.listen();


/*-------------------------------------------------
	9.ロールオーバー背景変更
--------------------------------------------------*/
function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'over') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_on'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

if(window.FastInit) {
	FastInit.addOnLoad(initRollovers);
} else {
	Event.observe(window, 'load', initRollovers);
}
//window.onload = initRollovers;

