function Gallery(divGalleryID,source,width,height,bgcolor) {
        
    //variables
    this.divGalleryID = divGalleryID;
    this.divGallery = document.getElementById(divGalleryID);
    this.divGalleryImage;
    this.imgImage;
    this.width = width;
    this.height = height;
    this.bgcolor = bgcolor;
    this.imageWidth = 440;
    this.xml = null;
    this.delay = 5000;
    this.isFirstImage = true;
        
    //constructor
    this.Constructor = Constructor;
    function Constructor() {
        this.divGallery.className = "gallery3";
        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 + "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);
        this.imgImage = document.createElement("IMG");
        this.divGalleryImage.appendChild(this.imgImage);
        //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;
        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);
            }
        }
        if (document.all && !this.isFirstImage) {
            this.imgImage.style.filter = "blendTrans(duration=2)";
            this.imgImage.filters.blendTrans.Apply();
        }
        this.imgImage.src = image2Url;
        this.imgImage.style.width = imageWidth + "px";
        this.imgImage.style.height = imageHeight + "px";
        this.imgImage.style.marginLeft = imageMarginLeft + "px";
        this.imgImage.style.marginTop = imageMarginTop + "px";
        if (document.all && !this.isFirstImage) {
            this.imgImage.filters.blendTrans.Play();
        }
        setTimeout(this.divGalleryID + "Object.ShowImage(" + (index + 1) + ")", this.delay)
        this.isFirstImage = false;
    }
 
    //call constructor
    this.Constructor();
       
}

