(function () {
    var ie = (function(){
        var undef, v = 3, div = document.createElement('div');

        while (
            div.innerHTML = '<!--[if gt IE '+(++v)+']><i></i><![endif]-->',
            div.getElementsByTagName('i')[0]
        );

    return v> 4 ? v : undef;
    }());

    var hidden = document.getElementById('mainVisualData');

    if (hidden.value === '') {
        return false;
    }

    hidden.parentNode.appendChild((function () {
        var imgTag = document.getElementById('main-visual');

        if (ie >= 9) {
            var images = JSON.parse(Base64.decode(hidden.value));
        } else {
            var images = eval(Base64.decode(hidden.value));
        }

        var image = images[Math.floor(Math.random() * images.length)];
        imgTag.src = image.path;
        imgTag.width = image.width;
        imgTag.height = image.height;
        imgTag.alt = image.alt;

        if (image.url) {
            return (function () {
                var anchor = document.createElement('a');
                anchor.href = image.url;

                if (image.blank === '1') {
                    anchor.target = '_blank';
                }

                anchor.appendChild(imgTag);

                return anchor;
            })();
        } else {
            return imgTag;
        }
    })());
})();

