
var photo_scrollapi;
var curPhoto="";
var prevPhoto="";
var sel_flg=0;
var mode=2;
var curPhotoNum=0;
var chagePhotoDelay=3600;

/* select photo thum	*/
function selectPhoto_user(e,skip){
	s_setTimeout("nextPhoto()", chagePhotoDelay);
	
	return selectPhoto(e,skip);
}
function selectPhoto(e,skip){
	if( sel_flg != 0 ){
		/* 	ItF[h͖	 */
		return false;
	}else{
		sel_flg=1;
		var splitkey="/--/";
		var imgs = $(e).children("img");
		var changeSrc = $(imgs).attr("src");
		var changeHref = $(e).attr("href");
		
		if( curPhoto==changeSrc ){
			sel_flg=0;
			return false;
		}
		if( prevPhoto != "undefined"){
			/* 	OItHg̑IgNA	 */
			$(prevPhoto).attr("class","");
		}
		/* 	ItHg̑Igݒ	 */
		$(e).attr("class","active");
		prevPhoto=e;
		curPhoto=changeSrc;
		
		/* 	alteLXg擾	 */
		var alts=$(imgs).attr("alt")+splitkey;
		var changealt = alts.split(splitkey)[0];
		var changealt2 = alts.split(splitkey)[1];
		var fadetim=600;
		var fadeintim2=800;
		if( skip > 0){
			fadetim=skip;
			fadeintim2=skip;
		}
		
		/* set img src */
		$("#photo-image-target").fadeOut(
			fadetim,
			function() {
				$(this).attr("src", changeSrc);
				$(this).attr("title", changealt);
				$(this).fadeIn(fadeintim2);
				sel_flg=0;
			}
		);
		/* set title text */
		$(".first-photo-text .photo-text-head-line").fadeOut(
			fadetim,
			function() {
				$(this).attr("innerHTML",changealt);
				$(this).fadeIn(fadetim);
			}
		);
		/* set info text */
		$(".first-photo-text .photo-text-info-line").fadeOut(
			fadetim,
			function() {
				$(this).attr("innerHTML",changealt2);
				$(this).fadeIn(fadetim);
			}
		);
		/* set link href */
		var flink=$("a.photo-link");
		$(flink).attr({href:changeHref,alt:changealt});
	}
	return false;
}

/*setup photo selecter*/
$(document).ready(function() {
	photo_scrollapi=$(".photo-selector  .scrollable-items").scrollable({horizontal:true,api:true,size: 5});
	$(document).ready(function (e) {
		$(".photo-selector  .scrollable-items .items a ")
		.hover( 
			function(){$(this).fadeTo(10, 0.5);},
			function(){$(this).fadeTo(20, 1);	}
		)
		.mouseover(function(){ return selectPhoto_user(this,100);} );
		/*
		.click(function(){ return selectPhoto_user(this,100);} );
		*/
	});
});

/*************** HOME Photo setup ***************/
$(document).ready(function(){
	var items=$(".photo-selector .scrollable-items  .items a");
	if( items != "undefined"){
		if( mode==1){
			/*random*/
			var lmax=4;
			lmax=lmax>items.length?items.length:lmax;
			var randnum = Math.floor( Math.random() * (lmax) ); 
			selectPhoto(items[randnum],1);
			curPhotoNum=randnum;
			photo_scrollapi.seekTo(randnum,1);
			
		}else{
			selectPhoto(items[0],1);
			photo_scrollapi.seekTo(0,1);
			
		}
		if( mode==2){
			s_setTimeout("nextPhoto()", chagePhotoDelay);
		}
	}
});

function nextPhoto(){
	var items=$(".photo-selector .scrollable-items  .items a");
	if( items != "undefined"){
		var num=curPhotoNum+1;
		num = num >= items.length ? 0 : num;
		selectPhoto(items[num],0);
		/*photo_scrollapi.seekTo(num,1);*/
		curPhotoNum=num;
	}
	s_setTimeout("nextPhoto()", chagePhotoDelay);
}
var stid=-1;
function 	s_setTimeout(func,delay){
	clearTimeout(stid);
	stid=setTimeout(func,delay);
}

/*setup disc selecter*/
$(document).ready(function() {
	$(".disc-selector .scrollable-items ").scrollable({horizontal:true});
	$(document).ready(function () {
		$(".disc-selector .scrollable-items  .items a")
		.fadeTo(1,1)
		.hover( 
			function(){
				$(this).fadeTo(1, 0.2);
			},
			function(){
				$(this).fadeTo(1, 1);
			}
		)
		.mouseover( function() {
			var splitkey="|";
			var imgs = $(this).children("img");
			var changeSrc = $(imgs).attr("src");
			var changeHref = $(this).attr("href");
			var alts=$(this).attr("title")+splitkey+splitkey;
			var changealt = alts.split(splitkey)[0];
			var changealt2 = alts.split(splitkey)[1];
			var changealt3 = alts.split(splitkey)[2];
			$("#disc-image-target").fadeOut(
				100,
				function() {
					$(this).attr("src", changeSrc);
					$(this).fadeIn(100);
				}
			);
			// set title text
			$("#disc-head-artist").fadeOut(
				100,
				function() {
					$(this).attr("innerHTML",changealt2);
					$(this).fadeIn(100);
				}
			);
			// set disc text
			$("#disc-head-disctitle").fadeOut(
				100,
				function() {
					$(this).attr("innerHTML",changealt3);
					$(this).fadeIn(100);
				}
			);
			// set disc text
			$("#disc-head-textline").fadeOut(
				100,
				function() {
					$(this).attr("innerHTML",changealt);
					$(this).fadeIn(100);
				}
			);
			return false;
		});
	});
});

