
var LIGHTBOX_OnAddAssetHandlers = new Array();
var LIGHTBOX_OnAddAssetArrayHandlers = new Array();
var LIGHTBOX_OnRemoveAssetHandlers = new Array();
var LIGHTBOX_OnRemoveAssetArrayHandlers = new Array();
var LIGHTBOX_OnClearHandlers = new Array();
var LIGHTBOX_OnLinkHandlers = new Array();
var LIGHTBOX_OnChangeHandlers = new Array();
var LIGHTBOX_xmlContents = null;
var LIGHTBOX_xmlContents_CurrentLimit = 0;
var LIGHTBOX_bContentsRequiresRefresh = true;
var LIGHTBOX_arrAccessibleLBs = null;
var LIGHTBOX_canCreate = false;
var LIGHTBOX_curLBInfo = null;
var LIGHTBOX_menuVisible = false;
function LIGHTBOX_RegisterHandler_OnAddAsset(funcCallback)
{
    LIGHTBOX_OnAddAssetHandlers.push(funcCallback);
}
function LIGHTBOX_RegisterHandler_OnAddAssetArray(funcCallback)
{
    LIGHTBOX_OnAddAssetArrayHandlers.push(funcCallback);
}
function LIGHTBOX_RegisterHandler_OnRemoveAsset(funcCallback)
{
    LIGHTBOX_OnRemoveAssetHandlers.push(funcCallback);
}
function LIGHTBOX_RegisterHandler_OnRemoveAssetArray(funcCallback)
{
    LIGHTBOX_OnRemoveAssetArrayHandlers.push(funcCallback);
}
function LIGHTBOX_RegisterHandler_OnClear(funcCallback)
{
    LIGHTBOX_OnClearHandlers.push(funcCallback);
}
function LIGHTBOX_RegisterHandler_OnLink(funcCallback)
{
    LIGHTBOX_OnLinkHandlers.push(funcCallback);
}
function LIGHTBOX_RegisterHandler_OnChange(funcCallback)
{
    LIGHTBOX_OnChangeHandlers.push(funcCallback);
}
function LIGHTBOX_AddAsset(nID)
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "lightbox.tlx", true);
    xmlhttp.onreadystatechange = function()
    {
        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
        {
            if (Sarissa.getParseErrorText(xmlhttp.responseXML) == Sarissa.PARSED_OK)
            {
                var strResult = xmlhttp.responseXML.documentElement.getElementsByTagName('result')[0].getAttribute('value');
                if (strResult == "OK")
                {
                    LIGHTBOX_bContentsRequiresRefresh = true;
                    for (var i = 0; i < LIGHTBOX_OnAddAssetHandlers.length; ++i)
                    {
                        LIGHTBOX_OnAddAssetHandlers[i](nID);
                    }
                }
            }
        }
    };
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('action=add&asset=' + nID);
}
function LIGHTBOX_AddAssetArray(arrIDs)
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "lightbox.tlx", true);
    xmlhttp.onreadystatechange = function()
    {
        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
        {
            if (Sarissa.getParseErrorText(xmlhttp.responseXML) == Sarissa.PARSED_OK)
            {
                var strResult = xmlhttp.responseXML.documentElement.getElementsByTagName('result')[0].getAttribute('value');
                if (strResult == "OK")
                {
                    LIGHTBOX_bContentsRequiresRefresh = true;
                    for (var i = 0; i < LIGHTBOX_OnAddAssetArrayHandlers.length; ++i)
                    {
                        LIGHTBOX_OnAddAssetArrayHandlers[i](arrIDs);
                    }
                }
            }
        }
    };
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('action=addarray&assetarray=' + arrIDs.join(','));
}
function LIGHTBOX_SelectSLB(nID)
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "lightbox.tlx", true);
    xmlhttp.onreadystatechange = function()
    {
        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
        {
            if (Sarissa.getParseErrorText(xmlhttp.responseXML) == Sarissa.PARSED_OK)
            {
                var strResult = xmlhttp.responseXML.documentElement.getElementsByTagName('result')[0].getAttribute('value');
                if (strResult == "OK")
                {
                	var lbInfo = xmlhttp.responseXML.documentElement.getElementsByTagName('info')[0];
                	if(lbInfo)
                	{
                		LIGHTBOX_curLBInfo = lbInfo;
                		$('lightbox_name').update(lbInfo.getAttribute('truncatedname'));
                		LIGHTBOX_canCreate = lbInfo.getAttribute('cancreate');
                		for (var i = 0; i < LIGHTBOX_OnChangeHandlers.length; ++i)
						{
							LIGHTBOX_OnChangeHandlers[i](true, lbInfo);
						}
					}
					LIGHTBOX_xmlContents = xmlhttp.responseXML.documentElement;
					var objContentsNode = LIGHTBOX_xmlContents.getElementsByTagName('contents')[0];
					var arrContents = objContentsNode.childNodes;
					var arrLBContents = new Array();
					for (var i = 0; (i < arrContents.length); i++)
					{
						arrLBContents.push(arrContents[i].getAttribute('id'));
					}
					var slbInfo = xmlhttp.responseXML.documentElement.getElementsByTagName('slb');
					if(slbInfo)
					{
						LIGHTBOX_arrAccessibleLBs = new Array();
						for(var i=0; i<slbInfo.length; i++)
						{
							LIGHTBOX_arrAccessibleLBs.push(new Array(slbInfo[i].getAttribute('id'), slbInfo[i].getAttribute('name'), slbInfo[i].getAttribute('candelete'), slbInfo[i].getAttribute('canedit'), slbInfo[i].getAttribute('createdbyuser'), slbInfo[i].getAttribute('creator')));
						}
					}
					for (var i = 0; i < LIGHTBOX_OnClearHandlers.length; ++i)
                    {
                        LIGHTBOX_OnClearHandlers[i]();
                    }
                    for (var i = 0; i < LIGHTBOX_OnAddAssetArrayHandlers.length; ++i)
                    {
                        LIGHTBOX_OnAddAssetArrayHandlers[i](arrLBContents);
                    }
                }
            }
        }
    };
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('action=selectslb&containerid=' + nID);
}
function LIGHTBOX_RemoveAsset(nID)
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "lightbox.tlx", true);
    xmlhttp.onreadystatechange = function()
    {
        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
        {
            if (Sarissa.getParseErrorText(xmlhttp.responseXML) == Sarissa.PARSED_OK)
            {
                var strResult = xmlhttp.responseXML.documentElement.getElementsByTagName('result')[0].getAttribute('value');
                if (strResult == "OK")
                {
                    LIGHTBOX_bContentsRequiresRefresh = true;
                    for (var i = 0; i < LIGHTBOX_OnRemoveAssetHandlers.length; ++i)
                    {
                        LIGHTBOX_OnRemoveAssetHandlers[i](nID);
                    }
                }
            }
        }
    };
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('action=remove&asset=' + nID);
}
function LIGHTBOX_RemoveAssetArray(arrIDs)
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "lightbox.tlx", true);
    xmlhttp.onreadystatechange = function()
    {
        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
        {
            if (Sarissa.getParseErrorText(xmlhttp.responseXML) == Sarissa.PARSED_OK)
            {
                var strResult = xmlhttp.responseXML.documentElement.getElementsByTagName('result')[0].getAttribute('value');
                if (strResult == "OK")
                {
                    LIGHTBOX_bContentsRequiresRefresh = true;
                    for (var i = 0; i < LIGHTBOX_OnRemoveAssetArrayHandlers.length; ++i)
                    {
                        LIGHTBOX_OnRemoveAssetArrayHandlers[i](arrIDs);
                    }
                }
            }
        }
    };
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('action=removearray&assetarray=' + arrIDs.join(','));
}
function LIGHTBOX_Clear()
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "lightbox.tlx", true);
    xmlhttp.onreadystatechange = function()
    {
        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
        {
            if (Sarissa.getParseErrorText(xmlhttp.responseXML) == Sarissa.PARSED_OK)
            {
                var strResult = xmlhttp.responseXML.documentElement.getElementsByTagName('result')[0].getAttribute('value');
                if (strResult == "OK")
                {
                    LIGHTBOX_bContentsRequiresRefresh = true;
                    for (var i = 0; i < LIGHTBOX_OnClearHandlers.length; ++i)
                    {
                        LIGHTBOX_OnClearHandlers[i]();
                    }
                }
            }
        }
    };
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('action=clear');
}
function LIGHTBOX_GetContents(funcCallBack, nSuggestedLimit)
{
    if (!nSuggestedLimit)
    {
        nSuggestedLimit = 0;
    }
    if (LIGHTBOX_bContentsRequiresRefresh || (nSuggestedLimit > LIGHTBOX_xmlContents_CurrentLimit))
    {
        var xmlhttp = new XMLHttpRequest();
        if (self.location.protocol == 'https:')
        {
	        xmlhttp.open("GET", "lightbox.tlx?action=getcontents&secure=1&limit=" + nSuggestedLimit, true);
		}
		else
		{
			xmlhttp.open("GET", "lightbox.tlx?action=getcontents&limit=" + nSuggestedLimit, true);
		}
        xmlhttp.onreadystatechange = function()
        {
            if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
            {
                if (Sarissa.getParseErrorText(xmlhttp.responseXML) == Sarissa.PARSED_OK)
                {
                    LIGHTBOX_xmlContents = xmlhttp.responseXML.documentElement;
                    LIGHTBOX_xmlContents_CurrentLimit = nSuggestedLimit;
                    LIGHTBOX_bContentsRequiresRefresh = false;
                    var lbInfo = xmlhttp.responseXML.documentElement.getElementsByTagName('info')[0];
                    if(lbInfo)
                    {
                    	LIGHTBOX_curLBInfo = lbInfo;
	                    LIGHTBOX_canCreate = lbInfo.getAttribute('cancreate');
	                    var lbName = $('lightbox_name');
	                    if(lbName)
	                    {
	                    	lbName.update(lbInfo.getAttribute('truncatedname'));
						}
						for (var i = 0; i < LIGHTBOX_OnChangeHandlers.length; ++i)
						{
							LIGHTBOX_OnChangeHandlers[i](false, lbInfo);
						}
					}
					var slbInfo = xmlhttp.responseXML.documentElement.getElementsByTagName('slb');
					if(slbInfo)
					{
						LIGHTBOX_arrAccessibleLBs = new Array();
						for(var i=0; i<slbInfo.length; i++)
						{
							LIGHTBOX_arrAccessibleLBs.push(new Array(slbInfo[i].getAttribute('id'), slbInfo[i].getAttribute('name'), slbInfo[i].getAttribute('candelete'), slbInfo[i].getAttribute('canedit'), slbInfo[i].getAttribute('createdbyuser'), slbInfo[i].getAttribute('creator')));
						}
					}
                    if (funcCallBack)
                    {
                        funcCallBack(LIGHTBOX_xmlContents);
                    }
                }
            }
        };
        xmlhttp.send('');
    }
    else
    {
        if (funcCallBack)
        {
            funcCallBack(LIGHTBOX_xmlContents);
        }
    }
}
function LIGHTBOX_AddAssetArrayToCollection(arrIDs, nCollectionID, bRedirectToCollection)
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "lightbox.tlx", true);
    xmlhttp.onreadystatechange = function()
    {
        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
        {
            if (Sarissa.getParseErrorText(xmlhttp.responseXML) == Sarissa.PARSED_OK)
            {
                var strResult = xmlhttp.responseXML.documentElement.getElementsByTagName('result')[0].getAttribute('value');
                if (strResult == "OK")
                {
                    if (bRedirectToCollection)
                    {
                        document.location.href = 'viewcollection.tlx?collectionid=' + nCollectionID + '&pictureid=' + arrIDs[0];
                    }
                    else
                    {
                        alert ('The files were added successfully');
                    }
                }
                else
                {
					alert ('Sorry, the files could not be added');
				}
            }
        }
    };
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('action=addarraytocollection&collectionid=' + nCollectionID + '&assetarray=' + arrIDs.join(','));
}
function LIGHTBOX_MoveAssetArrayToAlbum(arrIDs, nContainerID, bRedirectToAlbum)
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "lightbox.tlx", true);
    xmlhttp.onreadystatechange = function()
    {
        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
        {
            if (Sarissa.getParseErrorText(xmlhttp.responseXML) == Sarissa.PARSED_OK)
            {
                var strResult = xmlhttp.responseXML.documentElement.getElementsByTagName('result')[0].getAttribute('value');
                if (strResult == "OK")
                {
                    if (bRedirectToAlbum)
                    {
                        document.location.href = 'viewcontainer.tlx?containerid=' + nContainerID + '&pictureid=' + arrIDs[0];
                    }
                    else
                    {
                        alert ('The files were moved successfully');
                    }
                }
                else
                {
					alert ('Sorry, the files could not be moved');
				}
            }
        }
    };
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('action=movearraytoalbum&containerid=' + nContainerID + '&assetarray=' + arrIDs.join(','));
}
function LIGHTBOX_AddAssetArrayToContainer(arrIDs, nCollectionID, bRedirectToCollection)
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "lightbox.tlx", true);
    xmlhttp.onreadystatechange = function()
    {
        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
        {
            if (Sarissa.getParseErrorText(xmlhttp.responseXML) == Sarissa.PARSED_OK)
            {
                var strResult = xmlhttp.responseXML.documentElement.getElementsByTagName('result')[0].getAttribute('value');
                if (strResult == "OK")
                {
                    if (bRedirectToCollection)
                    {
                        document.location.href = 'viewcollection.tlx?containerid=' + nCollectionID + '&pictureid=' + arrIDs[0];
                    }
                    else
                    {
                        alert ('The files were added successfully');
                    }
                }
                else
                {
   					alert ('Sorry, the files could not be added');
				}
            }
        }
    };
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('action=addarraytocollection&containerid=' + nCollectionID + '&assetarray=' + arrIDs.join(','));
}
function LIGHTBOX_RemoveAssetFromCollection(nID, nCollectionID, onSuccess, onFailure)
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "lightbox.tlx", true);
    xmlhttp.onreadystatechange = function()
    {
        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
        {
            if (Sarissa.getParseErrorText(xmlhttp.responseXML) == Sarissa.PARSED_OK)
            {
                var strResult = xmlhttp.responseXML.documentElement.getElementsByTagName('result')[0].getAttribute('value');
                if (strResult == "OK")
                {
                    if (onSuccess)
                    {
                        onSuccess();
                    }
                    return;
                }
            }
            if (onFailure)
            {
                onFailure();
            }
        }
    };
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('action=removefromcollection&collectionid=' + nCollectionID + '&asset=' + nID);
}

