var _Common_ = {
	initRollovers:function(){
		if (!document.getElementById) return
		var aPreLoad = new Array();
		var sTempSrc;
		var aImages = document.getElementsByTagName('img');
		var img_Len = aImages.length;
		for (var i = 0; i < img_Len; i++) {		
			if (aImages[i].className == 'over') {
				var src = aImages[i].getAttribute('src');
				var ftype = src.substring(src.lastIndexOf('.'), src.length);
				var 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('_x'+ftype, ftype);
					this.setAttribute('src', sTempSrc);
				}
			}
		} 
		
		var aInputs = document.getElementsByTagName('input');
		var img_Len = aInputs.length;
		for (var i = 0; i < img_Len; i++) {		
			if (aInputs[i].className == 'over') {
				var src = aInputs[i].getAttribute('src');
				var ftype = src.substring(src.lastIndexOf('.'), src.length);
				var hsrc = src.replace(ftype, '_over'+ftype);
	
				aInputs[i].setAttribute('hsrc', hsrc);
				aPreLoad[i] = new Image();
				aPreLoad[i].src = hsrc;
				aInputs[i].onmouseover = function() {
					sTempSrc = this.getAttribute('src');
					this.setAttribute('src', this.getAttribute('hsrc'));
				}	
				aInputs[i].onmouseout = function() {
					if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_x'+ftype, ftype);
					this.setAttribute('src', sTempSrc);
				}
			}
		}   
		return;
	},
	url_Parse:function(url){
		var _ = false;
		if(url.indexOf("?") > 0 && url.indexOf("=") > 0){
			_ = new Array();
			var array = url.split("#");
			array = array[0].split("?");
			array = array[1].split("&");
			for(var i=0;i<array.length;i++){
				array[i] = array[i].split("=");
				var hash = array[i][0];
				var value = array[i][1];
				
				_[hash] = value;
			}
			delete array;
		}
		return _;
	},
	px:function(data){
		
		if(isNaN(data)){
			var sign = false;
			if(data.charAt(0) == "-"){
				sign = true;
			}
			
			var num = new Array();
			for(i=0;i<data.length;i++){
			
				if(!isNaN(data.charAt(i))){
					num[i] = data.charAt(i);
				}
			
			}
			num = num.join();
			num = num.replace(/\,/gi,"");
			if(sign){
				num = num - num * 2
			}
			data = Number(num);	
		}
		
		
		return data;
	}
};

/*

一覧ページ

*/
var List = {};
List.init = function(){
	
	$(".count").text(List.current + 1 + " / " + List.length);
	
	/*
	$(".photoList").mousewheel(function(event, delta) {
		if (delta > 0) List.prev();
		else if (delta < 0) List.next();
		return false;
	});
	*/

};

List.set = function(){
	
	var i=0,z=Math.max(0,this.current-2),a=0;
	var ln = this.current + 3;
	var src = "";
	for(z;z<ln;z++){
	src += '<div class="list"><table cellpadding="0" cellspacing="1" width="816" class="table">';
		for(x=z*3;x<z*3+3;x++){
		src += '<tr>';
		
			for(i=x*4;i<x*4+4;i++){
				if(data.imgary[i]){
					src +='<td width="25%"><a href="/detail.php?num='+i+'"><img src="/image_data/middle/' + data.lid + '/' + data.imgary[i] + '" /> </a></td>';
				}else{
					src +='<td width="25%" class="none">&nbsp;</td>';
				}
			}
		
		src += '</tr>';
		}
	src += '</table></div>';
	}
	$(".photoList").html(src);
	
};

List.px = 100;	
List.current = 0;
List.length = Math.ceil(data.imgary.length / 12);
List.moveVal = 816;	
List.end = (List.length-1) * (List.moveVal - List.moveVal * 2) +100;	
List.motion = "easeOutCubic";
List.time = 1200;
List.lock = 0;
	
	
List.prev = function(){
	with(this){
		if(current <= 0 || lock == 1){
			return false;
		}
		lock = 1;
		px += moveVal;
		current --;
		move();
	}
	
};
List.next = function(){
	with(this){
		if(current >= length-1 || lock == 1){
			return false;
		}
		lock = 1;
		px -= moveVal;
		current ++;
		move();
	}
};
List.move = function(){
	$(".photoList").stop();
	$(".photoList").animate({ 
		left: this.px + "px"
	}, this.time ,this.motion,function(){
		with(List){
			lock = 0;
			set();
			if(current <= 1){
				px = 100 - (current * moveVal);
			}else{
				px = -1532;
			}
			$(".photoList").css("left",px + "px");
			$(".count").text(List.current + 1 + " / " + List.length);
		}
	});
};








