/*

	@ Class:		media_gallery.js
	@ Author:		Andrew Regis
	@ Date:		05/13/09
	@ Version:	1.0
	@ Requires:	mootools v1.2.1-core and mootools v1.2.1-more ( all FX, all Drag, Sortables )
	@ Brief:		O3MS script for controling media center functionality and AJAX
			
*/

var GalleryManager = new Class({

	options: {
		Webroot:			 Class.empty,				// REQUIRED: The webroot of the page calling this script
		ActiveImageWrapper:	'gallery_image_container',	// REQUIRED: ID of the container that holds the 'large' or 'Active' image for an image gallery
		GalleryThumbs:		'.gallery_thumb'			// REQUIRED: Class on any image gallery thumbs
	},
	
	initialize: function( options ) {
		
		this.setOptions(options);

		this.Webroot			=     this.options.Webroot;
		this.ActiveImageWrapper	=  $( this.options.ActiveImageWrapper );
		this.GalleryThumbs		= $$( this.options.GalleryThumbs );
		
		if( this.ActiveImageWrapper && this.GalleryThumbs )
			for( var i = 0; i < this.GalleryThumbs.length; i++ )
				this.GalleryThumbs[i].addEvent( 'click', this.SwapPhotos.bindWithEvent( this, i ) );
		
	},
	
	// ////////////////////////////////////////////////////////////// Main Functions //
	
	SwapPhotos: function( event, i ) {
		
		event.stop();
		
		for( var j = 0; j < this.GalleryThumbs.length; j++ )
			if( this.GalleryThumbs[j].hasClass( 'active' ) )
				this.GalleryThumbs[j].removeClass( 'active' );

		this.GalleryThumbs[i].addClass( 'active' );

		this.ActiveImageWrapper.set( 'html', '<img src="' + this.Webroot + 'media_center/images/rendered/results/large/' + this.GalleryThumbs[i].getAttribute( 'rel' ) + '" width="651" alt="' + this.GalleryThumbs[i].getAttribute( 'rel' ) + '" />' );
		
	}

	
});


// /////////////////////////////////////////////////////////////////////////////// // IMPLMENTATION //


GalleryManager.implement( new Options );
