
function ArtistGallery() {
	this.artistId = 573;
	this.gallerySections = new Array();
	this.imagesPerPage = 8;
	this.currentSectionId; // = 2;
	this.currentSection;// = this.gallerySections[1];
	this.currentPageNumber = 1;
	this.currentDetailImage;
	// Methods;
	
	this.changeSection = changeArtistGallerySection;
	this.getCurrentDetailImage = getArtistGalleryCurrentDetailImage;	
	this.valueOf = genericValueOfOverRide;
	
} // End ArtistGallery class definition

ArtistGallery.prototype.addGallerySection = function(sectionObj) {
	this.gallerySections.push(sectionObj);	
}

ArtistGallery.prototype.getGalleryThumbnails = function() {
	var refToSelf = this;
	var onSuccessFunc = function(req) { handleGetGalleryThumbnailsResponse(req, refToSelf); }
	//var onSuccessFunc = this.handleGetGalleryThumbnailsResponse(req); 
	var onErrorFunc = function(req) { alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText); }
	var onTimeOutFunc = function(req) { alert('Timed Out!'); }
	var reqUrl = "ajax_requests/gallery.php";
	
	var req = AjaxRequest.post({'url':reqUrl, 'artistId':this.artistId, 'sectionId':this.currentSection.galleryType.replace(" ", "") + "_" + this.currentSectionId, 'imgsPerPage':this.imagesPerPage, 'pageNumber':this.currentPageNumber, 'onSuccess': onSuccessFunc, 'onError': onErrorFunc, 'onTimeout': onTimeOutFunc });
}

function handleGetGalleryThumbnailsResponse(reqObj, refToGalleryObj) {
	//alert(reqObj.responseText);
	retObj = eval("(" + reqObj.responseText + ")");	
	
	refToGalleryObj.totalPageCount = retObj.totalPageCount;
	
	if ((retObj.type == "fanuploads" || retObj.type == "gallery") && retObj.images) {
		refToGalleryObj.currentSection.maxImageId = retObj.sectionMaxImageId; //retObj.images[0]; // = 19131;
    	refToGalleryObj.currentSection.minImageId = retObj.sectionMinImageId; //retObj.images[0]; // = 19109;	
		
		refToGalleryObj.currentSection.images = retObj.images;
		//refToGalleryObj.updateThumbnailDisplay();
		//refToGalleryObj.doDetailSelect();
	} else {
		refToGalleryObj.totalPageCount = 0;
		refToGalleryObj.currentSection.maxImageId = 0;
    	refToGalleryObj.currentSection.minImageId = 0;	
		
		refToGalleryObj.currentSection.images = new Array();		
	}
	refToGalleryObj.updateThumbnailDisplay();
	refToGalleryObj.doDetailSelect();
}

function genericValueOfOverRide(recurse) {
	var retStr = "";
	
	for (var fld in this) { 
		if (typeof(this[fld]) == "function") {
		
		} else if (typeof(this[fld]) == "object" && recurse == true) {
			retStr += fld + " = " + this[fld].toSource() + " (type: " + typeof(this[fld]) + ")\n\n";
		} else {
			retStr += fld + " = " + this[fld] + " (type: " + typeof(this[fld]) + ")\n";
		}
	}
	return retStr;	
} // End genericValueOfOverRide

function changeArtistGallerySection(newId) {
	this.currentSectionId = newId;
	this.currentSection = null;
	this.currentPageNumber = 1;
	for (var i=0; i<this.gallerySections.length; i++) {
		if (this.gallerySections[i].id == newId) {
			this.currentSection = this.gallerySections[i];
			break;
		}	
	}
	// Load new images via Ajax:
	if (this.currentSection.images.length == 0) {
		//alert('getThumbs');
		this.getGalleryThumbnails();
	} else {
		//alert('updating from existing data');
		this.pageCount = this.currentSection.pageCount;
		this.updateThumbnailDisplay();
		this.doDetailSelect();		
	}
} // End changeArtistGallerySection method

function getArtistGalleryCurrentDetailImage() {
	
} // End getArtistGalleryCurrentDetailImage method

// ----------------------------------------------------------------------------
// Supporting Classes:
// ----------------------------------------------------------------------------
function ArtistGalleryImage(id, caption, name, url, thumbUrl, extraLargeUrl, sectionId) {
	this.id = id;
	this.caption = caption;
	this.name = name;
	this.url = url;
	this.thumbUrl = thumbUrl;
	this.extraLargeUrl = extraLargeUrl;
	this.sectionId = sectionId;
	this.valueOf = genericValueOfOverRide;

} // End ArtistGalleryImage class definition

function ArtistGallerySection(name, id, system, imageCount, ordinal, galleryType, imagesPerPage) {
	this.name = name;
	this.id = id;
	this.system = system;
	this.imageCount = imageCount;
	this.ordinal = ordinal;
	this.images = new Array();
	this.galleryType = galleryType;
	this.pageCount = Math.ceil(this.imageCount/imagesPerPage);
   	this.currentPageNumber; 
    this.maxImageId; // = 19131;
    this.minImageId; // = 19109;	
	// Methods:
	this.valueOf = genericValueOfOverRide;	
	
} // End ArtistGallerySection class definition

ArtistGallerySection.prototype.addImage = function(imgObj) {
	this.images.push(imgObj);
}