jQuery.noConflict();

jQuery(function() {
	
	// アコーディオン制御
	menuAccordionControl();
	
	// イメージリンク制御
	imageLinkControl();
	
	// グローバルナビ制御
	navMenuControl();
	
	// スライドショー制御
	slideshowControl();
	
	// スムーススクロール制御
//	smoothScrollControl();
	
	slideshowControl();
	
});


// -----------------------------------------------------------------------
// アコーディオン処理
// -----------------------------------------------------------------------
function menuAccordionControl() {

	jQuery("#menu h3").click(function(){
		
		jQuery(this).next("ul").stop(true,true).slideToggle("slow");
		
	});
}

// -----------------------------------------------------------------------
// イメージリンク処理
// -----------------------------------------------------------------------
function imageLinkControl() {
	
	// 記事中のリンク画像
	jQuery('#sidebar a img, #search a img').hover(
		function() {
			jQuery(this).fadeTo("fast",0.7);
		},
		function() {
			jQuery(this).stop(true,true).fadeTo("fast",1);
		}
	);
}

// -----------------------------------------------------------------------
// グローバルナビ処理
// -----------------------------------------------------------------------
function navMenuControl() {
	
	// 記事中のリンク画像
	jQuery('#global_nav img').hover(
		function() {
			jQuery(this).stop().attr('src', jQuery(this).attr('src').replace('_off', '_on')).fadeTo('fast',0.7).fadeTo('normal',1);
		},
		function() {
			if (!jQuery(this).hasClass('currentPage')) {
				jQuery(this).stop().fadeTo(1,1).attr('src', jQuery(this).attr('src').replace('_on', '_off'));
			}
		}
	);
}

// -----------------------------------------------------------------------
// スムーススクロール処理
// -----------------------------------------------------------------------
jQuery.easing.quart = function (x, t, b, c, d) {
    return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

function smoothScrollControl() {

	// スムーススクロール処理
	jQuery('a[href*=#]').click(function() {
	//jQuery('#gototop a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var target = jQuery(this.hash);
			target = target.length && target || jQuery('[name=' + this.hash.slice(1) +']');
			if (target.length) {
				var targetOffset = target.offset().top;
				jQuery('html,body').animate({ scrollTop: targetOffset }, 1200, 'quart');
				return false;
			}
		}
	});
	
}



// -----------------------------------------------------------------------
// スライドショー処理
// -----------------------------------------------------------------------

var TIMER_INTERVAL = 3000;
var current_index = -999;
var max_index = -999;
var do_timer = 0;

function slideshowControl() {
	
	var max_index = jQuery("#pictarea2 .slideshow li").length;
	
	def = Math.floor( Math.random() * max_index );
	
	// 初期のスライドを設定
	setCurrentSlide(def);
	
	// =====================================================
	// スライドショー
	// =====================================================
	// -----------------------------------------------------
	// タイマー処理
	// -----------------------------------------------------
	do_timer = jQuery.timer(TIMER_INTERVAL, function (timer) {
		next_index = current_index + 1;
		if ( next_index >= max_index ) {
			next_index = 0;
		}
		setCurrentSlide(next_index);
	});
	
}


// スライドを設定
function setCurrentSlide(index) {
	
	before_index = current_index;
	
	if (before_index == index) {
		return;
	}
	
	// -----------------------------------------------------
	// 旧スライドを非表示
	// -----------------------------------------------------
	// select slide & thumb
	slide = jQuery("#pictarea1 .slideshow li").get(before_index);
	
	// fadeIn
	jQuery(slide).fadeOut("slow");
	
	// select slide & thumb
	slide2 = jQuery("#pictarea2 .slideshow li").get(before_index);
	
	// fadeIn
	jQuery(slide2).fadeOut("slow");
	
	
	// -----------------------------------------------------
	// 新スライドを表示
	// -----------------------------------------------------
	// select slide & thumb
	slide = jQuery("#pictarea1 .slideshow li").get(index);
	
	// fadeIn
	jQuery(slide).fadeIn("slow");
	
	// select slide & thumb
	slide2 = jQuery("#pictarea2 .slideshow li").get(index);
	
	// fadeIn
	jQuery(slide2).fadeIn("slow");
	
	current_index = index;
}



