var VWAB = function () {
    var variation = {};

    function getCookie(name) {
        var cookies = document.cookie.split(';');
        for (var foo = 0; foo < cookies.length; foo++) {
            var parts = cookies[foo].replace(/ /g, '').split("=");
            if (parts[0] == name) {
                return decodeURIComponent(parts[1]);
            }
        }
        return null;
    }

    function setCookie(name, value) {
        var date = new Date();
        date.setTime(date.getTime() + 2592000000);
        document.cookie = name + "=" + encodeURIComponent(value) + "; expires=" + date.toUTCString() + "; path=/";
    }

    function createTest(testName, ratios) {
        if (typeof(ratios) == "undefined") {
            variation[testName] = 0;

            return;
        }

        var variationCount = ratios.length,
            myVariation = getCookie(testName),
            varRand = Math.random();

        if (myVariation === null) {
            myVariation = 0;

            for (var n = 0; n < variationCount; n++) {
                if (varRand > ratios[n]) {
                    myVariation = n + 1;
                }
            }

            setCookie(testName, myVariation);
        }

        variation[testName] = myVariation;
    }

    return {
        variation: variation,
        createTest: createTest,
        getCookie: getCookie,
        setCookie: setCookie
    }
}();

//VWAB.createTest("ab-mhp", [0.8]);   // > 0.8 = 20% visitors
VWAB.createTest("ab-mhp");  // Force the old version
