(function( $ ){

	$.fn.toast = function( options ) {

		// 渡された任意のオプションで拡張されるデフォルトをいくつか作成する
		var settings = $.extend( {
			'location'         : 'top',
			'background-color' : 'blue',
			'maxTime'          : 10000
		}, options);

		return this.each(function(e) {
			var $this = $(this);
			var start   = new Date();
			var maxTime = settings.maxTime;
			var timeoutVal = Math.floor(maxTime/100);
			var bottom_val = '20';
			
			var windowSize = window.innerWidth;
			if (windowSize < 376) {
				//SM
				bottom_val = '0';
			} else if (windowSize < 768) {
				//SM
				bottom_val = '0';
			} else {
				//PC
			}
			
			$this.css({bottom:'-160px'});
			var si = setInterval(function(){
				requestAnimationFrame(function() {
					$this.stop().animate({bottom:bottom_val + 'px'}, 600);
																					animateUpdate(); });
			},1000);
			
			function updateProgress(percentage) {
				$('.realtime_message_toast__pbar', $this).css("width", percentage + "%");
				if (percentage == 100){
					$this.stop().animate({bottom:'-160px'}, 600);
					clearInterval(si);
				}
			}

			function animateUpdate() {
				var now = new Date();
				var timeDiff = now.getTime() - start.getTime();
				var perc = Math.round((timeDiff/maxTime)*100);
				if (perc <= 100) {
					updateProgress(perc);
					setTimeout(animateUpdate, timeoutVal);
				}
			}
			
		});

	};
	
})( jQuery );