﻿var WebToImage = {};

WebToImage.EscapeHTML = function(str)
{
    var div = document.createElement('div');
    var text = document.createTextNode(str);
    div.appendChild(text);
    return div.innerHTML;
}

WebToImage.CreateThumbnail = function(id, size, url, showCode)
{
    var html = '';
    if (!url.match('^http'))
    {
        url = 'http://' + url;
    }
    if (showCode == null || showCode == '1') showCode = 1; else showCode = 0;
    var captureUrl = '/Capture.ashx?size=' + size + '&url=' + escape(url);
    var anchor = '<a href="' + url + '" target="_blank" style="text-decoration: none;"><img src="' + location.protocol + '//' + location.host + captureUrl + '" alt="" /></a>';
    var display = (showCode ? '<div class="urlimagelink">' + WebToImage.EscapeHTML(anchor) + '</div><br/>' : '');
    html = display + '<div class="urlimage"><div class="loading">' + anchor + '</div></div>';
    $(id).html(html);
}

WebToImage.ShowPopup = function(itemId, popupId)
{
    var item = $(itemId);
    var popup = $(popupId);
    var cpos = $('#container').position();
    var pos = item.position();
    if (pos.left - cpos.left > 512)
    {
        pos.left -= 384;
    }
    popup.css({ 'top': pos.top + 18, 'left': pos.left + 20, 'display': 'block' });
}

WebToImage.HidePopup = function(popupId)
{
    $(popupId).css('display', 'none');
}

