var OrderPlugin = new (function() {
    this.inIframe = false;
    this.getButtonIframeCSS = function(buttonType) {
        var width, height;
        if (buttonType.indexOf("-large") > -1) {
            height = 60;
            width = 199;
        } else {
            height = 32;
            width = 98;
        }
        if (buttonType.indexOf("-logo") > -1 && buttonType.indexOf("-medium") > -1) {
            height += 6;
            width += 26;
        }

        if (buttonType.indexOf("-powered") > -1) {
            height = 81;
            width = 200;
        }
        return "width: " + width + "px; "
            + "height: " + height + "px; "
            + "overflow: none; "
            + "border:none; ";
    };

    this.initializeOrdering = function(options) {
        this.insertButtonIframe(options);
    };

    this.insertButtonIframe = function(options) {
        var container = document.getElementById(options.containerId);
        if (!options.restaurantId) {
            throw "Missing required parameter restaurantId";
        }
        var iframe = document.createElement("iframe");
        iframe.setAttribute("src", options.iframeURL);
        iframe.style.cssText = OrderPlugin.getButtonIframeCSS(options.buttonType);
        iframe.onload = function() {
            iframe.setAttribute("scrolling", "no");
            if (window.self !== window.top) {
                OrderPlugin.inIframe = true;
                iframe.setHeight = 'auto';
            }
            options.resizeElements = [ iframe ];
        };
        container.appendChild(iframe);
    };
})();

var OrderPluginOptions = {
    restaurantId: 'null',
    containerId: 'order-plugin',
    iframeURL: 'https://eatstreet.com/OrderNowButton?button_type=&restaurant_id=null',
    buttonType : ''
};
if (window.addEventListener) {
    window.addEventListener("load", function() {
        OrderPlugin.initializeOrdering(OrderPluginOptions);
    }, false);
} else {
    window.attachEvent("onload", function() {
        OrderPlugin.initializeOrdering(OrderPluginOptions);
    });
}