MMWCore.CDN = {
    useCDN: false,
    buildNumber: '',
    arrayCDNHostnames: [],
    sslEnabled: false,
    getCDNPath: function (path) {
        if (!this.useCDN) {
            return path;
        }
        if (path.trim().substring(0,1) != '/') {
            return path;
        }
        var cleanPath = path.trim().replace(/\/+/,'/');
        var pathMatch = (/(API_RES\/1\.2|mmw)/).exec(cleanPath);
        if (pathMatch && pathMatch[0] != '') {
            var midPath = pathMatch[0].replace(/\/1\.2/, '');
            var imagePath = '/' + midPath + (this.buildNumber != '' ? '/' + this.buildNumber : '') + cleanPath.substring(pathMatch.index + pathMatch[0].length);
            var aryPath = imagePath.split('/');
            var protocol = 'http';
            if (this.sslEnabled) {
                protocol = 'https';
            }
            return protocol + '://' + this.arrayCDNHostnames[aryPath[aryPath.length-1].length%4] + aryPath.join('/');
        } else {
            return path;
        }
    }
}

