﻿function BuildAlbums(id, p, mid, pid) {
    $jq.ajax({
        cache: false,
        url: spath + "/DesktopModules/DNNInfo_ImageGallery/AlbumHandler.ashx?id=" + id + "&p=" + p + "&mid=" + mid + "&pid=" + pid,
        data: "{}",
        contentType: "text/html; charset=utf-8",
        dataType: "html",
        error: function(xhr, status, error) {
            //alert the error if needed
            //alert(xhr.responseText);
        },
        success: function(msg) {
            $jq("#" + id).html(msg);
            $jq("#" + id).removeClass("ajaxloadingbar");
        }
    });
}

function BuildImages(id, p, aid, mid, pid) {
    $jq("#" + id).html("");
    $jq("#" + id).addClass("ajaxloadingbar");
    $jq.ajax({
        cache: false,
        url: spath + "/DesktopModules/DNNInfo_ImageGallery/ImageHandler.ashx?id=" + id + "&p=" + p + "&aid=" + aid + "&mid=" + mid + "&pid=" + pid,
        data: "{}",
        contentType: "text/html; charset=utf-8",
        dataType: "html",
        error: function(xhr, status, error) {
            //alert the error if needed
            //alert(xhr.responseText);
        },
        success: function(msg) {
            $jq("#" + id).html(msg);
            $jq("#" + id).removeClass("ajaxloadingbar");
        }
    });
}

function BuildSelectedImages(id, p, aid, mid, pid) {
    obj = document.getElementById(aid);
    if (obj.selectedIndex == 0) {
        BuildAlbums(id, p, mid, pid);
    } else {
        BuildImages(id, p, obj.options[obj.selectedIndex].value, mid, pid);
    }
}

function addmoverclass(id) {
    $jq("#" + id).addClass(" mouseover ");
}

function addmoutclass(id) {
    $jq("#" + id).removeClass(" mouseover ");
}

function LoadBodyEvent(jsfunction) {
    var wload = window.onload;
    if (typeof window.onload == 'function') {
        window.onload = function() {
            if (wload) { wload(); }
            jsfunction();
        }
    } else {
        window.onload = jsfunction;
    }
}

//**** DNNINFO Gallery Template *****//
//mode: switch gallery type
//id: label gallery id
//p: pageindex for album
//pimg: pageindex for image
//mid: moduleid
//pid: portalid
function BuildDITGallery(mode, id, p, pimg, mid, pid) {
    $jq.ajax({
        cache: false,
        url: spath + "/DesktopModules/DNNInfo_ImageGallery/DITHandler.ashx?mode=" + mode + "&id=" + id + "&p=" + p + "&pimg=" + pimg + "&mid=" + mid + "&pid=" + pid,
        data: "{}",
        contentType: "text/html; charset=utf-8",
        dataType: "html",
        error: function(xhr, status, error) {
            //alert the error if needed
            //alert(xhr.responseText);
        },
        success: function(msg) {
            $jq("#" + id).html(msg);
            $jq("#" + id).removeClass("ajaxloadingbar");

            //Load image information
            $jq("#DNNInfo_ImageGallery_ImageLoaderInfo" + mid).hide();
            $jq("#DNNInfo_ImageGallery_ImageLoaderInfo" + mid).slideDown(1500);
        }
    });
}

function BuildDITAlbums(mode, id, p, pimg, mid, pid) {
    $jq("#DNNInfo_ImageGallery_AlbumList" + mid).html("");
    $jq("#DNNInfo_ImageGallery_AlbumList" + mid).addClass("ajaxloadingbar");
    $jq.ajax({
        cache: false,
        url: spath + "/DesktopModules/DNNInfo_ImageGallery/DITHandler.ashx?mode=" + mode + "&id=" + id + "&p=" + p + "&pimg=" + pimg + "&mid=" + mid + "&pid=" + pid,
        data: "{}",
        contentType: "text/html; charset=utf-8",
        dataType: "html",
        error: function(xhr, status, error) {
            //alert the error if needed
            //alert(xhr.responseText);
        },
        success: function(msg) {
            $jq("#DNNInfo_ImageGallery_AlbumList" + mid).html(msg);
            $jq("#DNNInfo_ImageGallery_AlbumList" + mid).removeClass("ajaxloadingbar");
        }
    });
}


