
/**
 * UILock
 * @param options	lock:	ロック時に実行されるfunction
 * 					unlock:	アンロック時に実行されるfunction
 * 					timeout:タイムアウト時に実行されるfunction
 * @returns
 */
var UILock = function(options){
	this.options = options;
	this.init();
};
UILock.prototype = {
	init: function(){
		this.funcs = {};
		this.locking = false;
		this.lockTimer = null;
		this.unlockTimer = null;
	},
	lock: function(time){
		this.locking = true;
		if(this.lockTimer){
			//ロックタイマーが既にセットされていたらクリアーしておく
			clearTimeout(this.lockTimer);
		}
		if(time){
			this.lockTimer = setTimeout(function(){
				try{
					this.options.timeout();
				}catch(e){}
				this.unlock();
			}.scope(this),time);
		}
		try{
			this.options.lock();
		}catch(e){
		}
	},
	isLock: function() {
		return this.locking;
	},
	unlock: function(time){
		if(this.lockTimer){
			//ロックタイマーが既にセットされていたらクリアーしておく
			clearTimeout(this.lockTimer);
		}
		if(!time){
			time = 0;
		}
		this.unlockTimer = setTimeout(function(){
			this.locking = false;
			try{
				this.options.unlock();
			}catch(e){
			}
		}.scope(this),time);
	}
};

/**
 *
 * @param options	show: イベント
 * 					hide: イベント
 * @returns
 */
var UIMessage = function(options){
	this.message = null;
	this.timer = null;
	this.counterTimer = null;
	this.counter = 0;
	this.obj = null;
	this.messageObj = null;
	this.options = options ? options : {};
};
UIMessage.prototype = {
	/**
	 *
	 * @param str
	 * @param timer 表示タイマー
	 * @param counter カウンタを発動するならtrue(表示タイマーが動作している場合のみ）
	 */
	show: function(str, timer, counter){
		if(str){
			this.set(str);
		}
		if(timer){
			this.setTimer(timer);
			if(counter === true){
				this.counter = Math.floor(timer/1000)+1;
				this.actionCounter();
			}
		}else{
			this.clearTimer();
		}
		this.getObj().show();
		if(this.options.show){
			this.options.show();
		}
	},
	actionCounter: function(){
		if(this.counter <= 0){return;}
		this.counter--;
		this.refreshMessage();
		setTimeout(this.actionCounter.scope(this), 1000);
	},
	hide: function(){
		this.getObj().hide();
		if(this.options.hide){
			this.options.hide();
		}
	},
	set: function(str){
		this.message = str;
		this.refreshMessage();
	},
	refreshMessage: function(){
		var str = this.message;
		str = str.replace(/%counter%/g, this.counter);
		this.getMessageObj().html(str);
	},
	setTimer: function(time){
		this.clearTimer();
		this.timer = setTimeout(function(){
			this.hide();
		}.scope(this),time);
	},
	clearTimer: function(){
		if(this.timer){
			try{
				clearTimeout(this.timer);
			}catch(e){}
		}
	},
	getObj: function(){
		return this.obj;
	},
	setObj: function(obj){
		this.obj = obj;
	},
	getMessageObj: function(){
		return this.messageObj;
	},
	setMessageObj: function(obj){
		this.messageObj = obj;
	}
};

var KanappsEntertainment = {
	nmoudame: function(str, callback){
		if(!str){
			return;
		}
		$.ajax({
			url: "http://tekito.kanichat.com/nmoudame/response.php",
			method: "GET",
			dataType: "jsonp",
			success: function(json){
				callback(json.result);
			},
			data: {
				length: 6,
				normal: 1,
				small: 1,
				dots: 1,
				ltu: 1,
				ltu_prob: 30,
				ex: 1,
				ex_prob: 30,
				c: 0,
				mode: "js",
				str: str
			}
		});
	}
};
