/* Javascript owned by McAurie.com and may NOT be used NOR disributed */

var Testimonial =
{
	init: function()
	{
		Testimonial.Opacity = 0.8;
		Testimonial.Active = null;
		Testimonial.TransitionLock = false;
		Testimonial.PreviousLock = false;
		
		var pPreview = $('preview').down('a.testimonial');
		var iIndex = 0;
		
		while(typeof(pPreview) != 'undefined')
		{
			pPreview.onclick = function()
			{
				Testimonial.show(this);
			}
			
			pPreview.setAttribute('href', 'javascript:void(0);');
			pPreview = $('preview').down('a.testimonial', iIndex);
			
			iIndex++;
		}
	},
	
	show: function(pElement)
	{
if(pElement.hasClassName('noTestimonial'))
{
	return;
}
		if(Testimonial.TransitionLock)
		{
			return;
		}
		
		Testimonial.TransitionLock = true;
		
		var iButtonIndex = Testimonial.getButtonIndex(pElement);
		var pLi = Testimonial.getLiByButtonIndex(iButtonIndex);
		var pDiv = pLi.down('div');
		
		if(pDiv.getStyle('display') != 'none')
		{
			var pFadeOptions =
			{
				duration: 1.4,
				to: 0,
				afterFinish: function()
				{
					Testimonial.TransitionLock = false;
				}
			}
			
			new Effect.Fade(pDiv, pFadeOptions);
			
			return;
		}
		
		if(pDiv != Testimonial.Active)
		{
			Testimonial.hide();
		}
		
		pDiv.setOpacity(0.01);
		pDiv.show();
		
		var pAppearOptions =
		{
			duration: 1.4,
			to: Testimonial.Opacity,
			afterFinish: function()
			{
				Testimonial.TransitionLock = false;
			}
		}
		
		Testimonial.Active = pDiv;
		new Effect.Fade(pDiv, pAppearOptions);
	},
	
	hide: function()
	{
		if(Testimonial.PreviousLock)
		{
			return;
		}
		
		if(!Testimonial.Active)
		{
			return;
		}
		
		Testimonial.PreviousLock = true;
		
		var pFadeOptions =
		{
			duration: 1.4,
			to: 0,
			afterFinish: function()
			{
				Testimonial.PreviousLock = false;
			}
		}
		
		new Effect.Fade(Testimonial.Active, pFadeOptions);
	},
	
	getButtonIndex: function(pElement)
	{
		var pPreview = $('preview').down('a.testimonial');
		var iIndex = 0;
		
		while(pElement != pPreview)
		{
			pPreview = $('preview').down('a.testimonial', iIndex);
			iIndex++;
		}
		
		return iIndex == 0 ? iIndex : (iIndex - 1);
	},
	
	getLiByButtonIndex: function(iButtonIndex)
	{
		return $('thumbs').down('li', iButtonIndex);
	}
}

Event.observe(window, 'load', Testimonial.init, false);
