/* ///////////////////////////////////////////////////////////////////////
Java Script 初期化
/////////////////////////////////////////////////////////////////////// */
$(function() {
	// ToolTip
	$("#tip a[title]").tooltip({effect:"fade"});
	// Tabs
	$("ul.tab1").tabs("div.panes1 > div");
	$("ul.tab2").tabs("div.panes2 > div");
	// Expose
	$(".expose").click(function() {
		$(this).expose();
	});
	// Jwise
	setJwise(1800, 5000, '0px', '0px', '0px', '26px', '#303030', '#303030', 'center', '0', '1');
	// delay FadeIn
	$('#fadeIn').fadeIn(1000);
});

/* ///////////////////////////////////////////////////////////////////////
jwise 本体
/////////////////////////////////////////////////////////////////////// */
(function($){
	// 乱数生成
	function rand(X, N) {
		if(!X) X = 10000;
		if(!N) return Math.floor(X * (Math.random() % 1));
		else{
			var inte = Math.floor((X - N + 1) * (Math.random() % 1));
			return N + inte;
		}
	}
	// 初期設定
	var opt, animContainer, jwiseInterval, firstInterval, curId;
	$.fn.jwise = function(options) {
		animContainer = $(this);
		opt = $.extend({
			animLines: "",
			animFadeTime: 700,
			animInterval: 3000,
			wordSpaceMin: animContainer.css("word-spacing"),
			letterSpaceMin: animContainer.css("letter-spacing"),
			fontSizeMin: animContainer.css("font-size"),
			fontSizeMax: animContainer.css("font-size"),
			colorStart: animContainer.css("color"),
			colorEnd: animContainer.css("color"),
			align: 'left',
			fadeMin: '1',
			fadeMax: '1'
		}, options);
		curId = 0;
		animContainer.each( function(){
			$(opt.animLines).css({ display: 'none' });
			clearInterval(jwiseInterval);
			firstInterval = opt.animInterval;
			runJwise();
			jwiseInterval = setInterval(function(){ runJwise(); }, opt.animInterval);
		});
	};
	// 停止
	$.fn.jwiseStop = function() {
		clearInterval(jwiseInterval);
	};
	// 実行
	function runJwise(){
		var divNum = $(opt.animLines + " > div").size();		// 要素数
		var anml = opt.animLines + " div:eq(" + curId + ")";	// 選択番号
		curId++;
		if (curId > divNum) curId = 0;
		opt.animInterval = opt.animInterval + (opt.animFadeTime*2);
		animContainer.animate({
			opacity: opt.fadeMin,
			wordSpacing: opt.wordSpaceMin,
			fontSize: opt.fontSizeMin,
			color: opt.colorStart,
			letterSpacing: opt.letterSpaceMin
		}, opt.animFadeTime);
		setTimeout(function(){ animContainer.html( $(anml).html() ); }, opt.animFadeTime);
		animContainer.css({ textAlign: opt.align });
		animContainer.animate({
			opacity: opt.fadeMax,
			wordSpacing: '0px',
			fontSize: opt.fontSizeMax,
			color: opt.colorEnd,
			letterSpacing: '0px'
		}, opt.animFadeTime);
	}
})(jQuery);

/* ///////////////////////////////////////////////////////////////////////
jwise 設定
/////////////////////////////////////////////////////////////////////// */
function setJwise(a, b, c, d, e, f, g, h, i, j, k){
	$('.animContainer').jwise({
		animLines: '.animLines',	// read all divs from the class "animLines"
		animFadeTime: a,			// a) time to fade in and out
		animInterval: b,			// b) next line after mSeconds
		wordSpaceMin: c,			// c) min word-spacing
		letterSpaceMin: d,
		fontSizeMin: e,				// e) min font-size
		fontSizeMax: f,				// f) max font-size
		colorStart: g,				// g) begin with the color
		colorEnd: h,				// h) end with the color
		align: i,					// i) set 1 value or array of valuee 
		fadeMin: j,
		fadeMax: k
	});
}

/* ///////////////////////////////////////////////////////////////////////
jwise 停止
/////////////////////////////////////////////////////////////////////// */
function stopAnimText(){
	$('.animContainer').jwiseStop();
}

