
$(document).ready(function () {
    $('<div class="sftOverlay" id="idSftOverlay"><div class="sftclose"><img class="sftclose" src="image/popup/close.gif" /></div><div class="sftOverlayContent"><iframe src="" frameborder="0"> </iframe></div></div>').appendTo('body');
    if (window.location.href.indexOf('/ms.help?') >= 0) {
        // fix close button image 
        var s = $("#Softelvdm_ImagePath").attr("src");
        var p = s.substring(0, s.indexOf(';') + 1);
        $("img.sftclose").attr("src", p + '/image/popup/close.gif');
        // fix area hrefs in V3
        var topic = $("#Softelvdm_TopicNameV3")[0];
        var thisUrl = topic.href;
        var thisTopic = topic.innerText;
        var reg = new RegExp('&id=' + thisTopic, "i");
        $("area").each(function () {
            var newUrl = $(this).attr("href");
            var match = newUrl.match(/\?Id=[^&]*/i);
            if (match != null) {
                var newTopic = match[0].substring(4);
                newUrl = thisUrl.replace(reg, '&id=' + newTopic);
                $(this).attr("href", newUrl);
            }
        });
    }
    var trigger = '';
    var ovl = $("#idSftOverlay").overlay({// popups
        api: true, top: 'center', speed: 'fast', close: 'sftclose', closeonclick: true,
        //expose: { color: '#555', opacity: 0.9, loadSpeed: 'fast' },
        onBeforeLoad: function () {
            var wrap = this.getContent().find(".sftOverlayContent");
            var url = $(trigger).attr("href");
            if (window.location.href.indexOf('/ms.help?') >= 0) {// use embedded=true for popups in V3
                if (url.indexOf('#') >= 0)
                    url = url.replace(/#/, '&embedded=true#');
                else
                    url += '&embedded=true';
            }
            $('iframe', wrap).first().attr('src', url);
        }
    });
    $("a[rel],area[rel]").click(function (ev) {
        ev.stopImmediatePropagation(); ev.preventDefault();
        trigger = this;
        ovl.load();
    });
    $(".sftclose").click(function () {
        ovl.close();
    });
});

