//**************************************************
//Handle the Gallery objects in the UI
//**************************************************
// if ((typeof (oId) != "undefined") && (oId != null)) {

//-------------------------------------------------------------
//GalNav Gallery
//-------------------------------------------------------------
// if ((typeof (oId) != "undefined") && (oId != null)) {


var popUpData = "";
var navDir = 1; //1 forward, -1 backward
var setGalText = "";
var currentItem = 0;
var currentItemData = 0;

function navImageBack(galType, counterId, arrGalObj, itemDataId) {
    var counter = document.getElementById(counterId);
    if (counter == null || typeof (counter) == 'undefined') {
        return;
    }
    var selectedNavGalIndex = counter.value;
    //catch exception:
    if (selectedNavGalIndex > 1)
        selectedNavGalIndex--;
    else
        selectedNavGalIndex = 0;
    counter.value = selectedNavGalIndex;

    navDir = -1;

    if (selectedNavGalIndex > -1) {
        var data = arrGalObj[selectedNavGalIndex];
        handleObjectData(data, galType, counterId, arrGalObj, itemDataId);
    }
    else if (selectedNavGalIndex == 0 && galType == "galNavAll") {
        var data = arrGalObj[selectedNavGalIndex];
        handleObjectData(data, galType, counterId, arrGalObj, itemDataId);
    }

    //handle buttons css
    if (selectedNavGalIndex > 0) {
        navAllowNav();
    }
    else {
        navHandleFirst();
    }
}
//-------------------------------------------------------------
//
function navImageForward(galType, counterId, arrGalObj, itemDataId) {
    //alert(selectedNavGalIndex);
    var counter = document.getElementById(counterId);
    if (counter == null || typeof (counter) == 'undefined') {
        return;
    }
    var selectedNavGalIndex = counter.value;
    selectedNavGalIndex++;
    counter.value = selectedNavGalIndex;

    navDir = 1;
    if (selectedNavGalIndex < arrGalObj.length) {
        var data = arrGalObj[selectedNavGalIndex];
        handleObjectData(data, galType, counterId, arrGalObj, itemDataId);
    }

    if (selectedNavGalIndex < arrGalObj.length - 1) {
        navAllowNav();
    }
    else {
        navHandleLast();
    }
}
//-------------------------------------------------------------
//set the data related to current image in the navGal
function handleObjectData(data, galType, counterId, arrGalObj, itemDataId) {

    var counter = document.getElementById(counterId);
    if (counter == null || typeof (counter) == 'undefined') {
        return;
    }
    var selectedNavGalIndex = counter.value;

    //get containers from page
    var imgDiv = document.getElementById("divImg" + itemDataId);
    if ((typeof (imgDiv) == "undefined") || (imgDiv == null)) {
        alert("divImg" + itemDataId + 'undefined!');
    }
    var swfDiv = document.getElementById("divSwf" + itemDataId);
    if ((typeof (swfDiv) == "undefined") || (swfDiv == null)) {
        alert("swfDiv" + itemDataId + 'undefined!');
    }
    var imgBig = document.getElementById("galBigImg" + itemDataId);
    if ((typeof (imgBig) == "undefined") || (imgBig == null)) {
        alert("imgBig" + itemDataId + 'undefined!');
    }

    var openPopup = 0;
    var imgMagnifyingGlass = document.getElementById("magnifyingGlass");

    if ((typeof (imgMagnifyingGlass) != "undefined") && (imgMagnifyingGlass != null)) {
        popUpData = data;
    }



    //alert(selectedNavGalIndex);
    //document.getElementById("lkImage").style.backgroundColor = "Yellow";
    //alert(document.getElementById("lkImage").innerHTML);
    //alert(data);

    var dataArr = data.split("#");

    if (galType == "galNav") {
        var url = dataArr[0];
        var width = parseInt(dataArr[1]);
        var height = parseInt(dataArr[2]);
        var itemId = parseInt(dataArr[3]);
        var itemDataId = parseInt(dataArr[4]);
        var typeDataId = parseInt(dataArr[5]);
        var link = removeStringEdges(dataArr[6]);
        var linkUrl = dataArr[7];
        var imgText = removeStringEdges(dataArr[8]);
    }
    else if (galType == "galNavAll") {
        var innerIndex = dataArr[0];
        var itemId = parseInt(dataArr[1]);
        var itemDataId = parseInt(dataArr[2]);
        var typeDataId = parseInt(dataArr[3]);
        var url = dataArr[4];
        var width = parseInt(dataArr[5]);
        var height = parseInt(dataArr[6]);
        var link = removeStringEdges(dataArr[7]); // or GalTitle
        var linkUrl = dataArr[8];
        var imgText = removeStringEdges(dataArr[9]);
        var textDivId = removeStringEdges(dataArr[10]);
    }


    if (url != "-") {
        if (getObjType(url) == "swf") {
            swfDiv.style.display = '';
            imgDiv.style.display = 'none';
            //set the swf object:
            makeFlashObjectData(swfDiv.id, url, width, height, '#ffffff');
        }
        else {
            swfDiv.style.display = 'none';
            imgDiv.style.display = 'block';
            var newUrl = getRelativeUrl(imgBig.src) + getImgPath(url);
            //alert(url + ' ' + bigImageWidth);
            imgBig.style.width = bigImageWidth + "px";
            imgBig.style.height = bigImageHeight + "px";
            imgBig.src = newUrl;
            setTimeout("setNewObject('" + newUrl + "','" + itemDataId + "')", 750);
        }


        //alert(imgText);
        var txtImgText = document.getElementById("txtImgText");
        if ((typeof (txtImgText) != "undefined") && (txtImgText != null)) {
            if (imgText != "-") {
                imgText = replaceAll(imgText, "**", "'");
                txtImgText.innerHTML = imgText;
            }
            else {
                txtImgText.innerHTML = "";
            }
        }

        var lkImage = document.getElementById("lkImage");
        if ((typeof (lkImage) != "undefined") && (lkImage != null)) {
            //alert(link.length + ' ' + link);
            if (link != "-") {
                link = replaceAll(link, "**", "'");
                lkImage.href = linkUrl;
                lkImage.innerHTML = link;
            }
            else {
                lkImage.href = "";
                lkImage.innerHTML = "";
                lkImage.innerHTML = "";
            }
        }


        var txtImgIndex = document.getElementById("txtImgIndex");
        if ((typeof (txtImgIndex) != "undefined") && (txtImgIndex != null)) {
            //alert(selectedNavGalIndex + " " + (arrGalObj.length - 1));
            if (galType == "galNavAll") {
                txtImgIndex.innerHTML = innerIndex;
            }
            else {//galNav
                txtImgIndex.innerHTML = " (" + (parseInt(selectedNavGalIndex) + 1) + "-" + (arrGalObj.length) + ")";
            }
        }
    }
    else {//if we have dont have a url then move to next image
        if (galType == "galNavAll") {
            //alert(data + ' ' + link);
            //set gal Text:
            if (navDir == 1) {//move forward
                if (link != "-") {
                    var divGalTitle = document.getElementById("divGalTitle");
                    if ((typeof (divGalTitle) != "undefined") && (divGalTitle != null)) {
                        divGalTitle.innerHTML = link;
                    }
                }

                var divGalText = document.getElementById("divGalText");


                var galText = document.getElementById(textDivId).innerHTML;
                if (galText != "-") {
                    galText = replaceAll(document.getElementById(textDivId).innerHTML, "**", "'");
                    if ((typeof (divGalText) != "undefined") && (divGalText != null)) {
                        document.getElementById("divGalText").innerHTML = galText;
                    }
                }
                else {
                    if ((typeof (divGalText) != "undefined") && (divGalText != null)) {
                        document.getElementById("divGalText").innerHTML = " ";
                    }
                }

                selectedNavGalIndex++;
            }
            else {//move backward
                var prevGalStartData = arrGalObj[parseInt(innerIndex)];
                var prevGalDataArr = prevGalStartData.split("#");
                //the prev itemId
                itemId = parseInt(prevGalDataArr[1]);
                itemDataId = parseInt(prevGalDataArr[2]);

                var prevGalTitle = removeStringEdges(prevGalDataArr[7]);
                prevGalTitle = replaceAll(prevGalTitle, "**", "'");
                if (prevGalTitle != "-") {
                    if ((typeof (divGalTitle) != "undefined") && (divGalTitle != null)) {
                        document.getElementById("divGalTitle").innerHTML = prevGalTitle;
                    }
                }

                var prevGalTextDivId = removeStringEdges(prevGalDataArr[10]);
                //alert(prevGalTextDivId);
                var prevGalText = document.getElementById(prevGalTextDivId).innerHTML;
                //alert(prevGalText);
                if (prevGalText != "-") {
                    prevGalText = replaceAll(document.getElementById(prevGalTextDivId).innerHTML, "**", "'");
                    if ((typeof (divGalText) != "undefined") && (divGalText != null)) {
                        document.getElementById("divGalText").innerHTML = prevGalText;
                    }
                }
                else {
                    if ((typeof (divGalText) != "undefined") && (divGalText != null)) {
                        document.getElementById("divGalText").innerHTML = " ";
                    }
                }

                selectedNavGalIndex--;

            }
            counter.value = selectedNavGalIndex;

            //handle menu Section:
            setGalMenus(itemId, itemDataId);
            if (currentItem == 0)
                currentItem = itemId;
            else if (currentItem != itemId) {
                hideAllSubMenu();
                document.getElementById("divSubMenu_" + itemId).style.display = "block";
                currentItem = itemId;
            }

            if (selectedNavGalIndex < 0)
                return;
            var newData = arrGalObj[selectedNavGalIndex];
            handleObjectData(newData, galType, counterId, arrGalObj);

        }
    }
}
//-------------------------------------------------------------
//Functions for galNavAll:
//-------------------------------------------------------------
function showSubMenu(subMenuDivId, index) {
    //alert(index);
    hideAllSubMenu();
    document.getElementById(subMenuDivId).style.display = "";
    navDir = 1; //direction is forward
    selectedNavGalIndex = index;
    var data = arrGalObj[selectedNavGalIndex];
    handleObjectData(data, 'galNavAll');
}

