(function() {
    INTEL("widget", function() {
        // If this has already been done, don't do it again.
        if (!INTEL.widget.onmessage) {
            // Shorten the domain.
            document.domain = "intel.com";
            // Setup an message handler to initialize and dispatch 
            // messages to the specific widgets.
            INTEL.widget.onmessage = function(data, widget) {
                // When the data.ready comes back call the
                // readyInitialize function on the widget itself.
                var widgetMethods = jQuery[widget.name];
                if (data && 
                    data.ready &&
                    widget && 
                    widgetMethods && 
                    jQuery.isFunction(widgetMethods.readyInitialize)) {
                        widgetMethods.readyInitialize(widget);
                }
                else if (data && 
                        !data.$$initialize &&
                        widgetMethods &&
                        jQuery.isFunction(widgetMethods.onmessage)) {
                        // if the widget itself has a special message handler,
                        // forward the message.
                        data = widgetMethods.onmessage(data, widget);
                }
                // This is requied to use the default handler for the remainder of the message.
                return data;
            };
        }
    });
})()

