﻿function loadThumbnails(param)
{
    AjaxThumbnails.Callback(param);
}

function toggle_image_dialog()
{
    if (dlgImage.IsShowing)
        dlgImage.Hide();
    else
        dlgImage.Show();
}

function GetWindowHeight()
{
    return (typeof (window.innerHeight) == 'number') ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight;
}

function GetWindowWidth()
{
    return (typeof (window.innerWidth) == 'number') ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.clientWidth;
}

function ShowImage(param)
{
    var window_height = GetWindowHeight();
    var window_width = GetWindowWidth();
    var scroll_pos = getClientScrollPos();

    AjaxImage.Callback('0' + ',' + param + ',' + scroll_pos.Left + ',' + scroll_pos.Top + ',' + window_height + ',' + window_width);

    dlgImage.Dialog.style.width = "auto";
    dlgImage.Dialog.style.height = "auto";

    dlgImage.Show();
}


function getClientScrollPos()
{
    var left = filterResults((window.pageXOffset ? window.pageXOffset : 0), (document.documentElement ? document.documentElement.scrollLeft : 0), (document.body ? document.body.scrollLeft : 0));
    var top = filterResults((window.pageYOffset ? window.pageYOffset : 0), (document.documentElement ? document.documentElement.scrollTop : 0), (document.body ? document.body.scrollTop : 0));
    return { Left: left, Top: top }
}

function filterResults(win, ele, body)
{
    var result = win ? win : 0;
    if (ele && (!result || (result > ele)))
        result = ele;
    return body && (!result || (result > body)) ? body : result;
}

function ChangeImage(current, move)
{
    var window_height = GetWindowHeight();
    var window_width = GetWindowWidth();
    var scroll_pos = getClientScrollPos();

    AjaxImage.Callback(move + ',' + current + ',' + scroll_pos.Left + ',' + scroll_pos.Top + ',' + window_height + ',' + window_width);

    dlgImage.Dialog.style.width = "auto";
    dlgImage.Dialog.style.height = "auto";

    dlgImage.Show();
}