if(typeof caseinc === "undefined") caseinc = {};

/**
 * Script: effect.js
 * Class: caseinc.effect
 * Copyright (c) 2011 [CASE Inc. (http://caseinc.jp/)]
*/
caseinc.effect = function()
{
	var graphics = new caseinc.graphics();
	
	//マウスオーバーで透明度を上げます。
	this.opacityFade = function(className)
	{
		$("."+className).each(function(i)
		{
			$(this).mouseover(function()
			{
				$(this).css(
				{
					"opacity"	: "0.7"
				});
			});
			$(this).mouseout(function()
			{
				$(this).css(
				{
					"opacity"	: "1"
				});
			});
		});
	};
	
	/**
	 * 指定クラス要素内の文字列1文字ずつフェード表示します。
	 */
	this.blinkFadeTextByClass = function(className)
	{
		$("."+className).each(function(i)
		{
			var txt = $(this).html();
			$(this).html("");
			var me = this;
			var txt_num = txt.length;
			for(var j=0;j<txt.length;j++){
				$(this).append("<span id='"+className+i+"_"+j+"'>"+txt.charAt(j)+"</span>");
				$("#"+className+i+"_"+j).css(
				{
					"color"	: "#fff"
				});
			}
			var count = 0;
			var st = setInterval(function(){
				if(txt_num == count)
				{
					clearInterval(st);
					$(me).html(txt);
				}
				$("#"+className+i+"_"+count).animate({"color": "#000"}, 100);
				count++;
			}, 70);
		});
	};
	
	
	/**
	 * 金額をアニメーション表示します。
	 */
	this.animatePriceByClass = function(className)
	{
		var uni_txt = "0123456789";
		
		$("."+className).each(function(i)
		{
			var txt = $(this).html();
			$(this).html("");
			
			for(var j=0;j<txt.length;j++){
				$(this).append("<span id='"+className+i+"_"+j+"'></span>");
			}
			var n = 0;
			setInterval(function(){
				nextTextDisp(txt.charAt(n), n);
				n++;
			}, 70);
			
			function nextTextDisp(str, str_no){
				var k = 0;
				var t = setInterval(function(){
					if(str === uni_txt.charAt(k) || k > uni_txt.length || uni_txt.indexOf(str, 0) < 0)
					{
						$("#"+className+i+"_"+str_no).text(str);
						$("#"+className+i+"_"+str_no).animate({
							"color" : graphics.random_rgb()
							}, 100, "easeInOutCirc", function(){
								$("#"+className+i+"_"+str_no).animate({
									"color" : "#000"
							}, 100);
						});
						clearInterval(t);
					}
					else
					{
						$("#"+className+i+"_"+str_no).text(uni_txt.charAt(k));
						k++;
					}
				}, 100);
			}
		});
	};
	

	this.loadingAnimation = function()
	{
		//LoadingAnimation
		var lfTimerID = new Array();
	
		/**
		 * LoadingAnimation play stop.
		 * @param id
		 */
		this.stopLoadingFlameAnimate = function (id)
		{
			$("#"+id).css("display", "none");
			clearInterval(lfTimerID[id]);
			lfTimerID[id] = null;
		};
	
		/**
		 * ローディング用アニメーション
		 * @param frame_id
		 * @param pointer_id
		 * @param speed
		 */
		this.loadingFrameAnimation = function(frame_id, pointer_id, speed)
		{
			if(!lfTimerID[frame_id])
			{
				$("#"+frame_id).css("display", "block");
				var w = getContentWidth(frame_id);
				var h = getContentHeight(frame_id);
				
				//初期値
				var top = h;
				var left = w;
				
				lfTimerID[frame_id] = setInterval(function()
				{
					//color
					$("#"+pointer_id).css("background-color", me.random_rgb());
					
					//move
					if(top <= 0 && left <= w) left += speed;
					if(left >= w && top <= h) top += speed;
					if(top >= h && left >= 0) left -= speed;
					if(left <= 0 && top >= 0) top -= speed;
					$("#"+pointer_id).css(
					{
						"top"	: top,
						"left"	: left
					});
				}, 30);
			}
		};
	};

	/**
	 * 画像のマウスオーバーした際に画像をフェードで差し替えます。
	 * @param id マウスオーバーで変換するID  
	 * @param time フェードする時間
	 */
	this.hoverFade = function (id, img_off, img_on, time)
	{
		$(id+", "+id+" a").css({
			"background"	: url(img_on),
			"display"			:"block"
		});
		$(id).css({
			"position"			:"absolute"
		});
		$(id+" a").css({
			"background"	: url(img_off)
		});
		$(id+" a").hover(
			function(){$(this).stop().animate({'opacity' : '0'}, time);},
			function(){$(this).stop().animate({'opacity' : '1'}, time);}
		);
	};
};