function hideAllSubMenu() {
    var innerDivs = document.getElementsByTagName("div");
    for (var k = 0; k < innerDivs.length; k++) {
        //alert(innerDivs[k].id.indexOf("divSubMenu") + ' - ' + innerDivs[k].id);
        if (innerDivs[k].id.indexOf("divSubMenu") >= 0) {
            //alert('divSubMenu=' + innerDivs[k].id);
            innerDivs[k].style.display = "none";
        }
    }
}

function showGal(index) {
    //alert(index);
    navDir = 1; //direction is forward
    selectedNavGalIndex = index;
    var data = arrGalObj[selectedNavGalIndex];
    handleObjectData(data, 'galNavAll');
}

function unSelectAllTd(type) {
    var innerTds = document.getElementsByTagName("td");
    for (var k = 0; k < innerTds.length; k++) {
        if (type == 'main') {
            if ((innerTds[k].id.indexOf("tdMainMenu") >= 0) || (innerTds[k].id.indexOf("tdSubMenu") >= 0))
                innerTds[k].className = 'galNavAll_td';
        }
        else {
            if (innerTds[k].id.indexOf("tdSubMenu") >= 0)
                innerTds[k].className = 'galNavAll_td';
        }
    }
}

function manageTdColor(obj, action) {
    if (obj.className != 'galNavAll_td_selected') {
        if (action == 'over')
            obj.className = 'galNavAll_td_hover';
        else
            obj.className = 'galNavAll_td';
    }
}

