if (!Ascribe) {
	var Ascribe = {};
}

if (typeof(Ascribe.Gallery) == 'undefined') {
	Ascribe.Gallery = function(config) {
		// ids
		this.largeImageContainerID = config.largeImageContainerID || 'large-image-container';
		this.largeImageID = config.largeImageID || 'default-photo';
		this.currentLargeImageSrc = '';
		this.loadingID = config.loadingID || 'loading';
		this.viewFullSizeID = config.viewFullSizeID || 'view-full-size';
		
		// options
		this.effectMorphBackgroundColor = config.effectMorphBackgroundColor || 'background-color: #000;';
		this.nodeFirstChild = '&nbsp;';
		this.viewFullSizeSrc = 'http://assets.ascribehq.com/integrations/images/misc/view_full_size.png';
		this.viewFullSizeAlt = 'View Full Size';
		
		// misc configs
		this.loadingInProgress = false;
		
		// set event listener
		Event.observe(this.largeImageID, 'load', this.fadeImage.bindAsEventListener(this));
	}
}

Ascribe.Gallery.prototype = {
	loadImage: function(largePhotoSrc, xlargePhotoSrc) {      
	  if (this.currentLargeImageSrc == largePhotoSrc) {
			return false;
		}

		this.loadingInProgress = true;
		
		$(this.loadingID).style.visibility = 'visible';
		
		new Effect.Morph(this.largeImageContainerID, {
	    style: this.effectMorphBackgroundColor,
	    duration: 0.2
	  });

	  new Effect.Opacity(this.largeImageID, {
	    from: 1,
	    to: .5,
	    duration: .2
	  });

		$(this.largeImageID).src = largePhotoSrc; 
		$(this.largeImageContainerID).href = xlargePhotoSrc;
		this.currentLargeImageSrc = largePhotoSrc;
	},
	
	fadeImage: function(event) {
	  this.loadingInProgress = false;
	  
		$(this.loadingID).style.visibility = 'hidden';
		
	  new Effect.Morph(this.largeImageContainerID, {
	    style: 'background: none;',
	    duration: 0.2
	  });

	  new Effect.Opacity(this.largeImageID, {
	    from: 0,
	    to: 1.0,
	    duration: .5
	  });
	},

	show_view_full_size: function() {
	  if (this.loadingInProgress == false) {
  	  $(this.viewFullSizeID).style.visibility = 'visible';
    }
	},

	hide_view_full_size: function() {
	  $(this.viewFullSizeID).style.visibility = 'hidden';
	}
} // Ascribe.Gallery.prototype
