﻿; if (!window.jqsDCCWMGSS) jqsDCCWMGSS = jQuery;
(function(jQuery) {
    MGSS = (function() {
        function LoadSlideShowSuccessCallback(result) {
            if (result != null || result != undefined) {
                DCCMGSS_SetConstants(result.ModuleId);
                DCCMGSS.totalPages = result.TotalPages;
                var parentDiv = jQuery("#dvMainSldeShowContainer_" + result.ModuleId);
                var ulGallery = parentDiv.find("*[id*=gallery]");
                var strImd = DCCMGSS.StrSlideTemplate.replace(/WIDTH/g, DCCMGSS.SlideShowWidth).replace(/HEIGHT/g, DCCMGSS.SlideShowHeight).replace(/MID/g, DCCMGSS.ModuleId);
                if (result.ImageList.length > 0) {
                    jQuery(result.ImageList).each(function(i) {
                        ulGallery.append(strImd.replace(/IMGSRC/g, DCCMGSS.strModulePath + 'ImageHandler.ashx?image=' + this.MediaSrc + '&ot=2&pid=' + DCCMGSS.PortalId + '&mid=' + result.ModuleId)
                .replace(/TITLE/g, this.MediaTitle).replace(/DESCRIPTION/g, this.MediaDescription));
                    });
                    DCCMGSS.SlideShow.isComplete = (result.ImageList.length == 0);
                    DCCMGSS.SlideShow.ulList = ulGallery;
                    DCCMGSS.SlideShow.init();
                }
            }
        }
        function AddSlidesSuccessCallback(result) {
            if (result != null || result != undefined) {
                DCCMGSS = DCCMGSS_SetConstants(result.ModuleId);
                DCCMGSS.totalPages = result.TotalPages;
                var parentDiv = jQuery("#dvMainSldeShowContainer_" + result.ModuleId);
                var ulGallery = jQuery("<ul id='gallery'>"); // parentDiv.find("*[id*=gallery]");
                var strImd = DCCMGSS.StrSlideTemplate.replace(/WIDTH/g, DCCMGSS.SlideShowWidth).replace(/HEIGHT/g, DCCMGSS.SlideShowHeight).replace(/MID/g, DCCMGSS.ModuleId);
                jQuery(result.ImageList).each(function(i) {
                    ulGallery.append(strImd.replace(/IMGSRC/g, DCCMGSS.strModulePath + 'ImageHandler.ashx?image=' + this.MediaSrc + '&ot=2&pid=' + DCCMGSS.PortalId + '&mid=' + result.ModuleId)
                .replace(/TITLE/g, this.MediaTitle).replace(/DESCRIPTION/g, this.MediaDescription));
                });
                DCCMGSS.SlideShow.isComplete = (result.ImageList.length == 0);
                if (!DCCMGSS.SlideShow.isComplete) {
                    ulGallery.hide();
                    DCCMGSS.SlideShow.createImageList(ulGallery);
                }                
            }
        }
        return objSlideShowAPI = {
            InitSlideShow: function(moduleId, galleryId, folderId) {
                DCCMGSS_SetConstants(moduleId);
                DCCMGSS.PageNo = 1;
                var argument = {
                    PortalId: DCCMGSS.PortalId,
                    ModuleId: moduleId,
                    GalleryId: galleryId,
                    FolderId: folderId,
                    PageNo: DCCMGSS.PageNo,
                    PageSize: DCCMGSS.PageSize
                };
                DNNCentric.MediaGallerySlideShow.SlideShowWebService.GetImages(argument, LoadSlideShowSuccessCallback, null);
            },
            AddSlides: function(moduleId, galleryId, folderId, pageNo) {
                DCCMGSS_SetConstants(moduleId);
                var argument = {
                    PortalId: DCCMGSS.PortalId,
                    ModuleId: moduleId,
                    GalleryId: galleryId,
                    FolderId: folderId,
                    PageNo: pageNo,
                    PageSize: DCCMGSS.PageSize
                };
                DNNCentric.MediaGallerySlideShow.SlideShowWebService.GetImages(argument, AddSlidesSuccessCallback, null);
            }
        }
    })();
})(jqsDCCWMGSS);
