﻿/***************************************************
 *
 * 共通JS
 * UTF-8
 * Target win IE6,7 FF2 Opera9 / mac FF2 Safari3
 *
 ***************************************************/

function SetEvents() {
	
	//クラス名から要素を取得
	this.getElementsByClassName = function(className,tagName){
		var i, j, eltClass;
		var elems = [];
		if(!tagName) tagName = '*';
		var objAll = document.getElementsByTagName(tagName);
		
		for (i = 0; i < objAll.length; i++) {
			eltClass = objAll[i].className.split(/\s+/);
			for (j = 0; j < eltClass.length; j++) {
				if (eltClass[j] == className) {
					elems.push(objAll[i]);
					break;
				}
			}
		}
		
		return elems;
	}
	
	//イベント登録
	this.addEvent = function(e, type, handler) {
		if (e.addEventListener) {
			e.addEventListener(type, handler, false);
		} else { //win ie
			e.attachEvent('on' + type, handler);
		}
	}
}


function rollover() {
	var elems = [];
	elems = setEvents.getElementsByClassName('rollover','img');
	elems = elems.concat(setEvents.getElementsByClassName('rollover','input'));
	
	var e;
	for(var i = 0, l = elems.length; i < l; i++) {
		e = elems[i];
		
		if(!e.src.match(/\-over(\.gif|\.jpg|\.png)$/)){
			var temp = new Image();
			e.src.match(/(\.gif|\.jpg|\.png)$/);
			temp.src = e.src.replace(RegExp.$1, '-over' + RegExp.$1);
			e.onmouseover = function() {
				this.src.match(/(\.gif|\.jpg|\.png)$/);
              	          this.src = this.src.replace(RegExp.$1, '-over' + RegExp.$1);
			}
			e.onmouseout = function() {
				this.src.match(/(\.gif|\.jpg|\.png)$/);
				this.src = this.src.replace('-over' + RegExp.$1, RegExp.$1);
			}
		}
	}
}


function popupWindow(URL,windowWidth,windowHeight,windowname) {
	windowWidth += 20;
	windowHeight += 20;
	if (!windowname) windowname = 'popup';
	targteWindow = window.open(URL, windowname, "width="+windowWidth+",height="+windowHeight+",resizable=yes,status=yes,location=yes,toolbar=no,titlebar=yes,scrollbars=yes");
	targteWindow.focus(); 
}

function popupMap(URL) {
	popupWindow(URL,540,764);
}











var setEvents = new SetEvents();

setEvents.addEvent ( window,'load',function() {
	rollover();
} );

//IE6 css hover 画像代替時のちらつき防止
try {
	document.execCommand('BackgroundImageCache', false, true); 
} catch(e) {} 