/*

詳細ページ

*/
var Detail ={};
Detail.init = function(){
	var data = _Common_.url_Parse(document.URL);
	if(data){
	
		this.current = data.num;
		this.listCurrent = Math.max(0,data.num - 2);
		if(this.listCurrent >= this.length - 6){
			this.listCurrent = Math.min(this.length-6,data.num - 2);
		}
		this.set();
		this.img(data.num);
		this.listCurrent--;
	}else{
		this.img(0);
	}
	$(".photo ul").animate({ 
		opacity: 0
	}, this.time ,this.motion,function(){
		$(".photo ul").animate({ 
			opacity: 1
		}, Detail.time ,Detail.motion);
	});

};
Detail.set = function(){
	
	with(this){
		var src ="";
		var ln = Math.min(8,data.imgary.length);
		for(i=Math.max(0,listCurrent-1);i<listCurrent + ln;i++){
			if(data.imgary[i]){
				if(i==current){
					src +='<li id="photo_' + i + '"><a class="current" href="/image_data/large/' + data.lid + '/' + data.imgary[i] + '.jpg" onclick="Detail.img(' + i + ');return false;"><img src="/image_data/small/' + data.lid + '/' + data.imgary[i] + '" /></a></li>';
				}else{
					src +='<li id="photo_' + i + '"><a href="/image_data/large/' + data.lid + '/' + data.imgary[i] + '" onclick="Detail.img(' + i + ');return false;"><img src="/image_data/small/' + data.lid + '/' + data.imgary[i] + '" /></a></li>';
				}
			}
		}
		
		$(".photo ul").html(src);
	}
};
Detail.motion = "easeOutCubic";	
Detail.time = 250;	
Detail.current = 0;	

Detail.px = 0;	
Detail.moveVal = 121;	
Detail.length = data.imgary.length;	
Detail.end = Math.max(Detail.length - 7,0) * Detail.moveVal;	

Detail.img = function(num){
	var a = ".photo a";
	var img = ".mainImg th img";
	var ln = 0;
	$(img).stop();
	$(a).removeAttr("class");
	
	if(this.listCurrent <= 0){
		var ln = num;
	}else{
		var ln = num - this.listCurrent + 1;
	}
	$("#photo_" + num + " a").attr("class","current");
	this.current = num;
	$(img).animate({ 
		opacity: 0
	}, this.time ,this.motion,function(){ //data.imgary[i]
		$(img).attr("src","/image_data/large/" + data.lid + "/" + data.imgary[Detail.current]);
		$(img).animate({ 
			opacity: 1
		}, Detail.time ,Detail.motion);
	});

};

Detail.prevMain = function(){
	with(this){
		if(current <= 0){
		
			return false;
		}else{
			var imgPath = ".mainImg th img";
			$(imgPath).stop();
			$(".photo a").removeAttr("class");
			current--;
			if(listCurrent <= 0){
				var ln = current;
			}else{
				var ln = current - listCurrent + 1;
			}
			
			$("#photo_" + current + " a").attr("class","current");
			

			$(imgPath).animate({ 
				opacity: 0
			}, time ,motion,function(){ //data.imgary[i]
				$(imgPath).attr("src","/image_data/large/" + data.lid + "/" + data.imgary[Detail.current]);
				
				$(imgPath).animate({ 
					opacity: 1
				}, Detail.time ,Detail.motion);
				
			});
		
		}
		/*
		if(current < listCurrent || current > $(".photo a").length + listCurrent){
		
			var imgPath = ".mainImg th img";
			$(".photo a").removeAttr("class");
			current--;

			$(imgPath).animate({ 
				opacity: 0
			}, time ,motion,function(){ //data.imgary[i]
				$(imgPath).attr("src","common/img/"+data.imgary[Detail.current]);
				
				$(imgPath).animate({ 
					opacity: 1
				}, Detail.time ,Detail.motion);
				
			});
		
		}else{
		
			if(current <= 0){
				return false;
			}else{
				img(current - 1);
			}
			
		}
		*/
	}
};

Detail.nextMain = function(){
	with(this){
		if(current >= length -1){
			return false;
		}else{


			var imgPath = ".mainImg th img";
			$(imgPath).stop();
			$(".photo a").removeAttr("class");
			current++;
			if(listCurrent <= 0){
				var ln = current;
			}else{
				var ln = current - listCurrent+1;
			}
			
			$("#photo_" + current + " a").attr("class","current");
			

			$(imgPath).animate({ 
				opacity: 0
			}, time ,motion,function(){ //data.imgary[i]
				$(imgPath).attr("src","/image_data/large/" + data.lid + "/" + data.imgary[Detail.current]);
				
				$(imgPath).animate({ 
					opacity: 1
				}, Detail.time ,Detail.motion);
				
			});


		}
	}
};




Detail.prevList = function(){
	with(this){
		if(listCurrent <= 0 || lock == 1){
			return false;
		}
		listCurrent--;
		px += moveVal;
		listMove();
	}
};

Detail.nextList = function(){
	with(this){
		if(listCurrent >= length - 7 || lock == 1){
			return false;
		}
		listCurrent++;
		px -= moveVal;
		listMove();
	}
};
Detail.listCurrent = 0;
Detail.lock = 0;
Detail.listMove = function(){
	this.lock = 1;
	$(".photo ul").stop();
	$(".photo ul").animate({ 
		marginLeft: this.px + "px"
	}, 150 ,"swing",function(){
	
		with(Detail){
			set();
			if(listCurrent <= 0){
				px = 0;
			}else{
				px = -121;
			}
			$(".photo ul").css("marginLeft",px + "px");
			lock = 0;
//		alert(listCurrent + ":" + current);
		}
	});
};










$(document).ready(function(){
	_Common_.initRollovers();
	if(data){
		List.init();
		Detail.init();
	}
});






jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});