//set the gal menu from menu click
function setGalMenus(itemId, itemDataId) {
    unSelectAllTd('main');
    document.getElementById("tdMainMenu" + itemId).className = "galNavAll_td_selected";
    document.getElementById("tdSubMenu" + itemDataId).className = "galNavAll_td_selected";

    if (selectedNavGalIndex > 0) {
        document.getElementById("imgNavForward").className = "allowClick";
        document.getElementById("imgNavBack").className = "allowClick";
    }
}
//-------------------------------------------------------------
//handle the behaviour of nav images in the 1st and last image
//-------------------------------------------------------------
function setNewObject(newUrl, itemDataId) {
    var imgBig = document.getElementById("galBigImg" + itemDataId);
    imgBig.src = newUrl;
}

function navHandleLast() {
    document.getElementById("imgNavForward").className = "blockClick";
    document.getElementById("imgNavForward").disabled = true;
}

function navHandleFirst() {
    document.getElementById("imgNavBack").className = "blockClick";
    document.getElementById("imgNavBack").disabled = true;
}

function navAllowNav() {
    var imgNavForward = document.getElementById("imgNavForward");
    if ((typeof (imgNavForward) != "undefined") && (imgNavForward != null)) {
        imgNavForward.className = "allowClick";
        imgNavForward.disabled = false;
    }

    document.getElementById("imgNavBack").className = "allowClick";
    document.getElementById("imgNavBack").disabled = false;
    //alert(document.getElementById("imgNavBack").className);
}
//-------------------------------------------------------------
//launch img in popUp window for galList
function displayGalListImageOnPopup(typeDataId, itemDataId) {
    sLaunchPopup = "Page.aspx?Action=Image&TypeDataId=" + typeDataId + "&ItemDataId=" + itemDataId + "";
    makeViewerWindow(sLaunchPopup, 'popup', 1);
}
//-------------------------------------------------------------
//launch img in popUp window
function displayImageOnPopup(galType) {
    //alert(galType);


    if (popUpData == "" && galType != "galBasic")
        return;
    //alert("popUpData=" + popUpData);
    var dataArr = popUpData.split("#");
    var itemId;
    var itemDataId;
    var typeDataId;
    var url;
    var height;
    var width;
    var link;
    var linkUrl;
    var title;
    var innerIndex;

    if (galType == "galNav") {
        url = dataArr[0];
        width = parseInt(dataArr[1]);
        height = parseInt(dataArr[2]);
        itemId = parseInt(dataArr[3]);
        itemDataId = parseInt(dataArr[4]);
        typeDataId = parseInt(dataArr[5]);
        link = removeStringEdges(dataArr[6]);
        linkUrl = dataArr[7];
        title = removeStringEdges(dataArr[8]);
    }
    else if (galType == "galNavAll") {
        innerIndex = dataArr[0];
        itemId = parseInt(dataArr[1]);
        itemDataId = parseInt(dataArr[2]);
        typeDataId = parseInt(dataArr[3]);
        url = dataArr[4];
        width = parseInt(dataArr[5]);
        height = parseInt(dataArr[6]);
        link = removeStringEdges(dataArr[7]);
        linkUrl = dataArr[8];
        title = removeStringEdges(dataArr[9]);
        textDivId = removeStringEdges(dataArr[10]);

    }
    else if (galType == "galBasic") {
        itemDataId = parseInt(dataArr[4]);
        typeDataId = parseInt(dataArr[5]);
    }
    sLaunchPopup = "Page.aspx?Action=Image&TypeDataId=" + typeDataId + "&ItemDataId=" + itemDataId + "";
    makeViewerWindow(sLaunchPopup, 'popup', 1);
}

