var theInt = null;
var $crosslink, $navthumb;
var curclicked = 0;
		
theInterval = function(cur){
	
	clearInterval(theInt);
	
	if( typeof cur != 'undefined' )
		curclicked = cur;
			
		$crosslink.removeClass("active-thumb");
		$navthumb.eq(curclicked).parent().addClass("active-thumb");
		$(".stripNav ul li a").eq(curclicked).trigger('click');
			
	theInt = setInterval(function(){
		$crosslink.removeClass("active-thumb");
		$navthumb.eq(curclicked).parent().addClass("active-thumb");
		$(".stripNav ul li a").eq(curclicked).trigger('click');
		curclicked++;
		if( 4 == curclicked )
			curclicked = 0;
				
	}, 8000);
};
		






$(document).ready(function(){
	
	//移動時間
	var span = 1000;
	var effect = 'easeOutExpo';
	
	$(function() {
		
		//Operaの場合、”html,body”をanimateすると表示がおかしくなるので、Operaの場合のみ”html”を指定。
		var ua = $.browser;
		
		$("a[href*=#]").click(function() {
									   
			if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
				
				$(this).blur();
				
				var t = navigator.appName.match(/Opera/) ? "html" : "html,body";
				
				$(t).queue([]).stop();
				
				var $targetElement = $(this.hash);
				
				var scrollTo = $targetElement.offset().top;
				
				if (window.scrollMaxY) {
					var maxScroll = window.scrollMaxY;
				} else {
					var maxScroll = document.documentElement.scrollHeight - document.documentElement.clientHeight;
				}//end if
						
				if (scrollTo > maxScroll){
					scrollTo = maxScroll;
				}//end if
				
				
				if(scrollTo != 0){
					span =1000;
					effect ='easeOutExpo';
				}else{
					span =5000;
					effect ='easeInOutQuart';
				}
						
				$(t).animate({ scrollTop: scrollTo }, span, effect);
					return false;
			}//end if
			
		});//end of function
	 });//end of function
	
	
	
	
	$(function(){
			
		$("#main-photo-slider").codaSlider();
			
		$navthumb = $(".nav-thumb");
		$crosslink = $(".cross-link");
			
		$navthumb.click(function() {
			clearInterval(theInt);
			var $this = $(this);
			theInterval($this.parent().attr('href').slice(1) - 1);
			return false;
		});
			
		theInterval();
	});
	
	
});



//ROLL_OVER
function setRollOver() {
	if (!document.getElementsByTagName) return false;
	var ovrImgList = document.getElementsByTagName('img');
	for (var i = 0; i < ovrImgList.length; i++) {
		if (ovrImgList[i].src.match(/_off\./i)) {
			var loadedImg = new Image();
			loadedImg.src = ovrImgList[i].src.replace(/_off\./i, '_over.');
			ovrImgList[i].onmouseover = function() { // マウスオーバー
				this.src = this.src.replace(/_off\./i, '_over.');
			}
			ovrImgList[i].onmouseout = function() { // マウスアウト
				this.src = this.src.replace(/_over\./i, '_off.');
			}
			ovrImgList[i].onmouseup = function() { // クリック後のロールオーバー解除
				this.src = this.src.replace(/_over\./i, '_off.');
			}
		}
	}
	
	return true;
}
if (window.addEventListener) window.addEventListener('load', setRollOver, false);
if (window.attachEvent) window.attachEvent('onload', setRollOver);


