// --------------------------------------------------
// MakeGallery Class

// Required:
// - NodeHelper Object
// - ImageHelper Object
// - WindowLauncher Object

MakeGallery = function(imageId){
	this.imageId = imageId;
	this.slides = new Array();
	this.active = 0;
	
	// Add an anchor tag to the fullsize image and 
	// attach an onclick event calling the "zoom" method.
	var self = this;
	var a = NodeHelper.addAnchor(document.getElementById(this.imageId));
	a.onclick = function(){self.zoom()};
}
MakeGallery.prototype.build = function(thumbId, zoomSrc, imageSrc, thumbSrc, activeSrc){
	var index = this.slides.length;
	var slide = this.slides[index] = new Object();
	slide.thumbId = thumbId;
	slide.zoomSrc = zoomSrc;
	slide.imageSrc = imageSrc;
	slide.thumbObj = ImageHelper.preload(thumbSrc);
	slide.activeObj = ImageHelper.preload(activeSrc);
	
	// Access the anchor tag wrapping this thumbnail image 
	// and attach an onclick event calling the "show" method.
	var self = this;
	document.getElementById(thumbId).parentNode.onclick = function(){self.show(index); return false};
}
MakeGallery.prototype.show = function(index){
	var active = this.slides[this.active];
	var slide = this.slides[index];
	ImageHelper.swap (active.thumbId, active.thumbObj);
	ImageHelper.swap (slide.thumbId, slide.activeObj);
	NodeHelper.replaceImage (this.imageId, slide.imageSrc);
	this.active = index;
}
MakeGallery.prototype.zoom = function(){
	var img = this.slides[this.active].zoomSrc;
	WindowLauncher.openZoom(img);
	return false;
}

// --------------------------------------------------

