	var detailsActive	= 1;
	var timeoutSet		= 0;
	var timerRunning	= 0;
	var activePhoto		= 1;
	var childList		= new Array();
	
	var photoGallery	= new Object();


/***** GET THE FUNCTIONS STARTED *****/

	photoGallery.Start = function() {
		photoGallery.Images();
		photoGallery.Pagination();
		photoGallery.Change(1,'start');
	}


/***** CLICK TO CHANGE THE IMAGE *****/

	photoGallery.Click = function(photoId) {
		photoGallery.Change(photoId,'click');
	}


/***** PREPARE ALL IMAGE ATTRIBUTES *****/

	photoGallery.Images = function() {
		
		childList = $(photoShell).childElements();
		
		var paginationList = childList;
		
		for(var i = 0; i < paginationList.length; i++) {
			var i2 = i + 1;
			paginationList[i].id		= 'brand_content' + i2;
			paginationList[i].className	= 'brand_content';
			paginationList[i].hide();
		}
		paginationList[0].show();
	}

/***** PREPARE ALL IMAGE ATTRIBUTES *****/

	photoGallery.Pagination = function() {
		
		var linkList = childList;
	
	// Set the UL
		var paginationUL	= document.createElement('ul');
		paginationUL.id = 'photo_pagination';
		$(photoShell).appendChild(paginationUL);
		
		var paginationLI	= new Array();
		var paginationA		= new Array();
		
		for(var i = 0; i < linkList.length; i++) {
			var i2 = i + 1;
		
		// Create the LIs
			paginationLI[i]	= document.createElement('li');
			paginationUL.appendChild(paginationLI[i]);
		
		// Create the hyperlinks
			paginationA[i]	= document.createElement('a');
			paginationLI[i].appendChild(paginationA[i]);
			paginationA[i].innerHTML	= i2;
			paginationA[i].href			= '#';
			paginationA[i].id			= 'photo_brand_link' + i2;
	
		// Set the onclick event handlers
			photoGallery.PaginationEvents(i2);
		}
	// Make the first link active
		paginationA[0].className = 'active';
	
	}

	photoGallery.PaginationEvents = function(i2) {
		Event.observe($('photo_brand_link' + i2), 'click', function() { photoGallery.Click(i2); });
	}


/***** SHOW/HIDE THE DETAILS AREA *****/

	photoGallery.Details = function() {
		var detailsLinkList = $(detailsLink).getElementsByTagName('a');
	
	// Hide the details area
		if(detailsActive == 1) {
			new Effect.Fade($(photoDetails), { scaleX: true, scaleY: false, duration: 0.4, afterFinish: function() {
				detailsActive = 0;
				detailsLinkList[0].innerHTML = 'show info';
			}
			});
		} else {
	
	// Show the details area
			new Effect.Appear($(photoDetails), { scaleX: true, scaleY: false, duration: 0.4, afterFinish: function() {
				detailsActive = 1;
				detailsLinkList[0].innerHTML = 'hide info';
			}
			});
		}
	}
	
/***** CHANGE THE PHOTO *****/
	
	photoGallery.Change = function(photoId,photoState) {

	// How was the photo changer started
		switch(photoState) {
		// When the page first loads
			case 'start':
				timeoutSet = setTimeout('photoGallery.Change(2,\'cycle\')', cycleTimer);
			break;
			
		// When someone clicks on the link
			case 'click':
				if(timerRunning == 0) {
					clearTimeout(timeoutSet);
					photoGallery.Change(photoId,'cycle_click');
				}
			break;
			case 'cycle':
			case 'cycle_click':

			// Fade the active image
				new Effect.Fade($('brand_content' + activePhoto), { duration: 1, beforeStart: function() {
					$('brand_content' + activePhoto).style.zIndex = '300';
					$('brand_content' + photoId).show();
					$('brand_content' + photoId).style.zIndex = '200';
					
					timerRunning = 1;
					
					for(var i = 0; i < childList.length; i++) {
						var i2 = i + 1;
						$('photo_brand_link' + i2).className = '';
					}
					$('photo_brand_link' + photoId).className = 'active';
				},
				afterFinish: function() {
					$('brand_content' + photoId).style.zIndex = '300';
					
					activePhoto		= photoId;
					timerRunning	= 0;
					
					for(var i = 0; i < childList.length; i++) {
						var i2 = i + 1;
						if(i2 != photoId) {
							$('brand_content' + i2).style.zIndex = '100';
						}
					}
					
				// Set the next photo id
					var brandNext	= photoId + 1;
					
					if(brandNext <= childList.length) {
						switch(photoState) {
						case 'cycle':
						case 'cycle_click':
							var Timer = clickTimer;
						break;
						}
					
						timeoutSet = setTimeout('photoGallery.Change(' + brandNext + ',\'cycle\')', Timer);
					}
					
				}
				});
			break;
		}
	}