function Gallery(divGalleryID,source,width,height,bgcolor) {
        
    //variables
    this.divGalleryID = divGalleryID;
    this.divGallery = document.getElementById(divGalleryID);
    this.divGalleryImage;
    this.divGalleryComments;
    this.divGalleryPopup = null;
    this.width = width;
    this.height = height;
    this.bgcolor = bgcolor;
    this.imageWidth = 440;
    this.xml = null;
    this.delay = 5000;
    this.commentsHeight = 0;
        
    //constructor
    this.Constructor = Constructor;
    function Constructor() {
        this.divGallery.className = "gallery5";
        this.divGallery.style.height = height + "px"
        this.divGallery.style.width = width + "px"
        this.divGallery.style.overflow = "visible";
        //divGalleryImage
        this.divGalleryImage = document.createElement("DIV");
        this.divGalleryImage.innerHTML = "";        
        this.divGalleryImage.style.height = (height - this.commentsHeight) + "px"        
        this.divGalleryImage.style.width = (width) + "px"        
        this.divGalleryImage.style.overflow = "hidden";
        this.divGalleryImage.className = "image";
        if (this.bgcolor!="") {
            this.divGalleryImage.style.backgroundColor = this.bgcolor;
            this.divGallery.style.borderWidth = "0px";
        }
        this.divGallery.appendChild(this.divGalleryImage);
        //divGalleryPopup
        this.divGalleryPopup = document.createElement("DIV")
        this.divGalleryPopup.className = "gallery5Popup";
        this.divGalleryPopup.id = divGalleryID + "_popup";
        this.divGalleryPopup.style.position = "absolute";
        this.divGalleryPopup.style.display = "none";
        this.divGallery.parentNode.insertBefore(this.divGalleryPopup, this.divGallery);
        //divGalleryComments
        this.divGalleryComments = document.createElement("DIV");
        this.divGalleryComments.className = "comments";
        this.divGallery.appendChild(this.divGalleryComments);        
        //custom
        this.divGalleryComments.style.display = "none";
        //load thumbs
        this.thumbsWidth = (width-36-36);
        if (source!="") this.LoadFromSource(source);
    }
    
    //methods
    this.LoadFromSource = LoadFromSource;
    function LoadFromSource(source) {
        var objGallery = this; 
        loadXMLDoc(source, function(result){    
            objGallery.xml = result;
            objGallery.imageWidth = parseInt(result.documentElement.getAttribute("width2"));
            objGallery.delay = parseInt(result.documentElement.getAttribute("delay"));
            if (objGallery.delay==0) objGallery.delay = 5000;
            objGallery.ShowImage(0);
        });
    }
    this.ShowImage = ShowImage;
    function ShowImage(index) {
        var pics = this.xml.getElementsByTagName("pic");
        if (index==pics.length) index = 0;
        var pic = pics[index];
        var image1Url = getElementTextNS("","image1", pics[index], 0);
        var image2Url = getElementTextNS("","image2", pics[index], 0);
        var image3Url = getElementTextNS("","image3", pics[index], 0);
        var imageName = getElementTextNS("","name", pics[index], 0);
        var imageDescription = getElementTextNS("","description", pics[index], 0);
        var escale = parseInt(getElementTextNS("","width", pics[index], 0)) / parseInt(getElementTextNS("","height", pics[index], 0));
        var imageWidth = this.imageWidth;
        var imageHeight = parseInt(this.imageWidth / escale);
        var imageMarginLeft = 0;
        var imageMarginTop = 0;
        var wAvailable = this.width;
        var hAvailable = (this.height - this.commentsHeight);
        var html = ""
        if (imageWidth<=wAvailable && imageHeight<=hAvailable) {
            imageMarginLeft = ((wAvailable-imageWidth)/2);
            imageMarginTop = ((hAvailable-imageHeight)/2);
        } else if (imageWidth<=wAvailable && imageHeight>hAvailable) {
            imageHeight = hAvailable;             
            imageWidth = parseInt(imageHeight * escale);
            imageMarginLeft = parseInt((wAvailable-imageWidth)/2);
        } else if (imageWidth>wAvailable && imageHeight<=hAvailable) {
            imageWidth = wAvailable;             
            imageHeight = parseInt(imageWidth / escale);
            imageMarginTop = parseInt((hAvailable-imageHeight)/2);
        } else if (imageWidth>wAvailable && imageHeight>hAvailable) {
            if ((imageWidth-wAvailable) > (imageHeight-hAvailable)) {            
                imageWidth = wAvailable;             
                imageHeight = parseInt(imageWidth / escale);
                imageMarginTop = parseInt((hAvailable-imageHeight)/2);
            } else {
                imageHeight = hAvailable;             
                imageWidth = parseInt(imageHeight * escale);
                imageMarginLeft = parseInt((wAvailable-imageWidth)/2);
           }
        } else {
        }        
        html = "<img id='" + this.divGalleryID + "_image' src='" + image2Url + "' onload='fadeTo(this.id,100,25)' style='width:" + imageWidth + "px;height:" + imageHeight + "px;margin-left:" + imageMarginLeft + "px;margin-top:" + imageMarginTop + "px;opacity:0; filter:alpha(opacity=0);cursor:pointer;' onclick=\"" + this.divGalleryID + "Object.ShowImageBig(this, " + index + ")\"  >";
        this.divGalleryImage.innerHTML = html;  
        html = "<b>" + (index+1) + "/" + pics.length + ".- " + imageName + "</b>";
        html += "<br/>";
        html += imageDescription;
        this.divGalleryComments.innerHTML = html;        
        setTimeout(this.divGalleryID + "Object.ShowImage(" + (index+1) + ")", this.delay)
        if (this.divGalleryPopup.style.display == "block") {
            this.ShowImageBig(this.divGallery, index);
        };
    }
    
    this.ShowImageBig = ShowImageBig;
    function ShowImageBig(sender, index) {
        var html = ""
        var pics = this.xml.getElementsByTagName("pic");
        var pic = pics[index];
        var imageUrl1 = getElementTextNS("","image1", pics[index], 0);
        var imageUrl2 = getElementTextNS("","image2", pics[index], 0);
        var imageUrl3 = getElementTextNS("","image3", pics[index], 0);
        var imageName = getElementTextNS("","name", pics[index], 0);
        var imageDescription = getElementTextNS("","description", pics[index], 0);        
        var imageScale = getAbsoluteWidth(sender) / getAbsoluteHeight(sender);
        if (this.divGalleryPopup.style.display == "block") {
            html += "<img id='" + this.divGalleryID + "_imagePopup' src='" + imageUrl2 + "' onclick='" + divGalleryID + "Object.CloseImageBig()' onload='" + this.divGalleryID + "Object.ResizeImageEnd()' style='opacity:0; filter:alpha(opacity=0);' />";
            html += "<div class='detail'><b>" + imageName +"</b><br/>" + imageDescription + "</div>"
            this.divGalleryPopup.innerHTML = html;
        } else {
            html += "<img id='" + this.divGalleryID + "_imagePopup' src='" + imageUrl2 + "' onload='" + this.divGalleryID + "Object.ResizeImage(this, " + index + ", " + imageScale + ")' style='width:1px;' onclick='" + divGalleryID + "Object.CloseImageBig()' />";
            html += "<div class='detail'><b>" + imageName +"</b><br/>" + imageDescription + "</div>"
            this.divGalleryPopup.innerHTML = html;
            this.divGalleryPopup.style.position = "absolute";
            this.divGalleryPopup.style.left = getAbsoluteLeft(sender.parentNode) + "px";
            this.divGalleryPopup.style.top = getAbsoluteTop(sender.parentNode) + "px"
            this.divGalleryPopup.style.width = getAbsoluteWidth(sender.parentNode) + "px";
            this.divGalleryPopup.style.height = getAbsoluteHeight(sender.parentNode) + "px";
            this.divGalleryPopup.style.display = "block";      
        }
    }
    this.ResizeImage = ResizeImage;
    function ResizeImage(sender, index, imageScale) {        
        var finalWidth = this.imageWidth;
        var finalHeight = parseInt(finalWidth / imageScale);
        var finalLeft = parseInt(getAbsoluteLeft(this.divGallery) + getAbsoluteWidth(this.divGallery)/2 - finalWidth/2);
        var finalTop = parseInt(getAbsoluteTop(this.divGallery) + getAbsoluteHeight(this.divGallery)/2 - finalHeight/2);        
        resizeTo(this.divGalleryPopup.id, finalLeft, finalTop, finalWidth, finalHeight, divGalleryID + "Object.ResizeImageEnd();" );
    }
    this.ResizeImageEnd = ResizeImageEnd;
    function ResizeImageEnd() {
        var img = document.getElementById(this.divGalleryID + "_imagePopup");
        setOpacity(img, 1);
        img.style.width = "";
        img.style.height = "";
        fadeTo(img.id, 100, 10, null)
    }    
    this.CloseImageBig = CloseImageBig;
    function CloseImageBig() {
        this.divGalleryPopup.style.display = "none";
    }
    
     
    //call constructor
    this.Constructor();
       
}

