var ROLLOVER_CLASSNAME = 'rollover';
var OFF_SUFFIX = '_1';
var ON_SUFFIX = '_2';

function enableMenuImageRollovers(){
	var imgs = getElementsByTagAndClassName('img',ROLLOVER_CLASSNAME);
	for(var i = 0; i < imgs.length; i++){
		var img=imgs[i];
		//Create a couple of new image objects.
		var imgOn = new Image();
		var imgOff = new Image();
		//Set their source (this triggers the browser to load them).
		imgOn.src=img.src.replace(OFF_SUFFIX,ON_SUFFIX);
		imgOff.src=img.src.replace(ON_SUFFIX,OFF_SUFFIX);
		//Bind them to the original image.
		img.imgOn = imgOn;
		img.imgOff = imgOff;
		//Switch to them on mouseover/mouseout.
		img.onmouseover=function() {
			this.src=this.imgOn.src;
		}
		img.onmouseout=function() {
			this.src=this.imgOff.src;
		}
	}
}

function getElementsByTagAndClassName(tagName, className){
	var items = new Array();
	var elems = document.getElementsByTagName(tagName);
	for(var i = 0; i < elems.length; i++){
		var elem = elems[i];
		var classNames = elem.className.split(" ");
		for (var j = 0; j < classNames.length; j++){
			if(classNames[j] == className){
				items.push(elem);
			}
		}
	}
	return items;
}

if (window.onload){
	//Hang on to any existing onload function.
	var existingOnload = window.onload;
}

window.onload=function(ev){
	//Run any onload that we found.
	if (existingOnload){
		existingOnload(ev);
	}
	//Don't bother loading unless getElementsByTagName is supported.
	if (document.getElementsByTagName){
		enableMenuImageRollovers();
	}
}

/*****************************************
 * JavaScript: window.js  1.0
 * 
 * last updated on 2010.03.10
 * (c) 2010 swoop inc. (http://www.swoop.jp/)
 *****************************************/
 var wo = null;
 
// contents URL
var url = new Array();
url[0] = '/gallery/index.html';
url[1] = '../gallery/index.html';

var popup = 0;
var blank = 0;
var pw = screen.width;
var ph = screen.height;
var bh = window.screen.availheight;

function popupWinOpen(idx) {
	var w,h;
	var param;
	w = pw;
	h = ph;
	x = (screen.width - w) / 2;
	y = (screen.height - h) / 2;
	param = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width='+pw+',height='+ph+',left='+x+',top='+y;
	popup = window.open(url[idx],'popup',param);
	popup.focus();
}

function winCheck(idx) {
	if(popup) {
		if(!popup.closed) {
			popup.close();
		}
	}
	popupWinOpen(idx);
}

function blankWinOpen(idx) {
	if(popup) {
		if(!popup.closed) {
			popup.close();
		}
	}
	blank = window.open(url[idx],'blank','');
	blank.focus();
}

function winClose(){
	window.close();
}

/*****************************************
 * 親ウィンドウURL変更
 *
 * 親ウインドウが存在しない場合は_blankで開く
 * @param string:url
 *****************************************/
function parentWinChange(idx) {
	if (!is_closed()) {
		wo = window.opener;
		wo.location.href = url[idx];
		this.blur();
	} else {
		wo = window.open(url[idx], null);
	}
	//timeID = setTimeout("setFocus()", 3000);
	setFocus();
}

/*****************************************
 * 親ウィンドウフォーカスセット
 *
 *****************************************/
 function setFocus() {
	 	//clearTimeout(timeID);
		wo.focus()
 }

/*****************************************
 * 親ウィンドウ確認
 *
 * @return boolean:closed true/opend false
 *****************************************/
function is_closed() {
	var pw = window.opener;
	var ua = navigator.userAgent;
	if( !!pw ) {
			if( ( ua.indexOf('Gecko')!=-1 || ua.indexOf('MSIE 4')!=-1 )
					 && ua.indexOf('Win')!=-1 ) {
					 return pw.closed;
			} else {
				return typeof pw.document  != 'object';
			}
	} else {
		return true;
	}
}