﻿if (!window.jqsDCCJMG) jqsDCCJMG = jQuery;
function _getScroll() {
    if (self.pageYOffset) {
        return { scrollTop: self.pageYOffset, scrollLeft: self.pageXOffset };
    } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
        return { scrollTop: document.documentElement.scrollTop, scrollLeft: document.documentElement.scrollLeft };
    } else if (document.body) {// all other Explorers
        return { scrollTop: document.body.scrollTop, scrollLeft: document.body.scrollLeft };
    };
};
function saveScroll() {
    restoreScroll.sScroll = _getScroll();
}
function restoreScroll() {
    if (restoreScroll.sScroll) {
        var sScroll = restoreScroll.sScroll.scrollTop;
        if (sScroll > 0) {
            if (document.documentElement)
                document.documentElement.scrollTop = sScroll;
            if (document.documentElement.scrollTop != sScroll && document.body) {
                if (window.navigator.appName == 'Netscape')
                    window.scroll(0, sScroll);
                else
                    document.body.scrollTop = sScroll;
            }
            else {
                window.scroll(0, sScroll);
            }
        }
    }
}
function WEBGetMediaList(_tabID, _PortalId, _ModuleId, _GalleryId, _FolderId, _UserId, _PageNo, _PageSize, _ThumbSortBy, _Specificuserdesc, _Specificuserflag) {
    jqsDCCJMG('div#' + _ModuleId + '_MediaGallery').find('ul.dcc_gallery_medialist').html('').addClass("dcc_gallery_mg_ajaxloader");
    DNNCentric.JMediaGallery.MediaGalleryController.GetAllMediaInfo(_tabID, _PortalId, _ModuleId, _GalleryId, _FolderId, _UserId, _PageNo, _PageSize, _ThumbSortBy, _Specificuserdesc, _Specificuserflag, SucceededCallbackGetMediaList, FailedCallback);
}
function WEBGetSubGalleriesList(_PortalId, _ModuleId, _GalleryId, _FolderId) {
    jqsDCCJMG('div#' + _ModuleId + '_MediaGallery').find('ul.dcc_gallery_subgallerylist').html('');
    DNNCentric.JMediaGallery.MediaGalleryController.GetAllSubGalleries(_PortalId, _ModuleId, _GalleryId, _FolderId, SucceededCallbackGetSubGalleriesList, FailedCallback);
}
function SucceededCallbackGetSubGalleriesList(result) {
    if ((result != null)) {
        DCCJMG_SetConstants(result.ModuleId);
        ShowSubGalleryList(result, DCCJMG.thumbnailWidth, DCCJMG.thumbnailHeight);
        restoreScroll();
    }
}
function SucceededCallbackGetMediaList(result, eventArgs) {
    if ((result != null)) {
        thumbShown = result.AlMediaList.length;
        DCCJMG_SetConstants(result.ModuleId);
        ShowMediaList(result, DCCJMG.thumbnailWidth, DCCJMG.thumbnailHeight);
        restoreScroll();
    }
}
function FailedCallback(error) {
    //alert("Failed: " + error._message.toString());
}
function SucceededCallbackWithContext(result, userContext, methodName) {
    if (userContext == "XmlDocument") {
        GetWebServiceXMLResult(result);
    }
}
function WEBDeleteMedia(_PortalId, _ModuleId, _MediaId) {
    DNNCentric.JMediaGallery.MediaGalleryController.DeleteMedia(_PortalId, _ModuleId, _MediaId, SucceededCallbackModMedia, FailedCallback);
}
function WEBGetMedia(_PortalId, _ModuleId, _MediaId) {
    DNNCentric.JMediaGallery.MediaGalleryController.GetMediaInfo(_PortalId, _ModuleId, _MediaId, SucceededCallbackGetMedia, FailedCallback);
}
function SucceededCallbackGetMedia(result, eventArgs) {
    if ((result != null)) {
        var dialogEditMedia = jqsDCCJMG('#' + result.ModuleId + '_dialogEditMedia');
        dialogEditMedia.find('#' + result.ModuleId + '_title').val(result.InfoMedia.MediaTitle);
        dialogEditMedia.find('#' + result.ModuleId + '_description').val(result.InfoMedia.MediaDescription);
        dialogEditMedia.find("#lblDeleteBoxCharCount").html(DCCJMG.maxCharCount - result.InfoMedia.MediaDescription.length);
        if (result.InfoMedia.MediaType != 1) {
            dialogEditMedia.find('#' + result.ModuleId + '_src').css('display', 'inline');
            dialogEditMedia.find("#lblMediaSrc").css('display', 'inline');
            dialogEditMedia.find('#' + result.ModuleId + '_src').val(result.InfoMedia.MediaSrc);
        }
        else {
            dialogEditMedia.find('#' + result.ModuleId + '_src').val(null);
            dialogEditMedia.find("#lblMediaSrc").css('display', 'none');
            dialogEditMedia.find('#' + result.ModuleId + '_src').css('display', 'none');
        }
        dialogEditMedia.find("#chkGalleryCover")[0].checked = result.IsAlbumCover;
        dialogEditMedia.find("select[id*=ddlGalerry]").find('option').each(function() {
            this.selected = (this.value == result.InfoMedia.GalleryId);
        });
        if (DCCJMG.IsLinkedGallery) {
            dialogEditMedia.find("select[id*=ddlGalerry]").find('option').attr('disabled', 'disabled');
        }
    }
}
function WEBSaveMedia(_PortalId, _ModuleId, _MediaId, _MediaTitle, _MediaDescription, _folderId, _isAlbumCover, _MediaSrc) {
    if (validEditVideoSource(_ModuleId) == false) {
        return false;
    }
    else {
        DNNCentric.JMediaGallery.MediaGalleryController.SaveMediaInfo(_PortalId, _ModuleId, _MediaId, _MediaTitle, _MediaDescription, _folderId, _isAlbumCover, _MediaSrc, SucceededCallbackModMedia, FailedCallback);
        return true;
    }
}
function validEditVideoSource(modid) {
    var extVideoArray = new Array("flv", "mp4", "3gp", "f4v");
    var dialogEditMedia = jqsDCCJMG('#' + modid + '_dialogEditMedia');
    var url = dialogEditMedia.find('#' + modid + '_src').val();
    url = url.trim().toLowerCase();
    //To Check Video or Image Gallery
    var gallerytype = jQuery(dialogEditMedia.find("select[id*=ddlGalerry]")).find('option').filter(':selected').val();
    var arrmetype1 = gallerytype.split(",");
    if (arrmetype1[2] == 2 && dialogEditMedia.find('#' + modid + '_src')[0].style.display == 'none') {
        alert("Image Media Not Allowed in Video Type Gallery");
        return false;
    }
    if (arrmetype1[2] == 1 && dialogEditMedia.find('#' + modid + '_src')[0].style.display == 'inline') {
        alert("Video Media Not Allowed in Image Type Gallery");
        return false;
    }
    //
    if (url.length > 0 && dialogEditMedia.find('#' + modid + '_src')[0].style.display != 'none') {
        if (url.indexOf('youtube.') != -1 || url.indexOf('metacafe.') != -1 || url.indexOf('vimeo.') != -1) {
            if (url.indexOf("<object") == -1 && url.indexOf("<embed") == -1) {
                alert("Not a valid Video link");
                return false;
            }
        }
        else if (url.indexOf("http") == 0 || url.indexOf("rtmp") == 0) {
            if (url.indexOf("http") == 0) {
                var fileSupported = false;
                var ext = url.slice(url.lastIndexOf(".") + 1);
                for (var i = 0; i < extVideoArray.length; i++) {
                    if (extVideoArray[i] == ext.toLowerCase()) {
                        fileSupported = true;
                        break;
                    }
                }
                if (!fileSupported) {
                    alert("Not a valid Video File Format");
                    return false;
                }
            }
        }
        else {
            alert("Not a valid Video File link Format");
            return false;
        }
    }
}