function LIGHTBOX_LinkAsset(nID)
{
	var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "lightbox.tlx", true);
    xmlhttp.onreadystatechange = function()
    {
        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
        {
            if (Sarissa.getParseErrorText(xmlhttp.responseXML) == Sarissa.PARSED_OK)
            {
                var strResult = xmlhttp.responseXML.documentElement.getElementsByTagName('result')[0].getAttribute('value');
                if (strResult == "OK")
                {
                	if(LIGHTBOX_OnLinkHandlers.length > 0)
                	{
	                	for (var i = 0; i < LIGHTBOX_OnLinkHandlers.length; ++i)
	                    {
	                        LIGHTBOX_OnLinkHandlers[i]();
	                    }
					}
					else
					{
	                    alert("Linked lightbox contents successfully");
					}
                }
            }
        }
    };
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('action=linklightboxtoasset&asset=' + nID);
}
function LIGHTBOX_ShowLBDropDown()
{
	if(!LIGHTBOX_menuVisible)
	{
		LIGHTBOX_menuVisible = true;
		var element = $('slbholder');
		var update = $('slbListHolder');
		var iefix = $('slbListHolder_iefix');

        var nLightboxesCreatedByCurrentUser = 0;
        var nLightboxesSharedWithCurrentUser = 0;
        for (var i = 0; i < LIGHTBOX_arrAccessibleLBs.length; i++)
        {
            if (LIGHTBOX_arrAccessibleLBs[i][4] == "1")
            {
                nLightboxesCreatedByCurrentUser++;
            }
            else
            {
                nLightboxesSharedWithCurrentUser++;
            }
        }

		var strHTML = "";
		if(LIGHTBOX_curLBInfo)
		{
			var canCreate = LIGHTBOX_curLBInfo.getAttribute("cancreate");
			var canEdit = LIGHTBOX_curLBInfo.getAttribute("canedit");
			var canDelete = LIGHTBOX_curLBInfo.getAttribute("candelete");
			var canSave = LIGHTBOX_curLBInfo.getAttribute("cansave");
			var lbID = LIGHTBOX_curLBInfo.getAttribute('id');
			if(canEdit || canDelete || canSave)
			{
				strHTML += '<div style="padding:3px;" ><strong>Lightbox Actions</strong></div>';
				strHTML += '<ul class="userselect" style="padding:5px;padding-top:0;margin:0;white-space:nowrap;">';
				if(canEdit)
				{
					strHTML += '<li class="userselect"><span onclick="LIGHTBOX_NewLightbox()" ><img src="menugraphics/add2.png" width="16" height="16" style="vertical-align:middle;" />&nbsp;&nbsp;';
					strHTML += "New Lightbox";
					strHTML += '</span></li>';
				}
				if(canEdit)
				{
					strHTML += '<li class="userselect"><span onclick="document.location.href=\'editlightbox.tlx?containerid=current\'" ><img src="menugraphics/edit.png" width="16" height="16" style="vertical-align:middle;" />&nbsp;&nbsp;Edit';
					if(canCreate)
					{
						strHTML += ' / Share';
					}
					strHTML += ' Lightbox</span></li>';
				}
				if(canDelete)
				{
					strHTML += '<li class="userselect"><span onclick="if(confirm(\'Are you sure that you wish to delete this lightbox?\'))document.location.href=\'dodelcontainer.tlx?containerid=' + LIGHTBOX_curLBInfo.getAttribute('id') + '\'" ><img src="menugraphics/delete2.png" width="16" height="16" style="vertical-align:middle;" />&nbsp;&nbsp;Delete Lightbox</span></li>';
				}
				if(canSave)
				{
					strHTML += '<li class="userselect"><span onclick="document.location.href=\'editcollection.tlx?collectionid=new&source=lightbox\'" ><img src="menugraphics/folder_add.png" width="16" height="16" style="vertical-align:middle;" />&nbsp;&nbsp;Save Lightbox as Collection</span></li>';
				}
				strHTML += "</ul>";
			}
		}
		
        
        var bLBFound = false;
		if(LIGHTBOX_arrAccessibleLBs.length > 0)
		{
		    if (nLightboxesSharedWithCurrentUser > 0)
		    {
                strHTML += '<div style="padding:3px;"><strong>Lightboxes created by you</strong></div>';
            }
            else
            {
                strHTML += '<div style="padding:3px;"><strong>Your Lightboxes</strong></div>';
            }
            strHTML += '<ul class="userselect" style="padding:5px;padding-top:0;margin:0;white-space:nowrap;">';
			for (var i = 0; i < LIGHTBOX_arrAccessibleLBs.length; i++)
			{
                if (LIGHTBOX_arrAccessibleLBs[i][4] == "1")
                {
				    var containerID = LIGHTBOX_arrAccessibleLBs[i][0];
				    if(!containerID) containerID = "0";
                    
                    strHTML += '<li class="userselect"><span onclick="LIGHTBOX_SelectSLB(' + containerID + ')" >' + LIGHTBOX_arrAccessibleLBs[i][1] + "</span>";
                    if(LIGHTBOX_arrAccessibleLBs[i][3])
                    {
                        strHTML += '&nbsp;<img onclick="javascript:document.location.href=\'editlightbox.tlx?selectlb=1&containerid=' + containerID + '\';" style="vertical-align:middle" src="menugraphics/edit.png" /></a>';
                    }
                    if(LIGHTBOX_arrAccessibleLBs[i][2] && nLightboxesCreatedByCurrentUser > 1)
                    {                        
                        strHTML += '&nbsp;<img onclick="javascript:if(confirm(\'Are you sure that you wish to delete this lightbox?\'))document.location.href=\'dodelcontainer.tlx?containerid=' + containerID + '&returnurl=' + escape(document.location.href) + '\';" style="vertical-align:middle" src="menugraphics/delete2.png" /></a>';
                    }
                    strHTML += '</li>';
                    bLBFound = true;
                }
			}
            if (!bLBFound)
            {
                strHTML += '<li style="font-style:italic;">No lightboxes are available</li>';
            }
            strHTML += "</ul>";
            
            if (nLightboxesSharedWithCurrentUser > 0)
            {
                strHTML += '<div style="padding:3px;"><strong>Lightboxes shared with you</strong></div>';
                strHTML += '<ul class="userselect" style="padding:5px;padding-top:0;margin:0;white-space:nowrap;">';
                for (var i = 0; i < LIGHTBOX_arrAccessibleLBs.length; i++)
    			{
                    if (LIGHTBOX_arrAccessibleLBs[i][4] != "1")
                    {
                        var containerID = LIGHTBOX_arrAccessibleLBs[i][0];
                        if(!containerID) containerID = "0";
                    
                        strHTML += '<li class="userselect"><span onclick="LIGHTBOX_SelectSLB(' + containerID + ')" >' + LIGHTBOX_arrAccessibleLBs[i][1] + (LIGHTBOX_arrAccessibleLBs[i][5] ? " (" + LIGHTBOX_arrAccessibleLBs[i][5] + ")" : "" ) + "</span>";
                        if(LIGHTBOX_arrAccessibleLBs[i][3])
                        {
                            strHTML += '&nbsp;<img onclick="javascript:document.location.href=\'editlightbox.tlx?selectlb=1&containerid=' + containerID + '\';" style="vertical-align:middle" src="menugraphics/edit.png" /></a>';
                        }
                        if(LIGHTBOX_arrAccessibleLBs[i][2])
                        {
                            strHTML += '&nbsp;<img onclick="javascript:if(confirm(\'Are you sure that you wish to delete this lightbox?\'))document.location.href=\'dodelcontainer.tlx?containerid=' + containerID + '&returnurl=' + escape(document.location.href) + '\';" style="vertical-align:middle" src="menugraphics/delete2.png" /></a>';
                        }
                        strHTML += '</li>';
                    }
    			}
            }
		}
		else
		{
            strHTML += '<ul class="userselect" style="padding:5px;padding-top:0;margin:0;">';
			strHTML += '<li style="font-style:italic;">No lightboxes are available</li>';
            strHTML += "</ul>";
		}
		update.innerHTML = strHTML;
        update.style.width = '50px';
        update.style.height = '50px';
		if(Element.getStyle(update, 'display')=='none')
		{
			if(!update.style.position || update.style.position=='absolute') {
			  update.show();
			  update.style.position = 'absolute';
			  Position.clone(element, update, {
				setHeight: false, 
				setWidth: false,
				offsetTop: element.offsetHeight
			  });
			  update.hide();
			}
			// Tweak height and width to avoid scroll bars or excessive padding.
			// We make visible to get the browser to set the width and
			// height, adjust the dimensions and make hidden again. The 4 px bias
			// is for IE. The height tweak is not needed if there is no height
			// specified in the CSS. But this code accounts for older sites.
			// The width tweak is always required.
                update.style.display='';
                update.scrollHeight;
                update.scrollWidth;
                update.style.height = update.scrollHeight+4+'px';
                update.style.overflow = 'auto';
                update.style.width = update.scrollWidth+7+'px';
                update.style.display='none';
                update._dimensionsSet = true;
                // End tweak
            Effect.Appear(update,{duration:0.15});
		}
		if(!this.iefix && 
		  (Prototype.Browser.IE) &&
		  (Element.getStyle(update, 'position')=='absolute')) {
		  new Insertion.After(update, 
		   '<iframe id="slbListHolder_iefix" '+
		   'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
		   'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
		  iefix = $('slbListHolder_iefix');
		}
		if(iefix) setTimeout(function () { Position.clone(update, iefix, {setTop:(!update.style.height)});
		iefix.style.zIndex = 1;
		update.style.zIndex = 2;
		Element.show(iefix);}, 50);
		document.observe("click", LIGHTBOX_HideLBDropDown);
	}
}
function LIGHTBOX_HideLBDropDown(event) 
{
    setTimeout(function(){
    	var element = $('slbholder');
		var update = $('slbListHolder');
		var iefix = $('slbListHolder_iefix');
    	if(Element.getStyle(update, 'display')!='none')
    	{
    		new Effect.Fade(update,{duration:0.15});
		}
    	if(iefix) Element.hide(iefix);
    	LIGHTBOX_menuVisible = false;
    	}, 250);
    document.stopObserving("click", LIGHTBOX_HideLBDropDown);
}

function LIGHTBOX_SaveLightbox()
{
	var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "lightbox.tlx", true);
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('action=savelightbox');
}
function LIGHTBOX_NewLightbox()
{
	var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "lightbox.tlx", true);
    xmlhttp.onreadystatechange = function()
    {
        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
        {
            if (Sarissa.getParseErrorText(xmlhttp.responseXML) == Sarissa.PARSED_OK)
            {
                var strResult = xmlhttp.responseXML.documentElement.getElementsByTagName('result')[0].getAttribute('value');
                if (strResult == "OK")
                {
                    LIGHTBOX_bContentsRequiresRefresh = true;
                    for (var i = 0; i < LIGHTBOX_OnClearHandlers.length; ++i)
                    {
                        LIGHTBOX_OnClearHandlers[i]();
                    }
                    return;
                }
            }
            if (onFailure)
            {
                onFailure();
            }
        }
    };
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('action=newlightbox');
}