//-------------------------------------------------------------
// Gallery Slider (with scroll div)
//-------------------------------------------------------------
var currentImageIndex;
var currentImageId;
var amountOfImages = 0;
var spaceBetweenImages = 7; // change this value (+-2) if the image is not exactly on the edge!
//-------------------------------------------------------------------
function setNextImg(selectedBasicGalIndexId, imgMainId, ImageCount, scrollDivId, smallImgsWidth, itemDataId, arrGalObj) {
    // debugger;
    //alert('selectedBasicGalIndexId= ' + selectedBasicGalIndexId + ' , imgMainId= ' + imgMainId + ' , ImageCount=' + ImageCount + ' , scrollDivId=' + scrollDivId + ' , smallImgsWidth=' + smallImgsWidth);

    var ctrl = document.getElementById(selectedBasicGalIndexId);
    if ((typeof (ctrl) == "undefined") || (ctrl == null)) {
        alert(selectedBasicGalIndexId + 'undefined!');
        return;
    }

    var selectedBasicGalIndex = parseInt(ctrl.value);

    if (selectedBasicGalIndex == ImageCount - 1) {
        selectedBasicGalIndex = 0;
    }
    else {
        selectedBasicGalIndex++;
    }

    var nextImgId = "galObj" + itemDataId + "_" + selectedBasicGalIndex;
    var selectedImg = document.getElementById(nextImgId);

    var imgDiv = document.getElementById("divImg" + itemDataId);
    if ((typeof (imgDiv) == "undefined") || (imgDiv == null)) {
        alert("divImg" + itemDataId + 'undefined!');
    }
    var swfDiv = document.getElementById("divSwf" + itemDataId);
    if ((typeof (swfDiv) == "undefined") || (swfDiv == null)) {
        alert("swfDiv" + itemDataId + 'undefined!');
    }

    var data = arrGalObj[selectedBasicGalIndex];
    var dataArr = data.split("#");
    var url = dataArr[0].replace("~/", "");
    var w = dataArr[1];
    var h = dataArr[2];

    if (selectedImg != null && typeof (selectedImg) != 'undefined') {
        HideSelectImg(itemDataId);
        selectedImg.className = "objBorderSelect";

        if (getObjType(url) == "swf") {
            swfDiv.style.display = 'block';
            imgDiv.style.display = 'none';
            //set the swf object:
            makeFlashObjectData(swfDiv.id, url, w, h, '#ffffff');
        }
        else {
            swfDiv.style.display = 'none';
            imgDiv.style.display = 'block';
            var mainImg = document.getElementById(imgMainId);
            if (mainImg != null && typeof (mainImg) != 'undefined') {
                mainImg.src = url;
            }
        }


        var scrollDiv = document.getElementById(scrollDivId);

        if (scrollDiv != null && typeof (scrollDiv) != 'undefined') {
            var direction = scrollDiv.style.direction;

            if (selectedBasicGalIndex == 0) {
                if (direction == 'ltr') {
                    scrollDiv.scrollLeft -= (ImageCount * smallImgsWidth);
                }
                else {
                    scrollDiv.scrollLeft += (ImageCount * smallImgsWidth);
                }
            }
            else {
                if (direction == 'ltr') {
                    scrollDiv.scrollLeft += (parseInt(smallImgsWidth) + parseInt(spaceBetweenImages));
                }
                else {
                    scrollDiv.scrollLeft -= (parseInt(smallImgsWidth) + parseInt(spaceBetweenImages));
                }
            }
        }
    }

    ctrl.value = selectedBasicGalIndex;
}
//-----------------------------------------------------------------------------
function setPrevImg(selectedBasicGalIndexId, imgMainId, ImageCount, scrollDivId, smallImgsWidth, itemDataId, arrGalObj) {
    var ctrl = document.getElementById(selectedBasicGalIndexId);
    if ((typeof (ctrl) == "undefined") || (ctrl == null)) {
        alert(selectedBasicGalIndexId + 'undefined!');
        return;
    }

    var selectedBasicGalIndex = parseInt(ctrl.value);

    if (selectedBasicGalIndex == 0) {
        selectedBasicGalIndex = ImageCount - 1;
    }
    else {
        selectedBasicGalIndex--;
    }

    var prevImgId = "galObj" + itemDataId + "_" + selectedBasicGalIndex;
    var selectedImg = document.getElementById(prevImgId);

    var imgDiv = document.getElementById("divImg" + itemDataId);
    if ((typeof (imgDiv) == "undefined") || (imgDiv == null)) {
        alert("divImg" + itemDataId + 'undefined!');
    }
    var swfDiv = document.getElementById("divSwf" + itemDataId);
    if ((typeof (swfDiv) == "undefined") || (swfDiv == null)) {
        alert("swfDiv" + itemDataId + 'undefined!');
    }

    var data = arrGalObj[selectedBasicGalIndex];
    var dataArr = data.split("#");
    var url = dataArr[0].replace("~/", "");
    var w = dataArr[1];
    var h = dataArr[2];

    if (selectedImg != null && typeof (selectedImg) != 'undefined') {
        HideSelectImg(itemDataId);

        selectedImg.className = "objBorderSelect";
        if (getObjType(url) == "swf") {
            swfDiv.style.display = 'block';
            imgDiv.style.display = 'none';
            //set the swf object:
            makeFlashObjectData(swfDiv.id, url, w, h, '#ffffff');
        }
        else {
            swfDiv.style.display = 'none';
            imgDiv.style.display = 'block';
            var mainImg = document.getElementById(imgMainId);
            if (mainImg != null && typeof (mainImg) != 'undefined') {
                mainImg.src = url;
            }
        }
    }

    var scrollDiv = document.getElementById(scrollDivId);
    if (scrollDiv != null && typeof (scrollDiv) != 'undefined') {
        var direction = scrollDiv.style.direction;
        if (selectedBasicGalIndex == (ImageCount - 1)) {//we r in the first img, move scroll to the last
            if (direction == 'ltr') {
                scrollDiv.scrollLeft += (ImageCount * smallImgsWidth);
            }
            else {
                scrollDiv.scrollLeft -= (ImageCount * smallImgsWidth);
            }
        }
        else {
            if (direction == 'ltr') {
                scrollDiv.scrollLeft -= (parseInt(smallImgsWidth) + parseInt(spaceBetweenImages));
            }
            else {
                scrollDiv.scrollLeft += (parseInt(smallImgsWidth) + parseInt(spaceBetweenImages));
            }
        }
    }
    ctrl.value = selectedBasicGalIndex;

}
//-----------------------------------------------------------------------------
function HideSelectImg(itemDataId) {
    var innerImg = document.getElementsByTagName("img");
    for (var k = 0; k < innerImg.length; k++) {
        if (innerImg[k].id.indexOf("galObj" + itemDataId) >= 0) {
            //innerImg[k].style.borderColor = "#d0d0d0";
            innerImg[k].className = "objBorder";
        }
    }
    //for swf
    var innerDiv = document.getElementsByTagName("div");
    for (var k = 0; k < innerDiv.length; k++) {
        if (innerDiv[k].id.indexOf("galObj" + itemDataId) >= 0) {
            //innerDiv[k].style.borderColor = "#d0d0d0";
            innerDiv[k].className = "objBorder";
        }
    }
}
//-------------------------------------------------------------
function HandleSelectImg(id, itemDataId) {
    HideSelectImg(itemDataId);
    //getE('galObj' + id).style.borderColor = "orange";
    getE(id).className = "objBorder";
}
//-------------------------------------------------------------
//-------------------------------------------------------------
//-------------------------------------------------------------
function Dr_Img(data) {
    var dataArr = data.split("#");
    var url = dataArr[0].replace("~/", "");
    var w = dataArr[1];
    var h = dataArr[2];
    var itemDataId = dataArr[4];
    var link = removeStringEdges(dataArr[6]);
    var linkUrl = dataArr[7];
    var imgText = removeStringEdges(dataArr[8]);
    var id = dataArr[9];

    var imsBorderColor = '#d0d0d0';
    //alert(id);
    if (id == 0)
        imsBorderColor = 'orange';

    var res = '';

    if (getObjType(url) == "swf") {
        res = '<div id="galObj' + id + ' onclick="HandleSelectImg(\'' + id + '\',\'' + itemDataId + '\');ShowBasicImage(\'' + itemDataId + '\',\'' + data + '\')"   style="border:solid 1x ' + imsBorderColor + '"> ' +
                                        '<object  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' +
                                        ' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' +
                                        ' width="' + w + 'px" height="' + h + 'px"  align="middle"  onclick="HandleSelectImg(\'' + id + '\',\'' + itemDataId + '\');ShowBasicImage(\'' + itemDataId + '\',\'' + data + '\')"> ' +
                                        ' <param name="allowScriptAccess" value="sameDomain" />' +
                                        ' <param name="wmode" value="Transparent" />' +
                                        ' <param name="movie" value="' + url + '" />' +
                                        ' <param name="quality" value="high" />' +
                                        ' <param name="bgcolor" value="#ffffff" />' +
                                        ' <embed src="' + url + '" quality="high" bgcolor="#ffffff" width="' + w + 'px" ' +
                                        '  height="' + h + 'px"  align="middle" allowScriptAccess="sameDomain" ' +
                                        '  type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object></div><br>';

        //alert(data);
        //alert(res);
    }
    else {
        res = '<img id="galObj' + id + '" style="border:solid 1x ' + imsBorderColor + '" src="' + url + '" width="' + w + '" height="' + h + '" title="' + imgText + '" onclick="HandleSelectImg(\'' + id + '\',\'' + itemDataId + '\');ShowBasicImage(\'' + itemDataId + '\',\'' + data + '\')" />';
    }

    return res;
}
//-------------------------------------------------------------
function Dr_ImgArr() {
    //getSliderSizes();
    var str = '';
    var Len = arrGalObj.length;
    var MoreImage = 0;
    for (i = 0; i < Len; i++) str += Dr_Img(arrGalObj[i]);
    for (i = 0; i < MoreImage; i++) str += Dr_Img(arrGalObj[i]);
    //alert(str);
    document.write(str);
}
//-------------------------------------------------------------
//Basic Gallery
//-------------------------------------------------------------
function resetBasicGaldivs(itemDataId) {
    var innerDivImg = document.getElementsByTagName("div");
    for (var k = 0; k < innerDivImg.length; k++) {
        if (innerDivImg[k].id.indexOf("divGalPage_" + itemDataId) >= 0) {
            //alert(innerDivImg[k].id);
            var obj = document.getElementById(innerDivImg[k].id);
            obj.style.display = "none";
            //alert(obj.id + ' ' + alert(obj.style.display));
        }
    }
}
//-------------------------------------------------------------	
function ShowGalBasicPage(itemDataId, pageNum) {
    resetBasicGaldivs(itemDataId);
    var divPage = document.getElementById("divGalPage_" + itemDataId + "_" + pageNum);
    divPage.style.display = "block";
    //alert(divPage.id + ' ' + divPage.style.display);
}
//-------------------------------------------------------------	
function ShowBasicImage(itemDataId, arrObj) {
    var openPopup = 0;
    var imgMagnifyingGlass = document.getElementById("magnifyingGlass");

    //    var imgDiv = document.getElementById("divImg");
    //    var swfDiv = document.getElementById("divSwf");
    //    var imgBig = document.getElementById("galBigImg");

    var imgDiv = document.getElementById("divImg" + itemDataId);
    if ((typeof (imgDiv) == "undefined") || (imgDiv == null)) {
        alert("divImg" + itemDataId + 'undefined!');
    }
    var swfDiv = document.getElementById("divSwf" + itemDataId);
    if ((typeof (swfDiv) == "undefined") || (swfDiv == null)) {
        alert("swfDiv" + itemDataId + 'undefined!');
    }
    var imgBig = document.getElementById("galBigImg" + itemDataId);
    if ((typeof (imgBig) == "undefined") || (imgBig == null)) {
        alert("imgBig" + itemDataId + 'undefined!');
    }


    var data = arrObj;
    if (data == null)
        return;
    var dataArr = data.split("#");
    var url = dataArr[0].replace("~/", "");
    var w = dataArr[1];
    var h = dataArr[2];
    var link = removeStringEdges(dataArr[6]);
    var linkUrl = dataArr[7];
    var imgText = removeStringEdges(dataArr[8]);


    if ((typeof (imgMagnifyingGlass) != "undefined") && (imgMagnifyingGlass != null)) {
        popUpData = data;
    }

    //alert(url + ' ' + getObjType(url));
    //    var imgSmall = document.getElementById("galObj_" + itemDataId + "_" + );
    //    if ((typeof (imgSmall) != "undefined") && (imgSmall != null)) {
    //        imgSmall.className = "objBorderSelect";
    //    }

    if (getObjType(url) == "swf") {
        swfDiv.style.display = '';
        imgDiv.style.display = 'none';
        //set the swf object:
        makeFlashObjectData(swfDiv.id, url, w, h, '#ffffff');
    }
    else {
        swfDiv.style.display = 'none';
        imgDiv.style.display = 'block';
        imgBig.src = url;
        imgBig.title = link;
    }

    var txtImgText = document.getElementById("txtImgText");
    if ((typeof (txtImgText) != "undefined") && (txtImgText != null)) {
        if (imgText != "-") {
            imgText = replaceAll(imgText, "**", "'");
            txtImgText.innerHTML = imgText;
        }
        else {
            txtImgText.innerHTML = "";
        }
    }

    var lkImage = document.getElementById("lkImage");
    if ((typeof (lkImage) != "undefined") && (lkImage != null)) {
        //alert(link.length + ' ' + link);
        if (link != "-") {
            link = replaceAll(link, "**", "'");
            lkImage.href = linkUrl;
            lkImage.innerHTML = link;
        }
        else {
            lkImage.href = "";
            lkImage.innerText = "";
            lkImage.innerHTML = "";
        }
    }
}
//-------------------------------------------------------------
//Table Gallery
//-------------------------------------------------------------	
var swfSelected = "";
function SetObjInContainer(objType, path, id, w, h) {

    //alert(objType + ','+path+','+id+','+w+','+h);
    //window.scrollTo(0,0);
    //handle img replace selection
    try { handleObjReplaceSelection(); }
    catch (e) { }

    try {
        if (objType == 2) {
            document.getElementById("Container").style.display = '';
            document.getElementById("TableSWFContainer").style.display = 'none';
            document.getElementById("SWFContainer").style.display = 'none';
            //handle img replace selection

            document.getElementById("Container").src = path;
            document.getElementById("Container").style.width = w;
            document.getElementById("Container").style.height = h;
            document.getElementById("Container").className = 'ImgGallerySelected';

        }
        else if (objType == 6) {
            document.getElementById("Container").style.display = 'none';
            document.getElementById("TableSWFContainer").style.display = '';
            document.getElementById("SWFContainer").style.display = '';
            document.getElementById("TableSWFContainer").style.width = w;
            document.getElementById("TableSWFContainer").style.height = h;
            //remember swf path for replacing selected obj...
            swfSelected = path;
            //load flash to container
            makeFlashObjectData('SWFContainer', path, w, h, '#ffffff');
        }

        document.getElementById(id).className = 'ImgGallerySelected';
        //load discreption for image...
        loadObjDescription(id, objType, "arr_images");
    }
    catch (e) { }

}
//-------------------------------------------------------------
function handleObjReplaceSelection() {

    if (swfSelected != "") {
        var oldID = getObjID(swfSelected);
        document.getElementById(oldID).className = 'ImgGallery';
        swfSelected = "";
    }
    else {
        var oldPath = document.getElementById("Container").src;
        var oldID = getObjID(oldPath);
        document.getElementById(oldID).className = 'ImgGallery';
    }
}
//-------------------------------------------------------------
function loadObjDescription(objID, objType, arrImages) {

    //alert('loadObjDescription=' + objID);

    var arr = eval(arrImages);
    //build link string
    var sLaunchPopup;
    //go over the image array and locate current obj
    for (y = 0; y < arr.length; y++) {
        if (!arr[y]) {
            continue;
        }
        else {
            TempArr = arr[y].split("@@@");
            if (TempArr[0] == objID) { // the current image...
                //set obj description
                document.getElementById("imgSubTitle").innerHTML = TempArr[3];
                if (TempArr[3].length > 0)
                    document.getElementById("tdSubTitle").className = 'tdGallerySubTitleOn';
                else
                    document.getElementById("tdSubTitle").className = 'tdGallerySubTitleOff';

            }
        }
    }
}
//-------------------------------------------------------------
//function onclick from container img
function loadDataForPopup(path) {
    //alert(path);
    callPopup(path, "arr_images");
}
//-------------------------------------------------------------
//launch img in popUp window
function callPopup(path, arrImages) {
    //alert('callPopup=' + path);
    //get current obj id
    var objID = getObjID(path);
    var objType = getObjType(path);
    var objPath = getImgPath(path);
    //alert(objID + ' ' + objType);

    var arr = eval(arrImages);
    //build link string
    var sLaunchPopup;
    //go over the image array and locate current obj

    for (y = 0; y < arr.length; y++) {
        if (!arr[y]) {
            continue;
        }
        else {
            TempArr = arr[y].split("@@@");

            if (TempArr[0] == objID) { // the current image...
                sLaunchPopup = "Admin/upload/popup.aspx?type=" + objType + "&path=" + objPath + "&width=" + TempArr[1] + "&height=" + TempArr[2] + "";
                makeWindow(sLaunchPopup, TempArr[1], TempArr[2], 'popup', 1)

            }
        }
    }
}