function SucceededCallbackModMedia(result, eventArgs) {
    if ((result != null)) {
        jqsDCCJMG(document).ready(function() {
            DCCJMG_SetConstants(result.ModuleId);
            if (thumbShown == 1) {
                if (DCCJMG.PageNo > 1)
                    DCCJMG.PageNo--;
                else
                    DCCJMG.PageNo = 1;
            }
            WEBGetMediaList(DCCJMG.TabId, result.PortalId, result.ModuleId, DCCJMG.galleryId, parseInt(DCCJMG.folderId), DCCJMG.iThisUserID, DCCJMG.PageNo, DCCJMG.pageSize, DCCJMG.thumbSortBy, DCCJMG.specificuserdesc, DCCJMG.specificuserflag);
        });
    }
}
function rPosition(element, mouseX, mouseY) {
    var offset = jqsDCCJMG(element).offset();
    var x = mouseX - offset.left;
    var y = mouseY - offset.top;
    return { 'x': x, 'y': y };
}
function LoadMG(obj) {
    saveScroll();
    var obj = jqsDCCJMG(obj);
    var moduleId = parseInt(obj.attr("mid"));
    DCCJMG_SetConstants(moduleId);
    var galleryId = parseInt(obj.attr("galleryid"));
    var folderId = parseInt(obj.attr("folderid"));
    if (folderId == DCCJMG.folderId) return false;

    //remove breadcrumb nodes
    var parentTD = obj.parents("td[id*=tdBreadCurumb]");
    if (parentTD.length > 0) {
        var anchor = parentTD.find("a[folderid='" + folderId + "'");
        obj.remove();
    }
    if ($('.pp_loaderIcon') != null)
        $('.pp_loaderIcon').show();
    //jqsDCCJMG('div#' + moduleId + '_MediaGallery').find('ul.dcc_gallery_medialist').html('').addClass("dcc_gallery_mg_ajaxloader");
    MediaGallery.LoadSubGalleries(moduleId, galleryId, folderId);
    MediaGallery.LoadMedia(moduleId, galleryId, folderId, 1);
    DCCJMG.folderId = folderId;
    return false;
}
function ShowSubGalleryList(subGallery, thmbnlWidth, thmbnlHeight) {
    DCCJMG_SetConstants(subGallery.ModuleId);
    var path = "path";
    var strsubGalleryItemList = "";
    var parentDiv = jqsDCCJMG('div#' + subGallery.ModuleId + '_MediaGallery');
    if(subGallery.BreadCrumb.length>0)
    parentDiv.find('#tlBreadCurumb').removeClass('dcc_gallery_BreadCurumbtable');
    parentDiv.find("td[id=tdBreadCurumb]").html('');
    for (var i = 0; i < subGallery.BreadCrumb.length; i++) {
        var bcFolder = subGallery.BreadCrumb[i];
        var spacer = " <span> &gt;  </span>";
        if (i == subGallery.BreadCrumb.length - 1) {
            var spacer = "";
        }
        parentDiv.find("td[id=tdBreadCurumb]").append(jqsDCCJMG("<a href='#' mid=\"" + subGallery.ModuleId + "\" galleryid=\"" + DCCJMG.galleryId + "\" folderid=\"" + bcFolder.FolderId + "\">" + bcFolder.FolderName + "</a>").click(function() { return LoadMG(this); })).append(spacer);
    }
    parentDiv.find("td[id=tdBreadCurumb]").find("a,span").css("color", '#' + DCCJMG.strTextColor);
    var ulSubGallery = parentDiv.find('ul.dcc_gallery_subgallerylist');
    ulSubGallery.html("");
    jqsDCCJMG(ulSubGallery).removeClass("dcc_gallery_mg_ajaxloader");
    if (subGallery.AlMediaList.length > 0) {
        jqsDCCJMG.each(subGallery.AlMediaList, function() {
            var tempLi = DCCJMG.StrTemplateSubGalleryThumbNail.replace(/MID/g, subGallery.ModuleId).replace(/SUBGALLERYIMAGESOURCE/g, DCCJMG.strModulePath + 'Thumbnail.ashx?gid=' + this.GalleryId + '&fid=' + this.FolderId + '&sgname=' + this.FolderName + '&ot=5&pid=' + DCCJMG.PortalId + '&mid=' + DCCJMG.ModuleId)
                .replace(/SUBGALLERYSOURCE/g, "#").replace(/GALLERYID/g, this.GalleryId).replace(/FOLDERID/g, this.FolderId).replace(/TOOLTIP/g, this.Tooltip);
            strsubGalleryItemList += tempLi;
        });
        ulSubGallery.append(strsubGalleryItemList);
        ulSubGallery.find("li").width(DCCJMG.SubGalleryThumbnailWidth).css("margin", DCCJMG.strSubGalleryMarginBetweenThumbnails + "px");
        if (DCCJMG.DisableRightClickOnThumb) {
            ulSubGallery.find("li").bind("contextmenu", function(e) {
                e.preventDefault();
            });
        }
        var dvToolTip = jqsDCCJMG("#dvToolTip");
        var isMouseOver = null;
        var timeoutID = 0;
        if (subGallery.ToolTipEnabled) {
            ulSubGallery.find("img").bind("mouseenter", function(e) {
                isMouseOver = true;
                var ev = e || window.event;
                var obj = ev.target || ev.srcElement;
                if (!dvToolTip.divGalleryContainer)
                    dvToolTip.divGalleryContainer = jQuery(".dcc_gallery_container");
                dvToolTip.html(jqsDCCJMG(obj).attr("tooltip"));
                if (jqsDCCJMG(obj).attr("tooltip") == '') return;
                dvToolTip.css("position", "absolute").css("left", ev.pageX + 15).css("top", ev.pageY + 15);
                timeoutID = setTimeout('jqsDCCJMG("#dvToolTip").show()', 500);
                jqsDCCJMG(this).mousemove(function(e) {
                    var ev = e || window.event;
                    var obj = ev.target || ev.srcElement;
                    if (dvToolTip.divGalleryContainer) {
                        var pos = rPosition(dvToolTip.divGalleryContainer, ev.pageX, ev.pageY);
                        dvToolTip.css("left", pos.x + 15).css("top", pos.y + 15);
                    }
                })
            }).mouseout(function(e) {
                isMouseOver = false;
                clearTimeout(timeoutID);
                dvToolTip.hide();
            });
        }

        ulSubGallery.find("img,td[id=tdBreadCurumb]a").click(function() {
            isMouseOver = false;
            clearTimeout(timeoutID);
            dvToolTip.hide();
            return LoadMG(this);
        });
    }
    else {
        jqsDCCJMG(ulSubGallery).html("");
    }
}
function ShowMediaList(mediaData, thmbnlWidth, thmbnlHeight) {
    DCCJMG_SetConstants(mediaData.ModuleId);
    var strMediaItemList = "";
    var ULMedia = jqsDCCJMG('div#' + mediaData.ModuleId + '_MediaGallery').find('ul.dcc_gallery_medialist');
    ULMedia.html("");
    jqsDCCJMG(ULMedia).removeClass("dcc_gallery_mg_ajaxloader");
    if (mediaData.AlMediaList.length > 0) {
        jqsDCCJMG.each(mediaData.AlMediaList, function() {
            var objMedia = this;
            objMediaTemp = new Media(objMedia);
            objMediaItemTemp = new MediaItem(objMediaTemp, thmbnlWidth, thmbnlHeight, mediaData.ModuleId);
            strMediaItemList = strMediaItemList + objMediaItemTemp.getMediaItem();
        });

        jqsDCCJMG(ULMedia).append(strMediaItemList);
        jqsDCCJMG(ULMedia).find("li").width(parseInt(thmbnlWidth)).css("padding", DCCJMG.strThumbBorderWidth + "px").css("margin", DCCJMG.strMarginBetweenThumbnails + "px");
        if (DCCJMG.strThumbnailContainerColor != "") {
            jqsDCCJMG(ULMedia).find("li").css("background-color", '#' + DCCJMG.strThumbnailContainerColor);
        }
        jqsDCCJMG(ULMedia).find("li").css("font-family", 'Verdana');
        if (DCCJMG.strThumbBorderColor != "") {
            jqsDCCJMG(ULMedia).find("li").css("border", '1px solid #' + DCCJMG.strThumbBorderColor);
        }
        if (DCCJMG.DisableRightClickOnThumb) {
            jqsDCCJMG(ULMedia).find("li").bind("contextmenu", function(e) {
                e.preventDefault();
            });
        }
        var dvToolTip = jqsDCCJMG("#dvToolTip");
        var isMouseOver = null;
        var timeoutID = 0;
        if (mediaData.ToolTipEnabled) {
            jqsDCCJMG(ULMedia).find("img").bind("mouseenter", function(e) {
                isMouseOver = true;
                var ev = e || window.event;
                var obj = ev.target || ev.srcElement;
                if (!dvToolTip.divGalleryContainer)
                    dvToolTip.divGalleryContainer = jQuery(".dcc_gallery_container");
                dvToolTip.html(jqsDCCJMG(obj).attr("tooltip"));
                if (jqsDCCJMG(obj).attr("tooltip") == '') return;
                dvToolTip.css("position", "absolute").css("left", ev.pageX + 15).css("top", ev.pageY + 15);
                timeoutID = setTimeout('jqsDCCJMG("#dvToolTip").show()', 500);
                jqsDCCJMG(this).mousemove(function(e) {
                    var ev = e || window.event;
                    var obj = ev.target || ev.srcElement;
                    if (dvToolTip.divGalleryContainer) {
                        var pos = rPosition(dvToolTip.divGalleryContainer, ev.pageX, ev.pageY);
                        dvToolTip.css("left", pos.x + 15).css("top", pos.y + 15);
                    }
                })
            }).mouseout(function(e) {
                isMouseOver = false;
                clearTimeout(timeoutID);
                dvToolTip.hide();
            });
        }

        jqsDCCJMG(ULMedia).find("li").find("div#gallerymain").css({
            'width': parseInt(thmbnlWidth) + 'px',
            'float': 'left',
            'position': 'relative'

        });

        //        jqsDCCJMG.each(jqsDCCJMG(ULMedia).find("li").find("div#gallerymain"), function() {
        //            this.style.position ='relative';
        //        });
        //To show overlay at thumbnail
        if (DCCJMG.strThumbshowoverlay != 'False') {
            jqsDCCJMG(ULMedia).find("li").find("span#toverlaytitle").css({
                'opacity': DCCJMG.strThumboverlayTransparency,
                'bottom': '0',
                'float': 'left',
                'font-family': 'Verdana,Arial,Helvetica,sans-serif',
                'font-size': '10px',
                'left': '0',
                'line-height': 'normal',
                'padding-bottom': '2px',
                'padding-top': '2px',
                'position': 'absolute',
                'right': '0',
                'text-align': 'center',
                'white-space': 'normal',
                'width': '100%',
                'overflow': 'hidden'
            });
        }
        else {
            jqsDCCJMG(ULMedia).find("li").find("span#toverlaytitle").css({
                'display': 'none'
            });
        }
        jqsDCCJMG(ULMedia).find("li").find("span#overlaydesc").css({
            'font-size': '11px',
            'font-style': 'italic'
        });
        jqsDCCJMG(ULMedia).find("li").find("span#overlaytitle").css({
            'font-size': '12px'
        });

        if (DCCJMG.strThumboverlayBackcolor != "") {
            jqsDCCJMG(ULMedia).find("li").find("span#toverlaytitle").css({
                'background-color': '#' + DCCJMG.strThumboverlayBackcolor
            });
        }
        if (DCCJMG.strThumboverlayForecolor != "") {
            jqsDCCJMG(ULMedia).find("li").find("span#toverlaytitle").css({
                'color': '#' + DCCJMG.strThumboverlayForecolor
            });
        }
        if (DCCJMG.strThumboverlayPosition != "OnImage") {
            jqsDCCJMG(ULMedia).find("li").find("span#toverlaytitle").css({
                'position': 'relative'
            });
            jqsDCCJMG(ULMedia).find("li").find("div#dadmin").css({

                'position': 'relative'
            });
        }

        if (DCCJMG.strThumbshowoverlaydesc == 'False') {
            jqsDCCJMG(ULMedia).find("li").find("span#overlaydesc").css({
                'display': 'none'
            });
        }

        //if admin then attaching the jquery ui to it
        if (mediaData.ShowEdit) {
            //attaching the jqui sortable
            //jqsDCCJMG('div#' + mediaData.ModuleId + '_MediaGallery').find("ul.dcc_gallery_medialist").sortable();
            jqsDCCJMG('div#' + mediaData.ModuleId + '_MediaGallery').find("ul.dcc_gallery_medialist").disableSelection();
            //attaching the jqui dialogs for delete
            jqsDCCJMG('#' + mediaData.ModuleId + '_dialogDeleteMedia').dialog({
                autoOpen: false,
                bgiframe: true,
                resizable: false,
                height: 150,
                modal: true,
                overlay: {
                    backgroundColor: '#000',
                    opacity: 0.8
                },
                buttons: {
                    Cancel: function() {
                        jqsDCCJMG(this).dialog('close');
                    },
                    'Delete Media': function() {
                        jqsDCCJMG(this).dialog('close');
                        WEBDeleteMedia(mediaData.PortalId, mediaData.ModuleId, DCCJMG.iMediaIdToMod);
                    }
                }
            });
            //attaching the jqui dialog for edit
            var parentDiv = jqsDCCJMG('#' + mediaData.ModuleId + '_dialogEditMedia');
            var title = parentDiv.find('#' + mediaData.ModuleId + '_title'),
            ddlParentGallery = parentDiv.find('*[id*=ddlGalerry]'),
			    description = parentDiv.find('#' + mediaData.ModuleId + '_description'),
			    allFields = jqsDCCJMG([]).add(title).add(description),
			    lblEditBoxTitleErrorMessage = parentDiv.find('#lblEditBoxTitleErrorMessage');
            var src = parentDiv.find('#' + mediaData.ModuleId + '_src');
            var chkGalleryCover = parentDiv.find("*[id*=chkGalleryCover]");
            function updateTips(t) {
                lblEditBoxTitleErrorMessage.html(t); //.effect("highlight", {}, 1500);
            }
            function checkLength(o, n, min, max) {
                if (o.val().length > max || o.val().length < min) {
                    jqsDCCJMG(o).css("border-color", "red");
                    updateTips("*");
                    return false;
                } else {
                    jqsDCCJMG(o).css("border-color", "gray");
                    updateTips("");
                    return true;
                }
            }
            function checkRegexp(o, regexp, n) {
                if (!(regexp.test(o.val()))) {
                    o.addClass('ui-state-error');
                    updateTips(n);
                    return false;
                } else {
                    return true;
                }
            }
            jqsDCCJMG('#' + mediaData.ModuleId + '_dialogEditMedia').dialog({
                autoOpen: false,
                bgiframe: true,
                height: 'auto',
                modal: true,
                overlay: {
                    backgroundColor: '#000',
                    opacity: 0.8
                },
                buttons: {
                    Cancel: function() {
                        jqsDCCJMG(this).find('#' + mediaData.ModuleId + '_title').css("border-color", "gray");
                        updateTips("");
                        jqsDCCJMG(this).dialog('close');
                    },
                    'Save': function() {
                        if (WEBSaveMedia(mediaData.PortalId, mediaData.ModuleId, DCCJMG.iMediaIdToMod, title.val(), description.val(), parseInt(ddlParentGallery.val().split(',')[1]), eval(chkGalleryCover.attr("checked")), src.val()))
                            jqsDCCJMG(this).dialog('close');
                    }
                },
                close: function() {
                    allFields.val('').removeClass('ui-state-error');
                }
            });
            jqsDCCJMG('div#' + mediaData.ModuleId + '_MediaGallery').find("#dialogDeleteSuccess").dialog({
                autoOpen: false,
                bgiframe: true,
                modal: true,
                buttons: {
                    Ok: function() {
                        jqsDCCJMG(this).dialog('close');
                    }
                }
            });
        }
        else {
            jqsDCCJMG('#' + mediaData.ModuleId + '_dialogEditMedia').hide();
            jqsDCCJMG('#' + mediaData.ModuleId + '_dialogDeleteMedia').hide();
        }
        //attaching the prettyphoto to the media
        jqsDCCJMG('div#' + mediaData.ModuleId + '_MediaGallery').find('.dcc_gallery_medialist a[rel^="prettyPhoto"]').prettyPhoto({
            animationSpeed: 'normal', /* fast/slow/normal */
            opacity: DCCJMG.strOverlayTransparency, /* Value between 0 and 1 */
            moduleId: mediaData.ModuleId,
            showTitle: true, /* true/false */
            allowresize: true, /* true/false */
            default_width: mediaData.PP_DefaultWidth,
            default_height: mediaData.PP_DefaultHeight,
            counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
            theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
            hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
            wmode: 'opaque', /* Set the flash wmode attribute */
            autoplay: true, /* Automatically start videos: True/False */
            modal: false /* If set to true, only the close button will close the window */
        });
        //jqsDCCJMG('a[rel^="prettyPhoto"]').prettyPhoto();
        if (mediaData.TotalPages > 1)
            handlePaging(mediaData.ModuleId, mediaData.PageNo, mediaData.TotalPages, 0);
        else
            handlePaging(mediaData.ModuleId, mediaData.PageNo, mediaData.TotalPages, 1);
    }
    else {
        //nothign to show
        //show msg
        //hidepager
        //jqsDCCJMG(ULMedia).html("<span style=\"text-decoration:none; color:#000000;\">No Media Found!</span>");
        if (mediaData.TotalPages > 1)
            handlePaging(mediaData.ModuleId, mediaData.PageNo, mediaData.TotalPages, 0);
        else
            handlePaging(mediaData.ModuleId, mediaData.PageNo, mediaData.TotalPages, 1);
    }
}

