// Currently Running on Script.Aculo.Us 1.8.3
// 

var fadeBox = $('gallery');				// Containing Gallery Thumbs
var galleryArray = [];					// Contains all data from thumbs in current gallery!
var from = null;						// FROM = NULL until set by changeGallery
var toBox = null;						// These boxes are for hidden gallery sections...
var fromBox = null;						// These boxes are for hidden gallery sections...

var setupNav = function(obj){			// Used in setupGallery to change the class of the (now) active Nav Element.
	if (nav) nav.className='';
	obj.className='active';
	nav=obj;
};

var changeGallery = function(to){			// Takes NavButton/(this), and Gallery Number
	if (!from) {
	
		var finishChangeGallery = function() {
			Effect.Fade(fadeBox,{duration:.5,queue:{scope:'gallery_tabs'},afterFinish:function(){
				toBox = $('g'+to);
				fadeBox.innerHTML = toBox.innerHTML;		// The from and to boxes make sure there is no duplication
				toBox.innerHTML = '';						// of gallery images. :)
				from = to;									// The From = To has to go here, since this is the actual finish of the script... It's the only way!
			}});
			Effect.Appear(fadeBox,{delay:.5,duration:.5,from:0.0,queue:{scope:'gallery_tabs'}});
			setupNav($(to));
		}
	Effect.MoveBy('nothing',0,0,{duration:.001,queue:{scope:'gallery_tabs',limit:1},afterFinish:finishChangeGallery});	
	} else if (from!=to) {
		var finishChangeGallery = function() {
			
			Effect.Fade(fadeBox,{duration:.5,queue:{scope:'gallery_tabs'},afterFinish:function(){
				toBox = $('g'+to);
				fromBox = $('g'+from);
				fromBox.innerHTML = fadeBox.innerHTML;			// The from and to boxes make sure there is no duplication
				fadeBox.innerHTML = $('g'+to).innerHTML;		// of gallery images. :)
				toBox.innerHTML = '';							// The From = To has to go here, since this is the actual finish of the script... It's the only way!
				from = to;
			}});
			Effect.Appear(fadeBox,{delay:.5,duration:.5,from:0.0,queue:{scope:'gallery_tabs'}});
			setupNav($(to));
		}
		Effect.MoveBy('nothing',0,0,{duration:.001,queue:{scope:'gallery_tabs',limit:1},afterFinish:finishChangeGallery});
	}	
};
