/* IE6用 背景キャッシュ
#
#　CSSスプライトなどを使用した背景の切り替え時、
#　IE6以下で砂時計が出る現象を回避する
#
--------------------------------------------------------------------*/
try { 
	document.execCommand('BackgroundImageCache', false, true); 
} catch(e) {}


/* smartRollover 関数
#
#　画像のロールオーバーをクラス名で判断して行なう
#
#　使用例
#　　<img src="～" class="rollover" />
#　　<input type="image" src="～" class="rollover" />
#
--------------------------------------------------------------------*/
var smartRollover = {
	config: function(){
		smartRollover.init('img');
		smartRollover.init('input');
	},

	init: function(tag) {
		var obj = document.getElementsByTagName(tag);
		if(typeof obj == 'undefined' || obj == null) return false;

		var preload = [];
		for(var i=0; i<obj.length; i++) {
			if(obj[i].className.indexOf('rollover') != -1){
				var src = obj[i].src;
				obj[i].ext = src.slice(src.length-4, src.length);
				obj[i].nimg = src;
				obj[i].oimg = src.replace(obj[i].ext, '_on'+obj[i].ext);

				preload[i] = new Image();
				preload[i].src = obj[i].oimg;

				obj[i].onmouseover = function() {
					this.setAttribute('src', this.oimg);
				};
				obj[i].onmouseout = function() {
					this.setAttribute('src', this.nimg);
				};
			}
		}
	},

	addEvent: function(){
		try {
			window.addEventListener('load', smartRollover.config, false);
		} catch (e) {
			window.attachEvent('onload', smartRollover.config);
		}
	}
}
smartRollover.addEvent();


/* olderIE 変数
#
#　IEブラウザのVersionチェック用
#
#　値
#　　true: 指定したIEのバージョン未満（デフォルトは６）
#　　false: 指定したIEのバージョン以上、またはIE以外
#
--------------------------------------------------------------------*/
var verIE = 6;
var olderIE = false;
if(/*@cc_on !@*/false){
	var ua = navigator.userAgent;
	var ver = ua.indexOf('MSIE');
	olderIE = (ua.substr(ver+5, 1) < verIE) ? true : false;
}


/* objCheck 関数
#
#　オブジェクトチェック用関数
#
#　戻り値
#　　true: 有効なオブジェクト
#　　false: 無効なオブジェクト
#
--------------------------------------------------------------------*/
function objCheck(obj) {
	return (typeof obj == 'undefined' || obj == null) ? false : true;
}


/* tabSwitch 関数
#
#
--------------------------------------------------------------------*/
var tabSwitch = function(target, trigger, hidden, callfunc){
	this.target = document.getElementById(target);
	this.trigger = document.getElementById(trigger);
	this.hidden = hidden;
	this.callfunc = callfunc;
}
tabSwitch.prototype = {
	setup: function(item){
		var self = this;
		this.trigger.onclick = function(){
			for(var i=0; i<item.length; i++){
				(item[i] == self) ? item[i].show() : item[i].hide();
				//myCookie.set(item[i].target.id, item[i].hidden, sDays);
			}
			self.callfunc();
			return false;
		}/*
		if(myCookie.get(this.target.id)){
			this.hidden = (myCookie.get(this.target.id) == 'true') ? true : false;
		}*/
		this.target.style.overflow = 'hidden';
		(this.hidden) ? this.hide() : this.show();
		this.callfunc();
	},
	show: function(){
		this.target.style.height = '';
		this.hidden = false;
		return false;
	},
	hide: function(){
		this.target.style.height = '0px';
		this.hidden = true;
		return false;
	}
}


