﻿function hideLocationList(itemID) {
    var element = jQuery("#" + itemID);
    if (element != null) {
        element.hide();
    };
};


function showLocationList(itemID) {
    var element = jQuery("#" + itemID);
    if (element != null) {
        element.show();
    };

};

//ImagePopup
(function ($) {

    var methods = {
        init: function (options) {

            var settings = {
                ImageToLoadSelector: '#fakeSelector',
                ShowPrintButton: false
            };

            //options
            if (options) {
                jQuery.extend(settings, options);
            }

            $this = jQuery(this);
            $this.each( function () {
                var $this = jQuery(this);
                $this.overlay({
                    fixed: false,
                    onBeforeLoad: function () 
                    {
                        jQuery(settings.ImageToLoadSelector).hide();
                        jQuery.ajax("/Functions/MediaGallery/MediaService.asmx/GetImageView", {
                            data: "{'imageId':'" + $this.attr('alt') + "'}",
                            type: 'POST',
                            dataType: 'JSON',
                            contentType: 'application/json; charset=utf-8',
                            success: function (msg) 
                            {
                                var imageToLoad = jQuery(settings.ImageToLoadSelector);
                                imageToLoad.show();
                                imageToLoad.attr('src', msg.d);
                            },
                            error: function (msg) 
                            {
                            }
                        });
                        if (settings.ShowPrintButton)
                        {
                            // Remove old button, if available
                            var imageToLoad = jQuery(settings.ImageToLoadSelector);
                            imageToLoad.parent().find('.Print').remove();

                            jQuery.ajax("/Functions/MediaGallery/MediaService.asmx/GetImageSource", {
                                data: "{'imageId':'" + $this.attr('alt') + "'}",
                                type: 'POST',
                                dataType: 'JSON',
                                contentType: 'application/json; charset=utf-8',
                                success: function (msg) 
                                {
                                    var printElement = '<div class="Print"><a class="iconLink printLink fr" href="' + msg.d + '">Печать</a></div>';
                                    imageToLoad.after(printElement);
                                },
                                error: function (msg) 
                                {
                                }
                            });
                        }
                    }
                });
            });
        }
    };

    $.fn.ImagePopup = function (method) {
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.ImagePopup');
        }

    };

})(jQuery);