function BuildDITImages(mode, id, p, pimg, mid, pid, aid) {
    $jq("#DNNInfo_ImageGallery_RightPane" + mid).html("");
    $jq("#DNNInfo_ImageGallery_RightPane" + mid).addClass("ajaxloadingbar");
    $jq.ajax({
        cache: false,
        url: spath + "/DesktopModules/DNNInfo_ImageGallery/DITHandler.ashx?mode=" + mode + "&id=" + id + "&p=" + p + "&pimg=" + pimg + "&mid=" + mid + "&pid=" + pid + "&aid=" + aid,
        data: "{}",
        contentType: "text/html; charset=utf-8",
        dataType: "html",
        error: function(xhr, status, error) {
            //alert the error if needed
            //alert(xhr.responseText);
        },
        success: function(msg) {
            $jq("#DNNInfo_ImageGallery_RightPane" + mid).html(msg);
            $jq("#DNNInfo_ImageGallery_RightPane" + mid).removeClass("ajaxloadingbar");
        }
    });
}

//We reduce the opacity of the albums and images
function initiateDIT() {
    $jq(document).ready(function() {
        $jq(".DNNInfo_ImageGallery_DITImageThumb").each(function(i) {
            $jq("#" + this.id).animate({ opacity: 0.75 }, 1000);
            $jq("#" + this.id).hover(function() {
                $jq("#" + this.id).animate({ opacity: 1 }, 1000);
            });
            $jq("#" + this.id).mouseout(function() {
                $jq("#" + this.id).animate({ opacity: 0.75 }, 1000);
            });
        });

        $jq(".DNNInfo_ImageGallery_DITAlbumThumb").each(function(i) {
            $jq("#" + this.id).animate({ opacity: 0.75 }, 1000);
            $jq("#" + this.id).hover(function() {
                $jq("#" + this.id).animate({ opacity: 1 }, 1000);
            });
            $jq("#" + this.id).mouseout(function() {
                $jq("#" + this.id).animate({ opacity: 0.75 }, 1000);
            });
        });
    });
}

function loadDITImage(mid, pid, aid, path,imgid) {
    $jq("#DNNInfo_ImageGallery_ImageLoaderInfo" + mid).hide();
    $jq("#DNNInfo_LoadingBar" + mid).addClass("DNNInfo_LoadingBar");
    $jq("#DNNInfo_ImageGallery_ImageLoader" + mid).animate({ opacity: 0.75 }, 100);
    $jq("#DNNInfo_ImageGallery_Img" + mid).animate({ opacity: 1 }, 1000);
    $jq("#DNNInfo_ImageGallery_Img" + mid).attr('src', path);
    $jq("#DNNInfo_ImageGallery_Img" + mid).load(function() {
        $jq("#DNNInfo_ImageGallery_ImageLoader" + mid).animate({ opacity: 1 }, 1);
        $jq("#DNNInfo_LoadingBar" + mid).removeClass("DNNInfo_LoadingBar");
        setTimeout(function() { loadDITImageInfo(3, mid, pid, aid, imgid); }, 500);
    });
}

function loadDITImageInfo(mode, mid, pid, aid, imgid) {
    $jq.ajax({
        cache: false,
        url: spath + "/DesktopModules/DNNInfo_ImageGallery/DITHandler.ashx?mode=" + mode + "&mid=" + mid + "&pid=" + pid + "&aid=" + aid + "&imgid=" + imgid,
        data: "{}",
        contentType: "text/html; charset=utf-8",
        dataType: "html",
        error: function(xhr, status, error) {
            //alert the error if needed
            //alert(xhr.responseText);
        },
        success: function(msg) {
            $jq("#DNNInfo_ImageGallery_ImageLoaderInfo" + mid).html(msg);
            $jq("#DNNInfo_ImageGallery_ImageLoaderInfo" + mid).hide();
            $jq("#DNNInfo_ImageGallery_ImageLoaderInfo" + mid).slideDown(1500)
        }
    });
}