function Gallery(divGalleryID,source,width,height,bgcolor,fgcolor) {
        
    //variables
    this.divGallery = document.getElementById(divGalleryID);
    this.divGalleryImage;
    this.imgGalleryImage;
    this.divGalleryComments;
    this.divGalleryImageThumbs;
    this.divGalleryImageThumbsBackForward;
    this.width = width;
    this.thumbWidth = 60;
    this.thumbsWidth = 0;
    this.bgcolor = bgcolor;
    this.fgcolor = fgcolor;
    this.selectedIndex = 0;
    this.pageCount = 0;
        
    //constructor
    this.Constructor = Constructor;
    function Constructor() {
        this.divGallery.className = "gallery2";
        this.divGallery.style.height = height + "px"
        this.divGallery.style.width = width + "px"
        this.divGallery.style.overflow = "visible";
        if (this.bgcolor!="") this.divGallery.style.backgroundColor = this.bgcolor;
        //divGalleryImage
        this.divGalleryImage = document.createElement("DIV");
        this.divGalleryImage.innerHTML = "";        
        this.divGalleryImage.style.height = (height - this.thumbWidth - 6 - 2 - 28 - 28) + "px"        
        this.divGalleryImage.style.width = (width) + "px"
        this.divGalleryImage.style.overflow = "hidden";        
        this.divGalleryImage.className = "image";
        this.imgGalleryImage = document.createElement("IMG");
        this.imgGalleryImage.id = divGalleryID + "Image";
        this.imgGalleryImage.onload = function() {eval("if (" + divGalleryID + "Object) " + divGalleryID + "Object.ResizeImage();")}
        this.divGalleryImage.appendChild(this.imgGalleryImage);
        this.divGallery.appendChild(this.divGalleryImage);
        //divGalleryComments
        this.divGalleryComments = document.createElement("DIV");
        this.divGalleryComments.className = "comments";
        if (this.bgcolor!="") this.divGalleryComments.style.backgroundColor = this.bgcolor;
        if (this.fgcolor!="") this.divGalleryComments.style.color = this.fgcolor;
        this.divGallery.appendChild(this.divGalleryComments);        
        //divGalleryImageThumbs
        this.divGalleryImageThumbs = document.createElement("DIV");
        this.divGalleryImageThumbs.innerHTML = "";
        this.divGalleryImageThumbs.style.height = (this.thumbWidth+4) + "px"
        this.divGalleryImageThumbs.style.width = (width-6) + "px";
        this.divGalleryImageThumbs.className = "thumbs";
        if (this.bgcolor!="") this.divGalleryImageThumbs.style.backgroundColor = this.bgcolor;
        this.divGallery.appendChild(this.divGalleryImageThumbs);
        //divGalleryImageThumbs
        this.divGalleryImageThumbsBackForward = document.createElement("DIV");
        this.divGalleryImageThumbsBackForward.innerHTML = "" +
            "<a href='#' onclick=\"" + divGalleryID + "Object.ShowPreviousThumbs();return false;\">&lt&lt; " + getLocalizedString("anterior", "anterior", "previous") + "</a>" +
            "<label>1/5</label>" +
            "<a href='#' onclick=\"" + divGalleryID + "Object.ShowNextThumbs();return false;\">" + getLocalizedString("seg&uuml;ent", "siguiente", "next") + " &gt;&gt;</a>";
        this.divGalleryImageThumbsBackForward.style.width = (width - 6) + "px";
        this.divGalleryImageThumbsBackForward.className = "thumbsbackforward";
        if (this.bgcolor != "") this.divGalleryImageThumbsBackForward.style.backgroundColor = this.bgcolor;
        this.divGallery.appendChild(this.divGalleryImageThumbsBackForward);
        //load thumbs
        this.thumbsWidth = (width-36-36);
        if (source!="") this.LoadFromSource(source);
    }
    
    //methods
    this.LoadFromSource = LoadFromSource;
    function LoadFromSource(source) {
        var objGallery = this; 
        this.imgGalleryImage.src = "";
        this.divGalleryComments.innerHTML = "";
        this.divGalleryImageThumbs.innerHTML = "";
        this.selectedIndex = 0;
        this.pageCount = 0;
        this.RefreshButtons();
        loadXMLDoc(source, function(result) {
            var items = result.getElementsByTagName("pic");
            var html = "<table id='" + objGallery.divGallery.id + "_table' cellspacing='0' cellpadding='0'><tr>";
            var imagesPerSlideCard = parseInt(objGallery.width / objGallery.thumbWidth) - 1;
            for (var i = 0; i < items.length; i++) {
                var image1Url = getElementTextNS("", "image1", items[i], 0);
                var image2Url = getElementTextNS("", "image2", items[i], 0);
                var image3Url = getElementTextNS("", "image3", items[i], 0);
                var imageName = getElementTextNS("", "name", items[i], 0);
                var ratio = parseInt(getElementTextNS("", "width", items[i], 0)) / parseInt(getElementTextNS("", "height", items[i], 0));
                var imageDescription = getElementTextNS("", "description", items[i], 0);
                var imageWidth = objGallery.thumbWidth;
                var imageLeftRightMargin = 0;
                var imageHeight = parseInt(objGallery.thumbWidth / ratio);
                if (imageHeight > objGallery.thumbWidth) {
                    imageHeight = objGallery.thumbWidth - 7;
                    imageWidth = parseInt(imageHeight * ratio);
                    imageLeftRightMargin = parseInt((objGallery.thumbWidth - imageWidth) / 2);
                }
                if ((i % imagesPerSlideCard) == 0) {
                    html += (i > 0 ? "</tr></table></td>" : "") + "<td><table style='width:" + (objGallery.width - 6) + "px; height:" + objGallery.thumbWidth + "px' cellspacing='0' cellpadding='0'><tr>";
                    objGallery.pageCount += 1;
                }
                html += "<td><a href='#' class='image' onclick='return false;'><img src='" + "" + image1Url + "' width='" + imageWidth + "' height='" + imageHeight + "' title='" + replace(imageName, "'", "") + "' description='" + replace(imageDescription, "'", "") + "' imageUrl='" + image2Url + "' onclick=\"" + divGalleryID + "Object.ShowImage(" + i + ")\" style=\"margin-left:" + imageLeftRightMargin + "px;margin-right:" + imageLeftRightMargin + "px\"/></a></td>";
            }
            html += "</tr></table></td>";
            html += "</tr></table>";
            objGallery.divGalleryImageThumbs.innerHTML = html;
            objGallery.ShowImage(0);
            objGallery.RefreshButtons();
        });
        
    }
    this.ShowImage = ShowImage;
    function ShowImage(index) {
        var objThumbs = this.divGalleryImageThumbs.getElementsByTagName("IMG");
        if (objThumbs.length<=index) return;
        var objThumb = objThumbs[index];        
        var imageUrl = objThumb.getAttribute("imageUrl"); 
        var imageTitle = (index+1) + "/" + objThumbs.length + ".- " + objThumb.title;
        var imageDescription = objThumb.getAttribute("description");
        this.imgGalleryImage.style.display = "none";
        this.imgGalleryImage.style.height = "";
        this.imgGalleryImage.style.width = "";
        this.imgGalleryImage.style.marginLeft = "";
        this.imgGalleryImage.style.marginTop = "";
        fadeTo(this.imgGalleryImage.id, 0, 20);
        this.imgGalleryImage.src = imageUrl;        
        this.divGalleryComments.innerHTML = imageTitle + "<br/>" + imageDescription;
    }
    this.ShowNextThumbs= ShowNextThumbs;
    function ShowNextThumbs() {
        var tableThumbs = this.divGalleryImageThumbs.getElementsByTagName("TABLE")[0];
        var viewWidth = this.width - 6;
        this.selectedIndex++;
        newPosition = (viewWidth * this.selectedIndex);
        slideHTMLElementLeft(tableThumbs.id, newPosition, 32, 5);
        this.RefreshButtons();
    }
    this.ShowPreviousThumbs = ShowPreviousThumbs;
    function ShowPreviousThumbs() {
        var tableThumbs = this.divGalleryImageThumbs.getElementsByTagName("TABLE")[0];
        var viewWidth = this.width - 6;
        this.selectedIndex--;
        newPosition = (viewWidth * this.selectedIndex);
        slideHTMLElementRight(tableThumbs.id, newPosition, 32, 5);
        this.RefreshButtons();
    }
    this.RefreshButtons = RefreshButtons;
    function RefreshButtons() {
        this.divGalleryImageThumbsBackForward.style.display = (this.pageCount>1 ? "block" : "none");
        this.divGalleryImageThumbsBackForward.childNodes[1].innerHTML = (this.selectedIndex + 1) + "/" + this.pageCount;
        this.divGalleryImageThumbsBackForward.childNodes[0].style.display = (this.selectedIndex > 0 ? "inline" : "none");
        this.divGalleryImageThumbsBackForward.childNodes[2].style.display = (this.selectedIndex < this.pageCount - 1 ? "inline" : "none");
    }
    this.ResizeImage = ResizeImage;
    function ResizeImage() {
        this.imgGalleryImage.style.display = "block";
        var wAvailable = parseInt(replace(this.divGalleryImage.style.width,"px",""));
        var hAvailable = parseInt(replace(this.divGalleryImage.style.height,"px",""));
        var w = this.imgGalleryImage.scrollWidth;
        var h = this.imgGalleryImage.scrollHeight;
        var ratio = w /h;
        if (w <= wAvailable && (h+6) <= hAvailable) {
            this.imgGalleryImage.style.marginLeft = ((wAvailable-w)/2) + "px";
            this.imgGalleryImage.style.marginTop = ((hAvailable-h)/2) + "px";
            this.imgGalleryImage.style.height = "";
            this.imgGalleryImage.style.width = "";
        } else if (w <= wAvailable && (h+6) > hAvailable) {
            this.imgGalleryImage.style.height = hAvailable - 6 + "px";        
            this.imgGalleryImage.style.marginTop = "0px";
            this.imgGalleryImage.style.marginLeft = ((wAvailable-parseInt(hAvailable * ratio))/2) + "px";
        } else if (w > wAvailable && (h+6) <= hAvailable) {
            this.imgGalleryImage.style.width = wAvailable + "px";        
            this.imgGalleryImage.style.marginTop = ((hAvailable-parseInt(wAvailable/ratio))/2) + "px";
            this.imgGalleryImage.style.marginLeft = "0px";
        } else if (w > wAvailable && (h+6) > hAvailable) {
            if ((w-wAvailable) > (h-hAvailable)) {            
                this.imgGalleryImage.style.width = wAvailable + "px";             
                this.imgGalleryImage.style.marginLeft = "0px";
                this.imgGalleryImage.style.marginTop = parseInt((hAvailable-wAvailable/ratio)/2) + "px";
            } else {
                this.imgGalleryImage.style.height = hAvailable + "px";             
                this.imgGalleryImage.style.marginTop = "0px";
                this.imgGalleryImage.style.marginLeft = parseInt((wAvailable-hAvailable*ratio)/2) + "px";
           }
        } else {
            //alert("ResizeImage:" + w + "," + h + ",    " + wAvailable + "," + hAvailable);
        }
        fadeTo(this.imgGalleryImage.id, 100, 10);
    }
    

    //call construcor    
    this.Constructor();

}

