function AEgallery(pAEid, pAE_HTML_Node, pAE_ParamList, pAE_Parent)
{
/*
Gallery active element, which requests a list of files from the server, constructs the HTML to create
a display of images which are styled by the css.
*/
    
    D.debugStartFunction("AEgallery", arguments);
    
    this.superclass = activeElement;
    this.superclass(pAEid, "AEgallery", "", pAE_HTML_Node, pAE_ParamList, pAE_Parent);
    
    this.aeInitialise = function() // Overloads master aeInitialise function
    {
        /*
        Overrides aeInitialise from master activeElement class.
        
        Called after new AE has been created.  Populates HTML nodes with startup text and
        performs any other initialisation for this AE.

        Request list of images from server, based on parameters supplied.
        (Response will be processed in aeProcessResponseData method)
        */
  
        D.debugStartFunction("AEgallery:aeInitialise", arguments);
        
        var Header = new Array;
        var Parameters = new Array;
        var DataRequest;
        var RequestXML;
        var RequestDetails;

        this.aeSetStatus("RequestingData");
        D.debug("Sending Request");
        
        Header['msgseqnum']   = this.aeGetMsgSeqNum();
        Header['requesttype'] = 'datarequest';
        Header['loggingflag'] = 'true';
        Header['aetype']      = this.aeGetAEtype();
        Header['aeid']        = this.aeGetAEid();

        RequestXML = this.aeCreateRequestHeaderXML(Header);

        // The payload for the Imagelist request will consist of the request type (i.e. Imagelist) and
        // the (sub)directory for which a list of files will be returned.
        RequestDetails = this.aeXMLnodeCreate('datarequesttype', 'Imagelist');
        RequestDetails += this.aeXMLnodeCreate('directory', "Gallery/" + this.aeGetScreenName());
        RequestXML += this.aeCreateDataRequestXML(RequestDetails);
        
        DataRequest = this.aeXMLnodeCreate('activeelementrequest', RequestXML);
        
        this.aeSendRequest(DataRequest);
    
        // Propogate to any controlled AEs under this one
        
        for (var i=0; i<this.AE_controlledAE_Count; i++)
        {
            this.AE_controlledAE_List[i].aeInitialise();
        }
        
        D.debugEndFunction("aeInitialise");

    }
    
    this.aeScreenChange = function(pScreen)
    {
        D.debugStartFunction("AEgallery.aeScreenChange", arguments);
        
        // Cascade to all child AEs
        
        for (var i=0; i<this.AE_controlledAE_Count; i++)
        {
            D.debug("Cascading to AEid " + this.AE_controlledAE_List[i].AE_AEid);
            this.AE_controlledAE_List[i].aeScreenChange(pScreen);
        }
        D.debugEndFunction();
    }

    this.aeUpdateContent = function(pXML)
    {
        D.debugStartFunction("AEgallery:aeUpdateContent", arguments);
        
        var singleImageHTML;
        var galleryHTML = "";
    	var IMGmaxHeight = 125; // Replace with values from parameter, width as well
        var IMGmaxWidth = 75;
        var PHPthumbDir = AE_ARCHITECTURE_HOME + "/phpthumb";
        var i;

        var dir = extractNodeValue(pXML, "dir");

        var imageArray = pXML.getElementsByTagName("file");
        var numImages = imageArray.length;
        
        for (i=0; i<numImages; i++)
        {
            var image   = extractNodeValue(imageArray[i], "filename");
            var title   = extractNodeValue(imageArray[i], "title");
            var height  = extractNodeValue(imageArray[i], "height");
            var width   = extractNodeValue(imageArray[i], "width");
            var caption = extractNodeValue(imageArray[i], "caption");
            var url = dir + "/" + image;
            var phpthumburl = AE_WEBSITE_HOME_PHPTHUMB + "/" + dir + "/" + image;
    
            // Need to calculate Thumbnail dimensions so that thumbnail will fit within an IMG tag of IMGmaxHeight X IMGmaxWidth
            // Compare scaling factor for width and height and take smaller factor (greatest reduction) to ensure both dimensions
            // fit.
            
            var heightScale = IMGmaxHeight / height;
            var widthScale = IMGmaxWidth / width;
            
            scale = Math.min(heightScale, widthScale);
            var IMGheight = Math.floor(scale * height + 0.5);
            var IMGwidth = Math.floor(scale * width+ 0.5);
     
            singleImageHTML =   "<div class=\"gallery-image\">" +
                                "<a href=\"./" +
                                url + 
                                "\" target=\"+blank\"><img src=\"" + PHPthumbDir + "/phpThumb.php?w=" + IMGwidth + "&h=" + IMGheight + "&src=/" + 
                                phpthumburl +
                                "\" alt=\"" + // for IE to display hint text (see http://drupal.org/node/35821)
                                caption + 
                                "\" title=\"" + // for Firefox to display hint text
                                caption + 
                                "\" /></a><p>" +
                                caption + 
                                "</p></div>";

            galleryHTML += singleImageHTML;
        }
        this.aeUpdateHTML_Nodes(galleryHTML);
        D.debugEndFunction();
    }
    

    this.aeCreateDataRequestXML = function(pRequestDetails)
    {
        var XML;
        
        XML = this.aeXMLnodeCreate('datarequest', pRequestDetails);
        
        return XML;
    }
    
    this.aeProcessResponseData = function(pXML)
    {
        /*
        This function overrides that of the parent class.
         
        From the file list returned, generate the XHTML create the gallery
        Note that associated CSS will style the slideshow (inc. showing/hiding images)
        */
        
        D.debugStartFunction("aeProcessResponseData", arguments);
        
        /* Pass the XML to Update Content which will format the XHTML and update the DOM */
          
        this.aeUpdateContent(pXML);

        D.debugEndFunction();        
    }

    this.aeInitialise();
    /* this.aeUpdateContent(); */
    
    D.debugEndFunction("AEslideshow");
}
