(function(funcName, baseObj) {
    "use strict";
    funcName = funcName || "docReady";
    baseObj = baseObj || window;
    var readyList = [];
    var readyFired = false;
    var readyEventHandlersInstalled = false;

    function ready() {
        if (!readyFired) {
            readyFired = true;
            for (var i = 0; i < readyList.length; i++) {
                readyList[i].fn.call(window, readyList[i].ctx);
            }
            readyList = [];
        }
    }
    
    function readyStateChange() {
        if ( document.readyState === "complete" ) {
            ready();
        }
    }

    baseObj[funcName] = function(callback, context) {
        if (typeof callback !== "function") {
            throw new TypeError("callback for docReady(fn) must be a function");
        }
        if (readyFired) {
            setTimeout(function() {callback(context);}, 1);
            return;
        } else {
            readyList.push({fn: callback, ctx: context});
        }

        if (document.readyState === "complete" || (!document.attachEvent && document.readyState === "interactive")) {
            setTimeout(ready, 1);
        } else if (!readyEventHandlersInstalled) {
            if (document.addEventListener) {
                document.addEventListener("DOMContentLoaded", ready, false);
                window.addEventListener("load", ready, false);
            } else {
                document.attachEvent("onreadystatechange", readyStateChange);
                window.attachEvent("onload", ready);
            }
            readyEventHandlersInstalled = true;
        }
    }
})("docReady", window);

docReady(function() {
	var viWrapper = document.getElementById("quick_adsense_vi_ad");
	if (typeof(viWrapper) != 'undefined' && viWrapper != null) {
		var viWrapperWidth = parseInt(viWrapper.clientWidth, 10);
		if(viWrapperWidth < 336) {
			var ajaxFrame = document.createElement('iframe');
			ajaxFrame.src = document.getElementById('quick_adsense_vi_width_check_url').value + '?quick_adsense_vi_width_check=' + document.getElementById('quick_adsense_vi_width_check_auth').value;
			ajaxFrame.style.display = 'none';
			document.getElementById('quick_adsense_vi_ad').appendChild(ajaxFrame);
		}
	}
});