function Media(objMedia) {
    this.id = objMedia.MediaID;
    this.title = objMedia.MediaTitle;
    this.desc = objMedia.MediaDescription;
    if (objMedia.MediaType == 1)
        this.src = unescape(objMedia.MediaSrc);
    else
        this.src = objMedia.MediaSrc;
    this.MediaUrl = objMedia.MediaUrl;
    this.folder = objMedia.FolderID;
    this.type = objMedia.MediaType;
    this.filename = objMedia.MediaOriginalFileName;
    this.sortorder = objMedia.SortOrder;
    this.tooltip = objMedia.Tooltip;
    this.username = objMedia.UserName;
}
function UrlEncode(url) {
    url = url.replace(/\r\n/g, "\n");
    var utftext = "";

    for (var n = 0; n < url.length; n++) {

        var c = url.charCodeAt(n);

        if (c < 128) {
            utftext += String.fromCharCode(c);
        }
        else if ((c > 127) && (c < 2048)) {
            utftext += String.fromCharCode((c >> 6) | 192);
            utftext += String.fromCharCode((c & 63) | 128);
        }
        else {
            utftext += String.fromCharCode((c >> 12) | 224);
            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
            utftext += String.fromCharCode((c & 63) | 128);
        }

    }

    return utftext;
}
function MediaItem(media, prmthmbnlWidth, prmthmbnlHeight, modId) {
    this.id = media.id;
    this.title = media.title;
    this.description = media.desc
    this.sortorder = media.sortorder;
    this.url = media.src;
    this.MediaUrl = media.MediaUrl;
    this.type = media.type;
    this.src = DCCJMG.strMediaPath + media.src;
    this.path = media.src;
    //  if (objMedia.MediaType == 1)
    //      this.src = escape(objMedia.MediaSrc);
    //  else
    //      this.src = objMedia.MediaSrc;
    this.galleryId = eval(DCCJMG.galleryId);
    var strMediaTemplate = "<img src=\"MTHUMB\" mediaTitle=\"MTITLE\" mediaDesc=\"MDESC\"  width=\"" + prmthmbnlWidth + "px\" height=\"" + prmthmbnlHeight + "px\" style='border: 0px;' tooltip='TOOLTIP' mediaid=\"MEDIAID\" moduleid=\"MODULEID\" >";
    this.getMediaItem = function() {
        var strMedia = "";
        if (this.type == "1") {
            strMedia = strMediaTemplate.replace(/MTHUMB/g, DCCJMG.strModulePath + 'Thumbnail.ashx?image=' + escape(this.path) + '&mediaId=' + this.id + '&ot=1&pid=' + DCCJMG.PortalId + '&mid=' + DCCJMG.ModuleId).replace(/MTITLE/g, this.title);
        }
        else {
            if (this.type == "2") {
                strMedia = strMediaTemplate.replace(/MTHUMB/g, DCCJMG.strModulePath + 'Thumbnail.ashx?gid=' + this.galleryId + '&mediaId=' + this.id + '&ot=4&url=' + UrlEncode(this.MediaUrl) + '&pid=' + DCCJMG.PortalId + '&mid=' + DCCJMG.ModuleId).replace(/MTITLE/g, this.title);
            }
        }
        strMedia = strMedia.replace(/MEDIAID/g, this.id).replace(/MODULEID/g, modId).replace(/TOOLTIP/g, media.tooltip).replace(/MDESC/g, this.description);
        if (DCCJMG.thisusername == "Administrators") {
            var strfinalMedia = DCCJMG.strTemplateMediaThumbNailfordelete;
        } else {

            if (media.username == DCCJMG.thisusername) {
                var strfinalMedia = DCCJMG.strTemplateMediaThumbNailfordelete;
            }
            else {
                var strfinalMedia = DCCJMG.strTemplateMediaThumbNail;
            }
        }
        strfinalMedia = strfinalMedia.replace(/MID/g, this.id).replace(/MTITLE/g, this.title).replace(/MDESC/g, this.description).replace(/MEDIA/g, strMedia).replace(/MODID/g, modId).replace(/MSOURCE/g, DCCJMG.strModulePath + 'Thumbnail.ashx?image=' + this.path + '&mediaId=' + this.id + '&ot=2&pid=' + DCCJMG.PortalId + '&mid=' + DCCJMG.ModuleId).replace(/MTITLE/g, this.title);
        strfinalMedia = strfinalMedia.replace(/MLSTCLASS/g, 'ui-state-default')
        return strfinalMedia;
    }
}
function AddSpace(title) {
    var index = 0;
    var maxContinuousLength = 15;
    var tempCommentText = title;
    if (maxContinuousLength < title.length) {
        tempCommentText = '';
        while (index < title.length) {
            var subStringSize = maxContinuousLength;
            if ((index + maxContinuousLength) > title.length) {
                subStringSize = title.length - index;
            }
            var subStr = title.substring(index, index + subStringSize);
            var spaceidx = subStr.indexOf(" ");
            if (subStr.length > maxContinuousLength - 1 && (spaceidx == -1 || spaceidx > maxContinuousLength)) {
                tempCommentText += " " + subStr + " ";
            }
            else {
                tempCommentText += subStr;
            }
            index += maxContinuousLength;
        }
    }
    return tempCommentText;
}

