//Alex Javascript Framework Version 0.1 beta
//Currently only base64 functions

var framework = (function() {
return {
    base64_encode: function (plain) {
        var b64= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
        var o1, o2, o3, bits, h1, h2, h3, h4, e = [], pad = '', c, coded;
        c = plain.length % 3;
        if (c > 0) {
            while (c++ < 3) {
                pad += '=';
                plain += '\u0000';
            }
        }
        for (c = 0; c < plain.length; c += 3) {
            o1 = plain.charCodeAt(c);
            o2 = plain.charCodeAt(c + 1);
            o3 = plain.charCodeAt(c + 2);
            bits = o1 << 16 | o2 << 8 | o3;
            h1 = bits >> 18 & 0x3f;
            h2 = bits >> 12 & 0x3f;
            h3 = bits >> 6 & 0x3f;
            h4 = bits & 0x3f;
            e[c / 3] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
        }
        coded = e.join('');
        coded = coded.slice(0, coded.length - pad.length) + pad;
        return coded;
    },

    base64_decode: function (plain) {
        var b64= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
        var o1, o2, o3, h1, h2, h3, h4, bits, d = [], coded = plain;
        for (var c = 0; c < coded.length; c += 4) {
            h1 = b64.indexOf(coded.charAt(c));
            h2 = b64.indexOf(coded.charAt(c + 1));
            h3 = b64.indexOf(coded.charAt(c + 2));
            h4 = b64.indexOf(coded.charAt(c + 3));
            bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
            o1 = bits >>> 16 & 0xff;
            o2 = bits >>> 8 & 0xff;
            o3 = bits & 0xff;
            d[c / 4] = String.fromCharCode(o1, o2, o3);
            if (h4 === 0x40) {
                d[c / 4] = String.fromCharCode(o1, o2);
            }
            if (h3 === 0x40) {
                d[c / 4] = String.fromCharCode(o1);
            }
        }
        plain = d.join('');
        return plain;
    }
 };
}());