//-------------------------------------------------------------
//start Functions for GalList:
//-------------------------------------------------------------
function LoadUc(obj, lkId, val) {
    //call the server from js
    //alert(obj.id + ' , ' + lkId + ' -- ' + val);
    if (obj != null) {
        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(lkId, val, true, "", "", false, true));
    }
}

function ShowListImages(containerDivId) {
    var containerDiv = document.getElementById(containerDivId);

    if (containerDiv != null && typeof (containerDiv) != 'undefined') {
        //alert(containerDivId);
        var innerImg = containerDiv.getElementsByTagName("img");
        for (var k = 0; k < innerImg.length; k++) {
            var n = (k + 1) * 2 * GetRandom();
            if (innerImg[k].className != 'cornerimage') {
                var t = setTimeout("DisplayImg('" + innerImg[k].id + "')", n);
            }
        }
    }
}

function DisplayImg(objId) {
    var img = document.getElementById(objId);
    if (img != null && typeof (img) != 'undefined') {
        //var path = img.src.replace('loader.gif', img.alt);
        //alert(img.alt);
        img.src = img.alt;
    }
}

function GetRandom() {
    var rand_no = Math.random();
    rand_no = rand_no * 100;
    rand_no = Math.ceil(rand_no);
    return rand_no;

}
//-------------------------------------------------------------
//end Functions for GalList:
//-------------------------------------------------------------


