// Build flyout menu
var FlyoutMenu = "";
function BuildMenu (ElementName)
{
	// Setup flyout menu
	FlyoutMenu = new MultiMenu(ElementName, true);
}

// Photo album image popup
function ShowSlideshow (Src, Width, Height, ParentDiv)
{
    // Build array of thumbs
    var AllHrefs = $(ParentDiv).getElementsByTagName("A");

    // Get title, next, previous
    var Title = "&nbsp;";
    var LoadPrevious = "alert('There are no previous images.');";
    var LoadNext = "alert('There are no more images.');";
    for (var i = 0; i < AllHrefs.length; i++)
    {
        // Find selected image
        if (AllHrefs[i].onclick.toString().toLowerCase().indexOf(Src.toLowerCase()) > -1)
        {
            // Vars
            var OnClickArray, ArrayIndex;

            // Previous
            if (i == 0) ArrayIndex = AllHrefs.length - 1; else ArrayIndex = i - 1;
            OnClickArray = AllHrefs[ArrayIndex].onclick.toString().split("ShowSlideshow");
            LoadPrevious = "ShowSlideshow" + OnClickArray[1].substr(0, OnClickArray[1].length - 2).replace(/\"/gi, "'");

            // Next
            if (i == AllHrefs.length - 1) ArrayIndex = 0; else ArrayIndex = i + 1;
            OnClickArray = AllHrefs[ArrayIndex].onclick.toString().split("ShowSlideshow");
            LoadNext = "ShowSlideshow" + OnClickArray[1].substr(0, OnClickArray[1].length - 2).replace(/\"/gi, "'");
            
            // Get image title
            Title = AllHrefs[i].getAttribute("title").toString() == "" ? "&nbsp;" : AllHrefs[i].getAttribute("title");

            // Done
            break;
        }
    }    

    // Create javascript
    var CloseJs = "clearInterval($('PopupImage').ResizeListener);closeModal();return false;";

    // Build HTML
    var Html = 
    "<div class=\"Slideshow\">" +
        "<img id=\"PopupImage\" src=\"" + Src + "\" width=\"" + Width + "\" height=\"" + Height + "\" alt=\"\" />" +
        "<div class=\"Title\">" + Title + "</div>" +
        "<div class=\"Nav\">" +
            (AllHrefs.length > 1 ?
            "<a href=\"\" onclick=\"return " + LoadPrevious + "\" class=\"Previous\"><img src=\"/Images/Previous.gif\" /></a>" +
            "<a href=\"\" onclick=\"return " + LoadNext + "\" class=\"Next\"><img src=\"/Images/Next.gif\" /></a>" : "") +
            "<a href=\"\" onclick=\"" + CloseJs + "\" class=\"Close\"><img src=\"/Images/Close.gif\" /></a>" +
        "</div>" +
    "</div>";

    // Clear current listener
    // if ($("PopupImage") && $("PopupImage").ResizeListener) clearInterval($("PopupImage").ResizeListener); 
   
    // Shop popup    
    showModal(Html, "auto", true); 
    // setImageSize(Width, Height); 

    // Create listener   
    // $("PopupImage").ResizeListener = setInterval("setImageSize(" + Width + ", " + Height + ")", 50);
    
    // Ignore click
    return false;
}