/* Toggle 関数
#
#　オブジェクト開閉（縦）
#
#　オブジェクト
#　　hidden: true : 非表示／false：非表示（default：false）
#　　setup: 初期設定（function）
#　　hide: 閉じる（function）
#　　show: 開く（function）
#　　callfunc: クリック時に実行される関数（function）
#
#　使用例
#　　var toggle01 = new Toggle('TARGET01', 'TORIGGER01', true, function(){～});
#
--------------------------------------------------------------------*/
var Toggle = function(target, trigger, hidden, callfunc){
	this.target = document.getElementById(target);
	this.trigger = document.getElementById(trigger);
	this.hidden = hidden;
	this.callfunc = callfunc;
}
Toggle.prototype = {
	setup: function(){
		var self = this;
		this.trigger.onclick = function(){
			//チェックボックスの処理
			if(this.type == 'checkbox'){
				(this.checked) ? self.show() : self.hide();
			}
			//その他
			else {
				(self.hidden) ? self.show() : self.hide();
			}
			myCookie.set(self.target, self.hidden, sDays);
			self.callfunc();
		}
		if(myCookie.get(this.target)){
			this.hidden = (myCookie.get(this.target) == 'true') ? true : false;
			if(this.trigger.type == 'checkbox'){
				this.trigger.checked = (myCookie.get(this.target) == 'true') ? false : true;
			}
		}
		this.target.style.display = (this.hidden) ? 'none' : '';
		this.callfunc();
	},
	show: function(func){
		this.target.style.display = '';
		this.hidden = false;
		return false;
	},
	hide: function(func){
		this.target.style.display = 'none';
		this.hidden = true;
		return false;
	}
}


/* myCookie 関数
#
#　クッキーの読み出し書き出し
#
--------------------------------------------------------------------*/
var sDays = 30;
var myCookie = {
	set: function(myCookie,myValue,myDay) {
		myExp = new Date();
		myExp.setTime(myExp.getTime()+(myDay*24*60*60*1000));
		myItem = '@' + myCookie + '=' + escape(myValue) + ';';
		myExpires = 'expires='+myExp.toGMTString();
		document.cookie = myItem + myExpires + '; path=/';
	},

	get: function(myCookie) {
		myCookie = '@' + myCookie + '=';
		myValue = null;
		myStr = document.cookie + ';' ;
		myOfst = myStr.indexOf(myCookie);
		if (myOfst != -1){
			myStart = myOfst + myCookie.length;
			myEnd   = myStr.indexOf(';' , myStart);
			myValue = unescape(myStr.substring(myStart,myEnd));
		}
		return myValue;
	}
}


/* PopWin 関数
#
#　ポップアップウィンドウをたちあげる
#
--------------------------------------------------------------------*/
var PopWin = function(winname, cssname, w, h, x, y, tool, resize, scroll, menu){
	this.winname = winname;
	this.cssname = cssname;
	this.size = {
		w: w,
		h: h,
		x: x,
		y: y
	}
	this.other = 'toolbar=' + tool + ',resizable=' + resize + ',scrollbars=' + scroll + ',menubar=' + menu;
}
PopWin.prototype = {
	setup: function(){
		var self = this;
		var ele = document.getElementsByTagName('a');
		for(var i=0; i<ele.length; i++){
			if((ele[i].className) && (ele[i].className.indexOf(this.cssname) != -1)){
				ele[i].onclick = function(){
					return self.openWin(this.href);
				}
			}
		}
	},

	openWin: function(url){
		window.open(url, this.winname,
			'width='	+ this.size.w +
			',Height='+ this.size.h +
			',left='	+ this.size.x +
			',top='	+ this.size.y + this.other
		);
		return false;
	}
}



/* 実行関数
#
#　全ページ対象のものを指定
#
--------------------------------------------------------------------*/

//ポップアップ
function popupInit(){
	var popup01 = new PopWin('winPopup', 'winPopup', '680', '600', '70', '70', '0', '1', '1', '0');
	var popup02 = new PopWin('envPopup', 'envPopup', '630', '600', '70', '70', '0', '1', '1', '0');
	var popup03 = new PopWin('priPopup', 'priPopup', '750', '600', '70', '70', '0', '1', '1', '0');
	popup01.setup();
	popup02.setup();
	popup03.setup();
}

//イベント追加
try {
	window.addEventListener('load', popupInit, false);
} catch (e) {
	window.attachEvent('onload', popupInit);
}
