﻿function makeAbsolute(attrName, obj, baseUrl) {
    var href = $(obj).attr(attrName).substring(0, 4);
    if (href == "mail" || href == "http" || href == "#")
        return;
    var url = baseUrl + $(obj).attr(attrName);
    $(obj).attr(attrName, url);
}

function makeImagesLinksAboslute(ctx, baseUrl) { 
   $('a',ctx).each(function(){ 
      makeAbsolute('href',$(this), baseUrl);
   });
   $('img', ctx).each(function() {
       makeAbsolute('src', $(this), baseUrl);
   });
}
function showPopup(popupInfo, callback) {
    var mask = $('<div/>');
    var box = $('<div/>');
    var popupText = popupInfo.Html;
    box.html(popupText);

    function setMaskSize() {
        //Get the screen height and width
        var maskHeight = $(window).height();
        var maskWidth = $(window).width();
        //Set height and width to mask to fill up the whole screen
        mask.css({ 'height': maskHeight, 'width': maskWidth });
    }
    function closePopup() {
        box.hide();
    }

    //update urls
    box.find("a").each(function() {
        makeAbsolute('href', $(this), popupInfo.AssetRoot);
    });
    box.find("img").each(function() {
        makeAbsolute('src', $(this), popupInfo.AssetRoot);
    });

    /* add mask */
    mask = $("<div/>").css({
        'position': 'absolute',
        'top': '0',
        'left': ' 0',
        'z-index': '9000',
        'background-color': '#000',
        'display': 'none'
    });
    mask.click(function() {
        closePopup();
    });
    box.find('.vc-invite-close').click(function() {
        closePopup();
    });

    box.find('a.vc-invite-link').each(function() {
        $(this).click(function() {
            closePopup();
            return false;
        });
    });
    box.find("div.vc-invite-window").each(function() {
        $(this).css({
            "position": "absolute",
            "left": "50%",
            "top": "50%",
            "overflow": "visible",
            "z-index": "9999",
            "padding": "0px"
        });
        var popupWidth = parseInt($(this).css("width").replace('px', ''));
        $(this).css("margin-left", -popupWidth / 2);
        var popupHeight = parseInt($(this).css("height").replace('px', ''));
        $(this).css("margin-top", -popupHeight / 2);   
    });
    box.find('.vc-invite-window .language').click(function(e) {
        $(".vc-invite-window").toggle();
        return false;
    });

    setMaskSize();
    $(window).resize(function() {
        setMaskSize();
    });
    box.append(mask);
    jQuery("body").append(box);
    
    //transition effect
    box.fadeIn(1000);   
    mask.fadeIn(250);
    mask.fadeTo("slow", 0.8);
    //transition effect
    if (callback) {
        callback();
    }
    return { box: box, mask: mask };
}

$(document).ready(function() { 
$('#main-column table tr:even').addClass("table-row-even");
$('#main-column table tr:odd').addClass("table-row-odd");
});