//-------------------------------------------------------------
//Accessory Functions
//-------------------------------------------------------------
function getE(id) {
    return document.getElementById(id);
}
//-------------------------------------------------------------
function makeFlashObjectData(o, filePath, Width, Height, Color) {
    //alert(o + ',' + filePath + ',' + Width + ',' + Height + ',' + Color);
    //Build Flash String
    var Data = "<object valign='top' classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"" + Width + "\" height=\"" + Height + "\" id=\"flash" + o + "\" align=\"middle\"><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"wmode\" value=\"Transparent\" /><param name=\"movie\" value=\"" + filePath + "\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"" + Color + "\" /><embed src=\"" + filePath + "\" quality=\"high\" bgcolor=\"" + Color + "\" width=\"" + Width + "\" height=\"" + Height + "\" name=\"flash" + o + "\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object>";
    //alert(Data);
    var oId = document.getElementById(o);
    oId.style.display = 'block';
    //alert(oId.id + ' ' + oId.style.display);
    //Check Ifnot null or undefined to avoid client script errors
    if ((typeof (oId) != "undefined") && (oId != null)) {
        oId.innerHTML = Data;
        //alert(oId.innerHTML);
    }
    else
        alert(oId.id);
    //alert('end');
}
//-------------------------------------------------------------
function getImgPath(path) {
    var lastSlashPos = path.lastIndexOf('/');
    var imgPath = path.substring(lastSlashPos + 1, path.length);
    return imgPath;
}
//-------------------------------------------------------------
function getRelativeUrl(path) {
    var lastSlashPos = path.lastIndexOf('/');
    var RelativeUrl = path.substring(0, lastSlashPos + 1);
    return RelativeUrl;
}
//-------------------------------------------------------------
function getObjID(path) {
    var temp = new Array();
    var lastSlashPos = path.lastIndexOf('/');
    var imgPath = path.substring(lastSlashPos + 1, path.length);
    temp = imgPath.split('.');
    var ObjID = temp[0];
    return ObjID;
}
//-------------------------------------------------------------
function getObjType(path) {
    var temp = new Array();
    var lastSlashPos = path.lastIndexOf('/');
    var imgPath = path.substring(lastSlashPos + 1, path.length);
    temp = imgPath.split('.');
    return (temp[1]);
}
//-------------------------------------------------------------
function removeStringEdges(str) {
    //alert(str);
    str = str.substr(1); //remove first letter
    //alert(str);
    var strLen = str.length; //remove last letter
    str = str.slice(0, strLen - 1);
    //alert(str);
    return str;
}
//-------------------------------------------------------------
function replaceAll(Source, stringToFind, stringToReplace) {
    var temp = Source;
    var index = temp.indexOf(stringToFind);
    while (index != -1) {
        temp = temp.replace(stringToFind, stringToReplace);
        index = temp.indexOf(stringToFind);
    }
    return temp;
}
//-------------------------------------------------------------

