//##########################################//
//## マウスオーバーでプロフィール写真変化 ##//
//##########################################//
var CtrlPhoto = {
	'init' : function() {
		var timeoutID = setTimeout("", 2000);
		var moveID = setTimeout("", 50);
		
		var cache1 = new Image();
		cache1.src = './photo/photo_fudanjukuB.jpg';
		
		var cache2 = new Image();
		cache2.src = './photo/photo_fudanjuku.jpg';
		
		var target = document.getElementById("photo");
		target.onmouseover = function() {
			clearTimeout(moveID);
			timeoutID = setTimeout(function() {
				target.src = cache1.src;
			}, 50);
		}
		target.onmouseout = function() {
			clearTimeout(timeoutID);
			moveID = setTimeout(function() {
				target.src = cache2.src;
			}, 50);
		}
	}
};

//########################################//
//## メンバープロフィールアニメーション ##//
//########################################//
var AniMember = {
	'option': {
		'defaultWidth':  130,
		'limitWidth':  950,
		'zIndex':  315,
		'k':  0.3 //係数
	},
	
	'init': function() {
		var that = this;
		
		var parent = document.getElementById("member");
		parent.heightID = setTimeout("", 40);
		parent.defaultHeight = parent.offsetHeight;
		
		var pTag = document.createElement("p");
		pTag.setAttribute("id", "note");
		pTag.innerHTML = "各メンバーをクリックするとプロフィールが表示されます。";
		
		parent.appendChild(pTag);
		
		var target = new Array();
		target.push(document.getElementById("yosuke"));
		target.push(document.getElementById("momotaro"));
		target.push(document.getElementById("uramasa"));
		target.push(document.getElementById("kyohei"));
		target.push(document.getElementById("kojiro"));
		target.push(document.getElementById("renji"));
		target.push(document.getElementById("kouki"));
		
		for(var i = 0; i < target.length; i++) {
			target[i].openID = setTimeout("", 40);
			target[i].moveID = setTimeout("", 40);
			target[i].touchID = setTimeout("", 10);
			target[i].isOpened = false;
			target[i].defaultLeft = parseInt(GET.style(target[i], "left"));
			
			target[i].profile = target[i].getElementsByTagName("DD")[0];
			target[i].profile.marginID = setTimeout("", 40);
			
			if(typeof document.body.style.minHeight != "undefined") {
				target[i].style.cursor = "pointer";
			} else {
				target[i].dt.style.cursor = "hand";
			}
			
			target[i].onmouseover = function() {
				clearTimeout(this.touchID);
			}
			target[i].onmouseout = function() {
				var self = this;
				
				this.touchID = setTimeout(function() {
					clearTimeout(self.openID);
					clearTimeout(self.moveID);
					clearTimeout(self.profile.marginID);
					clearTimeout(parent.heightID);
					
					self.openID = that.open(self, that.option.defaultWidth);
					self.moveID = that.move(self, self.defaultLeft);
					self.profile.marginID = that.margin(self.profile, 0);
					parent.heightID = that.height(parent, parent.defaultHeight);
					
					self.isOpened = false;
				}, 10);
			}
			
			target[i].onclick = function() {
				for(var j = 0; j < target.length; j++) {
					target[j].style.zIndex = that.option.zIndex - 1;
				}
				this.style.zIndex = that.option.zIndex;
				
				clearTimeout(this.openID);
				clearTimeout(this.moveID);
				clearTimeout(this.profile.marginID);
				clearTimeout(parent.heightID);
				
				if(this.isOpened) {
					this.openID = that.open(this, that.option.defaultWidth);
					this.moveID = that.move(this, this.defaultLeft);
					this.profile.marginID = that.margin(this.profile, 0);
					parent.heightID = that.height(parent, parent.defaultHeight);
					
					this.isOpened = false;
				} else {
					this.openID = that.open(this, that.option.limitWidth);
					this.moveID = that.move(this, 0);
					this.profile.marginID = that.margin(this.profile, 100);
					parent.heightID = that.height(parent, this.offsetHeight + 50);
					
					this.isOpened = true;
				}
			}
		}
	},
	
	'open': function(obj, end) {
		var that = this;
		
		var speed;
		var tempWidth;
		
		tempWidth = parseInt(GET.style(obj, "width"));
		if(Math.abs(tempWidth - end) > 1) {
			speed = (end - tempWidth) * this.option.k;
			speed > 0 ? speed = Math.ceil(speed) : speed = Math.floor(speed);
			
			obj.style.width = tempWidth + speed + "px";
			
			return setTimeout(function() {
				obj.openID = that.open(obj, end);
			}, 40);
		} else {
			obj.style.width = end + "px";
			clearTimeout(obj.openID);
		}
	},
	
	'move': function(obj, end) {
		var that = this;
		var speed;
		var tempPos;
		
		tempPos = parseInt(GET.style(obj, "left"));
		if(Math.abs(tempPos - end) > 1) {
			speed = (end - tempPos) * this.option.k;
			speed > 0 ? speed = Math.ceil(speed) : speed = Math.floor(speed);
			
			obj.style.left = tempPos + speed + "px";
			
			return setTimeout(function() {
				obj.moveID = that.move(obj, end);
			}, 40);
		} else {
			obj.style.left = end + "px";
			clearTimeout(obj.moveID);
		}
	},
	
	'margin': function(obj, end) {
		var that = this;
		var speed;
		var tempMargin;
		
		tempMargin = parseInt(GET.style(obj, "margin-left"));
		if(Math.abs(tempMargin - end) > 1) {
			speed = (end - tempMargin) * this.option.k;
			speed > 0 ? speed = Math.ceil(speed) : speed = Math.floor(speed);
			
			obj.style.marginLeft = tempMargin + speed + "px";
			
			return setTimeout(function() {
				obj.marginID = that.margin(obj, end);
			}, 40);
		} else {
			obj.style.marginLeft = end + "px";
			clearTimeout(obj.timeoutID3);
		}
	},
	
	'padding': function(obj, end) {
		var that = this;
		var speed;
		var tempPadding;
		
		tempPadding = parseInt(GET.style(obj, "padding-left"));
		if(Math.abs(tempPadding - end) > 1) {
			speed = (end - tempPadding) * this.option.k;
			speed > 0 ? speed = Math.ceil(speed) : speed = Math.floor(speed);
			
			obj.style.paddingLeft = tempPadding + speed + "px";
			
			return setTimeout(function() {
				obj.paddingID = that.padding(obj, end);
			}, 40);
		} else {
			obj.style.paddingLeft = end + "px";
			clearTimeout(obj.timeoutID3);
		}
	},
	
	'height': function(obj, end) {
		var that = this;
		
		var speed;
		var tempHeight;
		
		tempHeight = parseInt(GET.style(obj, "height"));
		if(Math.abs(tempHeight - end) > 1) {
			speed = (end - tempHeight) * this.option.k;
			speed > 0 ? speed = Math.ceil(speed) : speed = Math.floor(speed);
			
			obj.style.height = tempHeight + speed + "px";
			
			return setTimeout(function() {
				obj.heightID = that.height(obj, end);
			}, 40);
		} else {
			obj.style.height = end + "px";
			clearTimeout(obj.heightID);
		}
	}
};

//####################//
//## イニシャライズ ##//
//####################//
YAHOO.util.Event.onDOMReady(function() {
	//CtrlPhoto.init();
	AniMember.init();
	Shadowbox.init();
});
