// 外部ファイル読込jQuery Plug-in
// @param options
(function($){
    $.fn.loading = function(options){
        options = $.extend({
            type: 'GET',
            dataType: 'html',
            timeout: 5000,
            url: ''
        }, options);
        var elm = this;
        var htmlData, statusType = '';
        $.ajax({
            type: options.type,
            dataType: options.dataType,
            timeout: options.timeout,
            url: options.url,
            cache: false,
            success: function(data, dataType){
                if (data) {
                    htmlData = data;
                    statusType = 'ok';
                }
                else {
                    htmlData = '';
                    statusType = 'ng';
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                statusType = 'no_connect';
            },
            complete: function(XMLHttp, textStatus){
                var __mode = statusType;
                var data;
                switch (__mode) {
                    case 'ok':
                        data = htmlData;
                        break;
                    case 'ng':
                        data='';
                        break;
                    case 'no_connect':
                        data = '';
                        break;
                    default:
                        data = '';
                        break;
                }
                elm.hide().append(data).show();
            }
        });
    };
})(jQuery);

