window.onload = init;

function init() {
	initRollovers();
	border_none();
	setFancybox();
	setFancybox2();
	popupWindow("popup2",300, 200);
	popupWindow("popup3",500, 830);
	popupWindow("popup5",660, 610);
	popupWindow2("popup6",650, 610);
	//crossfade("pickuplist",1000,3000);
}

//-----------------------------------------------
//	女性個人fancyboxで表示
//-----------------------------------------------

function setFancybox() {
	if(document.getElementById("home") || document.getElementById("ladies") || document.getElementById("schedule")) {
		$("a.popup").fancybox({
			'width'				: 660,
			'height'			: 660,
			'padding'			: 0,
			'overlayOpacity'	: 0.5,
			'autoScale'			: true,
			'speedIn'			: 500,
			'speedOut'			: 500,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe',
			'titleShow'			: false,
			'centerOnScroll'	: true
		});
	} else {
		return;
	}
}

//-----------------------------------------------
//	女性個人fancyboxで表示
//-----------------------------------------------

function setFancybox2() {
	if(document.getElementById("home") || document.getElementById("ladies") || document.getElementById("schedule")) {
		$("iframe a.popup4").fancybox({
			'width'				: 660,
			'height'			: 660,
			'padding'			: 0,
			'overlayOpacity'	: 0.5,
			'autoScale'			: true,
			'speedIn'			: 500,
			'speedOut'			: 500,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe',
			'titleShow'			: false,
			'autoDimensions'	: false
		});
	} else {
		return;
	}
}


//-----------------------------------------------
//	西暦表示
//-----------------------------------------------
function setYear() {
	var date = new Date();
	document.write(date.getFullYear());
}

//-----------------------------------------------
//	ロールオーバー
//-----------------------------------------------
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 == 'rollover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			hsrc = src.replace(ftype, '_over'+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('_over'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

//-----------------------------------------------
//	クリック時のフォーカスを非表示に
//-----------------------------------------------
function border_none(){
	var all_link = document.links;
	for(i=0;i<all_link.length;i++){
		all_link[i].onfocus = function(){
			this.blur();
		}
	}
}

//-----------------------------------------------
//	ポップアップ
//-----------------------------------------------
function popupWindow(_class,_width, _height) {
	var options = "width=" + _width + ",height=" + _height + ",scrollbars=no";
	var open = function(url) {
		var newWindow = window.open(url, _class, options);
		newWindow.focus();
	}
	
	var links = document.getElementsByTagName("a");
	for(var i = 0; i < links.length; i++) {
		if(links[i].className == _class) {
			links[i].onclick = function() {
				open(this.getAttribute("href"));
				return false;
			}
		}
	}
}



//-----------------------------------------------
//	ポップアップ スクロールバー付
//-----------------------------------------------
function popupWindow2(_class,_width, _height) {
	var options = "width=" + _width + ",height=" + _height + ",scrollbars=yes";
	var open = function(url) {
		var newWindow = window.open(url, _class, options);
		newWindow.focus();
	}
	
	var links = document.getElementsByTagName("a");
	for(var i = 0; i < links.length; i++) {
		if(links[i].className == _class) {
			links[i].onclick = function() {
				open(this.getAttribute("href"));
				return false;
			}
		}
	}
}


//-----------------------------------------------
//	クロスフェード
//-----------------------------------------------

function crossfade(IDname , fadetime , speed){
	if(!document.getElementById(IDname)){
		return;
	}
	var news = document.getElementById(IDname);
	var newslinks = news.getElementsByTagName("li");
	for(var i=0; i<newslinks.length; i++){
		newslinks[i].id = [i];
		newlength = new Array([i]);
	}
	for(var j=0; j<newslinks.length; j++){
		newlength[j]=[j];
	}
	new Crossfader(newlength, fadetime, speed );
}

var useBSNns;

if (useBSNns){
	if (typeof(bsn) == "undefined")
		bsn = {}
	var _bsn = bsn;
}else{
	var _bsn = this;
}

_bsn.Crossfader = function (divs, fadetime, delay ){
	this.nAct = -1;
	this.aDivs = divs;
	
	for (var i=0;i<divs.length;i++){
		document.getElementById(divs[i]).style.opacity = 0;
		document.getElementById(divs[i]).style.position = "absolute";
		document.getElementById(divs[i]).style.filter = "alpha(opacity=0)";
		document.getElementById(divs[i]).style.visibility = "hidden";
	}
	
	this.nDur = fadetime;
	this.nDelay = delay;
	this._newfade();
}

_bsn.Crossfader.prototype._newfade = function(){
	if (this.nID1)
		clearInterval(this.nID1);
	
	this.nOldAct = this.nAct;
	this.nAct++;
	if (!this.aDivs[this.nAct])	this.nAct = 0;
	
	if (this.nAct == this.nOldAct)
		return false;
	
	document.getElementById( this.aDivs[this.nAct] ).style.visibility = "visible";
	
	this.nInt = 50;
	this.nTime = 0;
	
	var p=this;
	this.nID2 = setInterval(function() { p._fade() }, this.nInt);
}

_bsn.Crossfader.prototype._fade = function(){
	this.nTime += this.nInt;
	
	var ieop = Math.round( this._easeInOut(this.nTime, 0, 1, this.nDur) * 100 );
	var op = ieop / 100;
	document.getElementById( this.aDivs[this.nAct] ).style.opacity = op;
	document.getElementById( this.aDivs[this.nAct] ).style.filter = "alpha(opacity="+ieop+")";
	
	if (this.nOldAct > -1){
		document.getElementById( this.aDivs[this.nOldAct] ).style.opacity = 1 - op;
		document.getElementById( this.aDivs[this.nOldAct] ).style.filter = "alpha(opacity="+(100 - ieop)+")";
	}
	
	if (this.nTime == this.nDur){
		clearInterval( this.nID2 );
		
		if (this.nOldAct > -1)
			document.getElementById( this.aDivs[this.nOldAct] ).style.visibility = "hidden";
		
		var p=this;
		this.nID1 = setInterval(function() { p._newfade() }, this.nDelay);
	}
}

_bsn.Crossfader.prototype._easeInOut = function(t,b,c,d){
	return c/2 * (1 - Math.cos(Math.PI*t/d)) + b;
}


function winClose(){
	if(!document.getElementById("close")){
		return false;
	}
	var btnClose = document.getElementById("close");
	btnClose.onclick = function(){
		window.close();
	}
}

function prepareLinks() {
    if(!document.getElementsByTagName){
    	return false;
    }
    var links = document.getElementsByTagName("a");
    for (var i=0; i<links.length; i++) {
        if(links[i].getAttribute("className") == "popup" || links[i].getAttribute("class") == "popup") {
            links[i].onclick = function() {
                popUp(this.getAttribute("href"));
                return false;
            }
        }
    }
}