﻿// when the DOM has loaded
var modalWindow = {
    parent: "body",
    windowId: null,
    content: null,
    width: null,
    height: null,
    close: function() {
        $(".modal-window").remove();
        $(".modalshadow").remove();
        $(".modal-overlay").remove();
    },
    open: function() {
        var modal = "";
        modal += "<div class=\"modal-overlay\"></div>";
        modal += "<div class=\"modalshadow\" style=\"left:" + (screen.width - this.width) / 2 + "px;\">";
        modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\ style=\"z-index:999999;\">";
        modal += this.content;
        modal += "</div>";
        modal += "</div>";
        $(this.parent).append(modal);
        $(".modal-window").prepend("<a class=\"close-window linkPlain\" style=\"float:right;margin:10px 10px 0 0;\" ><img src=\"https://resource.bmwusa.com/image_30976237-adb0-468c-b162-d0103b627bb3.arox\"></a>");
        //$(".modal-window").append("<a class=\"close-window linkPlain\" style=\"float:left;margin:-30px 10px 10px 20px;width:100px;\" >Back to homepage</a>");
        $(".close-window").click(function() { modalWindow.close(); });
    }

};

var openMyModal = function(source) {
    modalWindow.windowId = "myModal";
    modalWindow.width = 974;
    modalWindow.height = 536;
    modalWindow.content = "<iframe width='954' height='510' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'></iframe>";
    modalWindow.open();

};


var closeModal = function() {
    $(".modal-window").remove();
    $(".modal-overlay").remove();
}





