/***** collection homepage javascript functions - by adolmedia.com  *****/

	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');
		$('photo_shell').removeClassName('photo_shell_hide');
	}


/***** CLICK TO CHANGE THE IMAGE *****/

	photoGallery.Click = function(photoId) {
		photoGallery.Change(photoId,'click');
	}


/***** PREPARE ALL IMAGE ATTRIBUTES *****/

//Visible window width
			function getWindowWidth() {
				return window.offsetWidth || document.documentElement.clientWidth;
			};
			
			//Visible window height
			function getWindowHeight() {
				return window.offsetHeight || document.documentElement.clientHeight;
			};
		var WidthRomo = getWindowWidth();
		var HeightRomo = getWindowHeight();
		
		var ImgWidthRomo = WidthRomo;
		var ImgHeightRomo = WidthRomo * 0.72;

	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].firstChild.style.width = ImgWidthRomo + 'px';
			paginationList[i].firstChild.style.height = ImgHeightRomo + 'px';
			//paginationList[i].firstChild.style.margin = '0px 0px 0px -' + (ImgWidthRomo / 2) + 'px';
				if(ImgWidthRomo <= 1080) {
						paginationList[i].firstChild.style.width = 1080 + 'px';
						paginationList[i].firstChild.style.height = (1080*0.72) + 'px';
						//paginationList[i].firstChild.style.margin = '0px 0px 0px -' + (ImgWidthRomo / 2) + 'px';
				};
			paginationList[i].hide();
		}
		paginationList[0].show();
	}
	
// Pan and zoom objects.
var frontBurns;
var backBurns;

function setOpacity(image, value)
{
	if (image.filters && image.filters[0])
	{
		image.filters[0].opacity = value * 100;
	}
	else
	{
    	image.style.opacity = value;
    }
}

function stepTail(animationIndex)
{
	if (frontBurns)
	{
		var time = animationIndex / ((secondsPerImage + secondsPerFade) * stepsPerSecond);
		frontBurns.apply(frontImage, time);
	}

	if (backBurns)
	{
		var time = (animationIndex + secondsPerImage * stepsPerSecond) / ((secondsPerImage + secondsPerFade) * stepsPerSecond);
		if (time > 1)
			backBurns = 0;
		else
			backBurns.apply(backImage, time);
	}

	++timeIndex;

	window.setTimeout(step, 1000 / stepsPerSecond);
}

/***** 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.Fade($(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: 4, beforeStart: function() {
					$('brand_content' + activePhoto).style.zIndex = '5';
					$('brand_content' + photoId).show();
					$('brand_content' + photoId).style.zIndex = '3';
					
					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 = '3';
					
					activePhoto		= photoId;
					timerRunning	= 0;
					
					for(var i = 0; i < childList.length; i++) {
						var i2 = i + 1;
						if(i2 != photoId) {
							$('brand_content' + i2).style.zIndex = '1';
						}
					}
					
				// Set the next photo id
					var brandNext	= photoId + 1;
					
					if(brandNext > childList.length) {
						brandNext = 1;
					}
					switch(photoState) {
						case 'cycle':
						case 'cycle_click':
							var Timer = clickTimer;
						break;
					}
					
					timeoutSet = setTimeout('photoGallery.Change(' + brandNext + ',\'cycle\')', Timer);
				}
				});
				
					Event.observe(window, 'resize', function () {
											  
		//Visible window width
			function getWindowWidth() {
				return window.offsetWidth || document.documentElement.clientWidth;
			};
			
		//Visible window height
			function getWindowHeight() {
				return window.offsetHeight || document.documentElement.clientHeight;
			};
			
		//Resize image with changes in overall window width	
			
		var WidthRomo = getWindowWidth();
		var HeightRomo = getWindowHeight();
		
		var divWidthRomo = getWindowWidth();
		var divHeightRomo = getWindowHeight();
		
		var ImgWidthRomo = WidthRomo;
		var ImgHeightRomo = WidthRomo * 0.72;
		
		childList2 = $(photoShell).childElements();
		
		for(var i = 0; i < childList2.length; i++) {
			
			childList2[i].firstChild.style.width = ImgWidthRomo + 'px';
			childList2[i].firstChild.style.height = ImgHeightRomo + 'px';
			//childList2[i].firstChild.style.margin = '0px 0px 0px -' + (ImgWidthRomo / 2) + 'px';
			if(ImgWidthRomo <= 1080) {
						childList2[i].firstChild.style.width = 1080 + 'px';
						childList2[i].firstChild.style.height = (1080*0.72) + 'px';
						//childList2[i].firstChild.style.margin = '0px 0px 0px -' + (ImgWidthRomo / 2) + 'px';
				};
			
			/*
			console.log('Image height is' + ImgHeightRomo + 'px, Image width is ' + ImgWidthRomo);
			console.log(divWidthRomo);
			
				if (mainWidthRomo =< 800) {
				
					$('body').firstchild.style.width = 800 + 'px';
					
				}; */

		}
	});
			break;
		}
	}
	
	
/***** PREVENT THE WINDOW FROM REDUCING BELOW CERTAIN DIMENSIONS *****/



