var IGS = new Class.create();
IGS.prototype = {
    id: "",
    ajaxUrl: "",
	imageUrl: "",
	thumbUrl: "",
	thumbWidth: 80,
	thumbHeight: 80,
	initialize: function(id, url) 
	{ 
	    this.id = id;
	    this.ajaxUrl = url + '/Documents/XML/' + this.id + '_imageData.xml';
		this.imageUrl = url + 'PublishingImages/' + this.id + '/';
		this.thumbUrl = url + 'PublishingImages/' + this.id + '/Thumbs/';
	}
};

var AAOnlineIG = {
    imgGalleryObjs: [], 
    getIGData: function(ig, container) {
        var opt =
        {
            method: 'get',
            parameters: '',
            onSuccess: function(req) {
                var docRoot = req.responseXML.documentElement;
                var arrName = docRoot.getElementsByTagName("NAME");
                var arrCaption = docRoot.getElementsByTagName("CAPTION");
				
				if (arrName.length > 5)
				{
					$(ig.id+'_prev').style.visibility = 'visible'
					$(ig.id+'_next').style.visibility = 'visible'			
				}
				
				var ul = Builder.node('ul', {});
				for (var i = 0; i < arrName.length; i++) 
				{
					var imgName = arrName[i].childNodes[0].nodeValue;
					var imgCaption = arrCaption[i].childNodes[0].nodeValue;

					var li = Builder.node('li', {});
					var img = Builder.node('img', 
					{
						src: ig.thumbUrl + imgName,
						width: ig.thumbWidth,
						height: ig.thumbHeight,
						alt: imgCaption
					});
					var an = Builder.node('a', 
                        { 
                            title: imgCaption,
                            href: ig.imageUrl + imgName,
							rel: 'lightbox[' + ig.id + ']'
                        }
                    );
                    
					an.appendChild(img);
					li.appendChild(an);
                    ul.appendChild(li);
                }
				container.appendChild(ul);
                hCarousel = new UI.Carousel(ig.id + "_carousel");
				return false;
            },
            onFailure: function(req) {
                alert('Error has occured while retrieving data. ');
                return false;
            }
        }
       
        new Ajax.Request(ig.ajaxUrl, opt);
    }
    ,
    init: function() 
	{
	    AAOnlineIG.imgGalleryObjs.each( function (ig) 
        {
             var container = $(ig.id);
	         if(container)
	            AAOnlineIG.getIGData(ig, container);
	    });
	}
}

