if (!PuffEffectsCore)
{
	var PuffEffectsCore =
	{	
		nextButtonClassName: 'puff-next-button',
		prevButtonClassName: 'puff-prev-button',
		puffControlsClassName: 'puff-controls',
		scriptAppliedClassName: 'puff-effect',
	
		/*
		 * 
		 */
		LoadDependentScripts: function(baseUrl)
		{
			// If the moo.rd script hasn't been loaded, load it.
			if (!window.Moo)
			{
				this.LoadScript(baseUrl + 'js/lib/moo.rd.js');	
				this.LoadScript(baseUrl + 'js/effects/moo.rd.extend.js');
			}
		},
		
		
		/*
		 * 
		 */
		LoadScript: function(url)
		{
			document.write('<script src=' + url + '><\/script>');

			/* CAUSED ISSUES WITH IE, STRANGE ISSUES!
			 *
			var e = document.createElement("script");
			e.src = url;
			e.type="text/javascript";
			document.getElementsByTagName("head")[0].appendChild(e);*/
		},
		
		/*
		 * 
		 */
		ScriptsLoaded: function()
		{
			try
			{
				if (Fx.Cycle.fade &&
					Fx.Cycles.scrollRightWithInversePrevious &&
					Fx.Cycles.scrollUpWithInversePrevious)
				{
					return true;
					
				}	
				else
				{
					return false;
				}
			}
			catch (error)
			{
				return false;
			}	
			
		},
		
		/*
		 * 
		 */
		CheckNumberOfPuffs: function(containerId)
		{
			var nodes = $(containerId).childNodes;
			var divCount = 0;
			
			for (var i = 0; i < nodes.length; i++)
			{	
				if (nodes[i].tagName == 'DIV')
				{
					divCount++;
				}
			}
			
			return divCount;
		},
		
		/*
		 * 
		 */
		ApplyEffect: function(containerId, effect, effectDelay, controlsEnabled)
		{	
			
			
			if (controlsEnabled == null)
			{
				controlsEnabled = true;
			}
			
			// Check to see if the scripts have loaded first
			if (!this.ScriptsLoaded())
			{
				setTimeout(Utils.Bind(this, this.ApplyEffect, containerId, effect, effectDelay, controlsEnabled), 50);
			}
			else
			{
				var puffCount = this.CheckNumberOfPuffs(containerId);
		
				if (puffCount > 1)
				{
					$(containerId).parentNode.className += ' ' + this.scriptAppliedClassName;
					
					var steps = effectDelay * 1000;
					
					var opts =
					{
						duration: 2500,
						steps: steps,
						overflow: 'hidden'
					};
					
					if (controlsEnabled == true)
					{
						var linkIds = this.CreatePrevNextLinks(containerId);
						
						opts.handles = {
								          next: linkIds.next,
							              prev: linkIds.prev
									   };
					}
					

					switch (effect)
					{
						case 'fade':
							var fx = new Fx.Cycle.fade(containerId, opts);
							this.BindReStartFunction(containerId, fx);
							this.BindPauseFunction(containerId, fx);				
							
							break;
						
						case 'scrollRight':
							var fx = new Fx.Cycles.scrollRightWithInversePrevious(containerId, opts);
							this.BindReStartFunction(containerId, fx);
							this.BindPauseFunction(containerId, fx);
							
							break;
						
						case 'scrollDown':
							var fx = new Fx.Cycles.scrollUpWithInversePrevious(containerId, opts);
							this.BindReStartFunction(containerId, fx);
							this.BindPauseFunction(containerId, fx);
							
							break;
					}
					
				}
			
			}
		},
		
		/*
		 * 
		 */
		BindPauseFunction: function(containerId, fx)
		{
			$(containerId).onmouseover = function ()
			{
				fx.stop();
			}
		},
		
		/*
		 * 
		 */
		BindReStartFunction: function(containerId, fx)
		{
			$(containerId).onmouseout = function ()
			{
				fx.autostart();
			}
		},
		
		/*
		 * 
		 */
		CreatePrevNextLinks: function(containerId)
		{
			var prevTextStr = 'prev';
			var nextTextStr = 'next';
			
			var container = $(containerId).parentNode;
			
			var ulEl = document.createElement('ul');
			ulEl.id = containerId + '_control';
			ulEl.className = this.puffControlsClassName;


			
			var nextLi = document.createElement('li');
			var nextButton = document.createElement('a');
			var nextText = document.createTextNode(nextTextStr);
			nextLi.className = this.nextButtonClassName;
			nextButton.id = containerId + '_next';
			nextButton.href = '#';
			nextButton.appendChild(nextText);
			nextLi.appendChild(nextButton);
			
			
			var prevLi = document.createElement('li');
			var prevButton = document.createElement('a');
			var prevText = document.createTextNode(prevTextStr);
			prevLi.className = this.prevButtonClassName;
			prevButton.id = containerId + '_prev';
			prevButton.href = '#';
			prevButton.appendChild(prevText);
			prevLi.appendChild(prevButton);

			ulEl.appendChild(nextLi);
			ulEl.appendChild(prevLi);	
			
			container.appendChild(ulEl);
			
			return {next: nextButton.id, prev: prevButton.id};
		}
		
		
	}

}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------

