(function($){
	
	var _email = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
	var _url = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
	
	var methods = {
		check : function(regex, value){
			var str = "_"+regex+".test('"+value+"')";
			var isValid = eval(str);
			if(!isValid){return false;}
			else{return true;}
		}
	};
	
	REGEX = function(method){
		if ( methods[method] ) {
            return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
            return methods.init.apply( this, arguments );
        } else {
            $.error( 'Method '+method +' does not exist.' );
        }
	};
})(jQuery);

(function($){

	var _form = null;
	
	var _verify = function(){
		var isValid = REGEX('check', 'email', $('#form-email').val());
		return isValid;
	};
	
	var _save = function(){
		
		var datas = $('#form').serialize();
		$.ajax({
			type: 'POST',
			url: $('#form').attr('action'),
			data: datas,
			dataType: 'json',
			cache : false,
			beforeSend: function () {
				console.log('beforeSend');
			},
			success: function (json) {
				
				$('#result').html('<span>'+json.message+'<span>').css({background:'#00B1F2'}).animate({background:'#0099D1'}, 300);
				
			}
		});
	};
	
	var methods = {
		init : function(){
			$('#form').bind('submit', function(e){
				var valid = _verify();
				if(valid){
					_save();
				}
				return false;
			});
		}
	};

	IKO = function(method){
		if ( methods[method] ) {
            return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
            return methods.init.apply( this, arguments );
        } else {
            $.error( 'Method '+method +' does not exist.' );
        }
	};

})(jQuery);



$(document).ready(function(){
	IKO('init');
});