function handlePaging(moduleId, thisPageNo, totalPages, hidePager) {

    DCCJMG_SetConstants(moduleId);
    var parentDiv = jqsDCCJMG('div#' + moduleId + '_MediaGallery');
    idlbPrevText = parentDiv.find('a#PrevText');
    idlbPrevPrevPrevPrev = parentDiv.find('a#PrevPrevPrevPrev');
    idlbPrevPrevPrev = parentDiv.find('a#PrevPrevPrev');
    idlbPrevPrev = parentDiv.find('a#PrevPrev');
    idlbPrev = parentDiv.find('a#Prev');
    idlbCurrent = parentDiv.find('span#Current');
    idlbNext = parentDiv.find('a#Next');
    idlbNextNext = parentDiv.find('a#NextNext');
    idlbNextNextNext = parentDiv.find('a#NextNextNext');
    idlbNextNextNextNext = parentDiv.find('a#NextNextNextNext');
    idlbNextText = parentDiv.find('a#NextText');
    parentDiv.find("a").css("color", '#' + DCCJMG.strTextColor);

    if (hidePager != 1) {
        idlbCurrent.parents('div.dcc_gallery_mediapager').show();

        if (((thisPageNo - 4) <= 0) || ((thisPageNo - 4) > totalPages)) {
            idlbPrevPrevPrevPrev.hide();
            idlbPrevPrevPrevPrev.parent('li').hide();
        }
        else {
            idlbPrevPrevPrevPrev.show();
            idlbPrevPrevPrevPrev.parent('li').show();
            idlbPrevPrevPrevPrev.html(thisPageNo - 4);
            idlbPrevPrevPrevPrev.data("PageNo", thisPageNo - 4);


        }

        if (((thisPageNo - 3) <= 0) || ((thisPageNo - 3) > totalPages)) {
            idlbPrevPrevPrev.hide();
            idlbPrevPrevPrev.parent('li').hide();
        }
        else {
            idlbPrevPrevPrev.show();
            idlbPrevPrevPrev.parent('li').show();
            idlbPrevPrevPrev.html(thisPageNo - 3);
            idlbPrevPrevPrev.data("PageNo", thisPageNo - 3);

        }

        if (((thisPageNo - 2) <= 0) || ((thisPageNo - 2) > totalPages)) {
            idlbPrevPrev.hide();
            idlbPrevPrev.parent('li').hide();

        }
        else {
            idlbPrevPrev.show();
            idlbPrevPrev.parent('li').show();
            idlbPrevPrev.html(thisPageNo - 2);
            idlbPrevPrev.data("PageNo", thisPageNo - 2);


        }

        if (((thisPageNo - 1) <= 0) || ((thisPageNo - 1) > totalPages)) {
            idlbPrev.hide();
            idlbPrev.parent('li').hide();
            idlbPrevText.hide();
            idlbPrevText.parent('li').hide();
        }
        else {
            idlbPrev.show();
            idlbPrev.parent('li').show();
            idlbPrevText.show();
            idlbPrevText.parent('li').show();
            idlbPrev.html(thisPageNo - 1);
            idlbPrev.data("PageNo", thisPageNo - 1);

        }

        if ((thisPageNo <= 0) || (thisPageNo > totalPages)) {
            idlbCurrent.hide();
            idlbCurrent.parent('li').hide();
        }
        else {
            idlbCurrent.show();
            idlbCurrent.parent('li').show();
            idlbCurrent.html(thisPageNo);
            idlbCurrent.data("PageNo", thisPageNo);

        }

        if ((thisPageNo + 1) <= 0 || (thisPageNo + 1) > totalPages) {
            idlbNext.hide();
            idlbNext.parent('li').hide();

            idlbNextText.hide();
            idlbNextText.parent('li').hide();

        }
        else {
            idlbNext.show();
            idlbNext.parent('li').show();

            idlbNextText.show();
            idlbNextText.parent('li').show();

            idlbNext.html(thisPageNo + 1);
            idlbNext.data("PageNo", thisPageNo + 1);

        }



        if (((thisPageNo + 2) <= 0) || ((thisPageNo + 2) > totalPages)) {
            idlbNextNext.hide();
            idlbNextNext.parent('li').hide();

        }
        else {
            idlbNextNext.show();
            idlbNextNext.parent('li').show();

            idlbNextNext.html(thisPageNo + 2);
            idlbNextNext.data("PageNo", thisPageNo + 2);
        }

        if (((thisPageNo + 3) <= 0) || ((thisPageNo + 3) > totalPages)) {
            idlbNextNextNext.hide();
            idlbNextNextNext.parent('li').hide();

        }
        else {
            idlbNextNextNext.show();
            idlbNextNextNext.parent('li').show();

            idlbNextNextNext.html(thisPageNo + 3);
            idlbNextNextNext.data("PageNo", thisPageNo + 3);
        }

        if (((thisPageNo + 4) <= 0) || ((thisPageNo + 4) > totalPages)) {
            idlbNextNextNextNext.hide();
            idlbNextNextNextNext.parent('li').hide();

        }
        else {
            idlbNextNextNextNext.show();
            idlbNextNextNextNext.parent('li').show();

            idlbNextNextNextNext.html(thisPageNo + 4);
            idlbNextNextNextNext.data("PageNo", thisPageNo + 4);
        }

        idlbPrevText.data("PageNo", thisPageNo - 1);
        idlbNextText.data("PageNo", thisPageNo + 1);
    }
    else {
        idlbCurrent.parents('div.dcc_gallery_mediapager').hide();


    }
}


//every external Javascript file that is being referenced from ScriptManager must have a call to Sys.Application.
if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

