var SASM = (function($, $$){
    $$.init = function() {
    };

    $$.debug = false;

    var loadedFiles = [];
    var loadingFiles = [];
    $$.load = function(urls, funcs) {
        if (typeof urls === "string") {
            urls = [urls];
        }
        if (typeof funcs === "function") {
            funcs = [funcs];
        }
                
        var index = 0;
        for (var i = 0; i <urls.length; i++) {
            if ($.inArray(urls[i], loadingFiles) < 0) {
                loadingFiles.push(urls[i]);
            }
            else if ($.inArray(urls[i], loadedFiles) < 0) {
                window.setTimeout(function() {$$.load(urls)}, 50);
                return;
            }
            else {
                index++;
            }
        }

        var _loading = function () {
            if (index < urls.length) {
                if ($$.debug) {
                    $.getScript(urls[index], function() {_loaded(urls[index])});
                }
                else {
                    $.ajaxSetup({cache: true});
                    $.getScript(urls[index], function() {_loaded(urls[index])});
                    $.ajaxSetup({cache: false});
                }
            }
        };

        var _loaded = function (url) {
            if (funcs && funcs.length > index) {
                funcs[index]();
            }
            index++;
            loadedFiles.push(url);
            _loading();
        };

        _loading();
        return $$;
    };

    return $$;

})(jQuery, SASM || {});
var $$ = SASM;
$$.debug = (window.location.hostname != "www.bluer.co.kr");

if (typeof console == "undefined") {
    console = {};
    console.log = function(msg) {
        if ($$.debug) {
            var $console = $("#IEDebugConsole");
            if ($console.length > 0) {
                if ($console.html() == '') {
                    $console.html('<div id="IEDebugHeader">Javascript Debug Console</div>' + msg)
                }
                else {
                    $console.html($console.html() + "<br />" + msg);
                }
            }
        }
    };
}


