/* $.fn.circus */
$.fn.circus = function(options){

	//デフォルト値
		var c = $.extend({
		interval: 5000,
		fade: 'fast'
		},options);

	var curucuru = function fnname() {
	var $active = $('li.active',c.target);
	var $next =  $active.next().length ? $active.next(): $(c.target).find('li:first');
	$active.animate({'filter':'alpha(opacity=0)','-moz-opacity': '0.0','opacity': '0.0'}, c.fade).addClass('last-active');
	$next.css({'filter':'alpha(opacity=0)','-moz-opacity': '0.0','opacity': '0.0'})
	.addClass('active')
	.animate({'filter':'alpha(opacity=100)','-moz-opacity': '1.0','opacity': '1.0'}, c.fade, function() {
		$active.removeClass('active last-active');
//オマケ機能
		var number = $('#circus li.active').index();
		$('#numspace').html(number+1+' / '+$('#circus li').length);
	});
}

/*
2個以上書く場合で挙動制御する場合は、setTimeout（setIntervalも）タイマーIDの分割が必要、かつ、それぞれのターゲットの状態を設定する必要があるんでどうしても冗長化してしまいます。

コントロール不要なら複数でも下記のこれだけでいけるはず
	sn = setInterval( curucuru, c.interval );

要コントロールかつ1このときはサーカス設定とストップ挙動のclick functionがいります。

			var phase_sn=0;
			sn = setInterval( curucuru, c.interval );

		$(c.stop).click(function(){
			if (phase_sn!=1){
				clearInterval(sn);
				phase_sn=1;
				$('#stop_circus').html('再生');
			}else{
				phase_sn=0;
				sn = setInterval( curucuru, c.interval );
				$('#stop_circus').html('停止');
			}
		});

*/

	if(c.target=='#circus'){
			var phase_sn=0;
			sn = setInterval( curucuru, c.interval );
	}else{
			var phase_sn2=0;
			sn2 = setInterval( curucuru, c.interval );
	}

$(c.stop).click(function(){
if(c.target=='#circus'){
	if (phase_sn!=1){
		clearInterval(sn);
		phase_sn=1;
		$('#stop_circus').html('<img src="/view/images/btn_play.gif" alt="スライドショー再生" />');
	}else{
		phase_sn=0;
		sn = setInterval( curucuru, c.interval );
		$('#stop_circus').html('<img src="/view/images/btn_stop.gif" alt="スライドショー一時停止" />');
	}
}else{
	if (phase_sn2!=1){
		clearInterval(sn2);
		phase_sn2=1;
		$('#stop_circus2').html('<img src="/view/images/btn_play.gif" alt="スライドショー再生" />');
	}else{
		phase_sn2=0;
		sn2 = setInterval( curucuru, c.interval );
		$('#stop_circus2').html('<img src="/view/images/btn_stop.gif" alt="スライドショー一時停止" />');
	}
}
});


}


/* circus function (another_js_file can use) */
/*
アクセシビリティ対応に関しては<noscript>で同じulを吐き出してください。
*/
$(function(){


if($('#circus li').length==1){
	$('#circus li').addClass('active');
	$('#circus_ctrl').css({'display':'none'});
}else{
	$('#circus').parent().addClass('slideshow').find('li:first').addClass('active').circus({
	  interval: 7700,
	  target: '#circus',
	  stop: '#stop_circus',
	  fade: "normal"
	});
//オマケ機能
		var number = $('#circus li.active').index();
		$('#numspace').html(number+1+' / '+$('#circus li').length);
}

if($('#circus2 li').length==1){
	$('#circus2 li').addClass('active');
	$('#circus_ctrl2').css({'display':'none'});
}else{
	$('#circus2').parent().addClass('slideshow').find('li:first').addClass('active').circus({
	  interval: 5500,
	  target: '#circus2',
	  stop: '#stop_circus2',
	  fade: "normal"
	});
}


});

