/**
************************************
* Visual Effects Class
************************************
*
* Adapted from the PortAll VFX Class (www.portallcms.com)
* which was also written by Jack Chapple (myself)
*
* This class is still a work in progress
*
* @copyright	Copyright (C) 2006, Jack Chapple
* @author	Jack Chapple <jack@jcxp.net>
*/

jc.Effect = function()
{
	// =============================
	// Defaults...
	// =============================
	
	this.fps      = 25;
	this.duration = 0.8;
	
	// =============================
	// Initialize Variables
	// =============================
	
	this.running      = false;
	this.stop         = false;
	this.useEase      = true;
	this.easeType     = "easeInOutStrong";
	this.fms          = 0;
	this.dur_ms       = 0;
	this.max_frame    = 0;
	this.frame_count  = 0;
	this.attribsArray = Array();
	this.layerObj;
	
	// =============================
	// Callbacks
	// =============================
	
	this.onBeforeStart;
	this.onBeforeRedraw;
	this.onAfterRedraw;
	this.onAfterFinish;
	
	// =============================
	// Calculate FPS Values
	// =============================
	
	this.calculateFps = function()
	{
		this.fms       = 1000/this.fps;
		this.dur_ms    = this.duration*1000;
		this.max_frame = Math.round(this.dur_ms/this.fms);
	}
	
	// =============================
	// Set Attributes for the effect
	// Syntax: attrib:value;attrib2:anothervalue;attrib3:andanother; etc...
	// =============================
	
	this.setAttribs = function( attribs )
	{
		var rawAttribs = attribs.split( ';' );
	
		for ( i in rawAttribs )
		{
			if ( !rawAttribs[i] ) continue;
			
			var thisAttribSplit = rawAttribs[i].split( ':' );
			this.setAttrib( thisAttribSplit[0], thisAttribSplit[1] );
		}
	}
	
	// =============================
	// Set a single attribute for the effect
	// =============================
	
	this.setAttrib = function( attribName, attribValue )
	{
		this.attribsArray[ attribName.toLowerCase() ] = attribValue;
	}
	
	// =============================
	// Throw an Error
	// =============================
	
	this.error = function( errStr )
	{
		jc.error( 'Effect Class:\n\n' + errStr );
		this.stop = true;
	}
	
	// =============================
	// Run the Effect
	// =============================
	
	this.run = function()
	{
		if ( this.running )	return;
		
		this.running = true;
		
		if ( !this.layerObj )
		{
			if ( typeof(this.attribsArray['layer']) == "string" )
			{
				this.layerObj = document.getElementById( this.attribsArray['layer'] );
			}
			else
			{
				this.layerObj = this.attribsArray['layer'];
			}
		}
		
		var effectName = this.attribsArray['effect'];
		
		if ( !this.layerObj )
		{
			this.error( 'layerObj was undefined' );
			return;
		}
		if ( !effectName )
		{
			this.error( 'effectName was undefined' );
			return;
		}
		
		if ( this.attribsArray['fps'] )
		{
			if ( this.attribsArray['fps'] <= 100 )
			{
				// =============================
				// No higher than 100, please.. O_O
				// =============================
				
				this.fps = this.attribsArray['fps'];
			}
		}

		if ( this.attribsArray['useease'] ) this.useEase = this.attribsArray['useease'];
		if ( this.attribsArray['easetype'] ) this.easeType = this.attribsArray['easetype'];
		if ( this.attribsArray['duration'] ) this.duration = this.attribsArray['duration'];
		
		this.calculateFps();
		
		effectName = effectName.toLowerCase();
		
		if ( typeof this.onBeforeStart == "function" ) this.onBeforeStart();
		
		switch( effectName )
		{
			case "fade":
				if ( !this.attribsArray['direction'] ) this.attribsArray['direction'] = "in";
				if ( !this.attribsArray['max'] ) this.attribsArray['max'] = 100;
				this.attribsArray['fin_mult'] = this.attribsArray['max']/this.max_frame;
				
				this.fade();
			break;
			
			case "flash":
				if ( !this.attribsArray['color'] ) this.attribsArray['color'] = "#F3859B";
				this.attribsArray['layerRgb'] = this.hexToRgb( this.getBgColor( this.layerObj ) );
				this.attribsArray['flashRgb'] = this.hexToRgb( this.attribsArray['color'] );
				
				this.attribsArray['rMax'] = Math.max( this.attribsArray['layerRgb']['r'], this.attribsArray['flashRgb']['r'] );
				this.attribsArray['gMax'] = Math.max( this.attribsArray['layerRgb']['g'], this.attribsArray['flashRgb']['g'] );
				this.attribsArray['bMax'] = Math.max( this.attribsArray['layerRgb']['b'], this.attribsArray['flashRgb']['b'] );
				this.attribsArray['rMin'] = Math.min( this.attribsArray['layerRgb']['r'], this.attribsArray['flashRgb']['r'] );
				this.attribsArray['gMin'] = Math.min( this.attribsArray['layerRgb']['g'], this.attribsArray['flashRgb']['g'] );
				this.attribsArray['bMin'] = Math.min( this.attribsArray['layerRgb']['b'], this.attribsArray['flashRgb']['b'] );
				
				var rDif = this.attribsArray['rMax']-this.attribsArray['rMin'];
				var gDif = this.attribsArray['gMax']-this.attribsArray['gMin'];
				var bDif = this.attribsArray['bMax']-this.attribsArray['bMin'];
				
				this.attribsArray['max'] = Math.max( rDif, gDif, bDif );
				this.attribsArray['fin_mult'] = this.attribsArray['max']/this.max_frame;
				
				this.attribsArray['rDir'] = ( this.attribsArray['layerRgb']['r'] > this.attribsArray['flashRgb']['r'] ) ? 'pos' : 'neg';
				this.attribsArray['gDir'] = ( this.attribsArray['layerRgb']['g'] > this.attribsArray['flashRgb']['g'] ) ? 'pos' : 'neg';
				this.attribsArray['bDir'] = ( this.attribsArray['layerRgb']['b'] > this.attribsArray['flashRgb']['b'] ) ? 'pos' : 'neg';
				
				this.flash();
			break;
			
			case "slide":
				if ( !this.attribsArray['direction'] ) return;
				
				if ( this.attribsArray['direction'].indexOf("right") > -1 || this.attribsArray['direction'].indexOf("left") > -1 )
				{
					this.attribsArray['max'] = parseInt( jc.getStyle( this.layerObj, 'width' ) );
				}
				else if ( this.attribsArray['direction'].indexOf("top") > -1 || this.attribsArray['direction'].indexOf("bottom") > -1 )
				{
					this.attribsArray['max'] = parseInt( jc.getStyle( this.layerObj, 'height' ) );
				}
				
				this.attribsArray['fin_mult'] = this.attribsArray['max']/this.max_frame;
				
				this.slide();
			break;
			
			case "scroll":
				if ( !this.attribsArray['direction'] ) return;
				
				this.attribsArray['fin_mult'] = this.attribsArray['by']/this.max_frame;
				
				this.scroll();
			break;
		}
	}
	
	// =============================
	// Fade Effect
	// =============================
	
	this.fade = function()
	{
		if ( this.attribsArray['direction'] == "in" )
		{
			if ( this.frame_count == 0 && this.layerObj.style.display == 'none' )
			{
				this.layerObj.style.display = '';
			}
		
			var opac = Math.round( this.frame_count * this.attribsArray['fin_mult'] );
		}
		else
		{
			var opac = this.attribsArray['max'] - Math.round( this.frame_count * this.attribsArray['fin_mult'] );
		}
		
		if ( this.frame_count <= this.max_frame )
		{
			if ( typeof this.onBeforeRedraw == "function" ) this.onBeforeRedraw();
			
			if ( this.setOpac( this.layerObj, opac ) == -1 )
			{
				// =============================
				// Opacity not available.. 
				// =============================
				
				if ( this.attribsArray['direction'] == "in" )
				{
					this.layerObj.style.display = '';
				}
				else
				{
					this.layerObj.style.display = 'none';
				}
				
				if ( typeof this.onAfterFinish  == "function" ) this.onAfterFinish();
				
				this.running = false;
			}
			else
			{
				// =============================
				// Opacity Available
				// =============================
				
				this.frame_count++;
				
				if ( typeof this.onAfterRedraw == "function" ) this.onAfterRedraw();
				
				// =============================
				// We need to create a seperate reference - "me" for "this", due to the fact
				// that the setTimeout function executes in the scope of the window object
				// =============================
				
				var me = this;
				window.setTimeout( function(){ me.fade() }, this.fms );
			}
		}
		else
		{
			if ( this.attribsArray['direction'] != "in" )
			{
				this.layerObj.style.display = 'none';
				this.setOpac( this.layerObj, this.attribsArray['max'] );
			}
			
			if ( typeof this.onAfterFinish  == "function" ) this.onAfterFinish();
			
			this.frame_count = 0;
			this.running = false;
		}
	}
	
	// =============================
	// "Flash" Effect
	// =============================
	
	this.flash = function()
	{
		if ( this.frame_count <= this.max_frame )
		{
			if ( this.frame_count == 0 )
			{
				this.layerObj.style.backgroundColor = this.attribsArray['color'];
			}
			else
			{
				if ( this.attribsArray['rDir'] == "pos" )
				{
					var r = this.attribsArray['rMin'] + Math.round( this.frame_count * this.attribsArray['fin_mult'] );
					
					if ( r > this.attribsArray['rMax'] ) r = this.attribsArray['layerRgb']['r'];
				}
				else
				{
					var r = this.attribsArray['rMax'] - Math.round( this.frame_count * this.attribsArray['fin_mult'] );
					
					if ( r < this.attribsArray['rMin'] ) r = this.attribsArray['layerRgb']['r'];
				}
				
				if ( this.attribsArray['gDir'] == "pos" )
				{
					var g = this.attribsArray['gMin'] + Math.round( this.frame_count * this.attribsArray['fin_mult'] );
					
					if ( g > this.attribsArray['gMax'] ) g = this.attribsArray['layerRgb']['g'];
				}
				else
				{
					var g = this.attribsArray['gMax'] - Math.round( this.frame_count * this.attribsArray['fin_mult'] );
					
					if ( g < this.attribsArray['gMin'] ) g = this.attribsArray['layerRgb']['g'];
				}
				
				if ( this.attribsArray['bDir'] == "pos" )
				{
					var b = this.attribsArray['bMin'] + Math.round( this.frame_count * this.attribsArray['fin_mult'] );
					
					if ( b > this.attribsArray['bMax'] ) b = this.attribsArray['layerRgb']['b'];
				}
				else
				{
					var b = this.attribsArray['bMax'] - Math.round( this.frame_count * this.attribsArray['fin_mult'] );
					
					if ( b < this.attribsArray['bMin'] ) b = this.attribsArray['layerRgb']['b'];
				}
				
				var newHex = this.rgbToHex( r, g, b );
				
				this.layerObj.style.backgroundColor = newHex;
			}
			
			this.frame_count++;
			
			var me = this;
			window.setTimeout( function(){ me.flash() }, this.fms );
		}
		else
		{
			this.frame_count = 0;
			
			if ( typeof this.onAfterFinish  == "function" ) this.onAfterFinish();
			
			this.running = false;
		}
	}
	
	this.slide = function()
	{
		if ( this.stop ) return;
		
		if ( this.frame_count <= this.max_frame )
		{
			if ( this.frame_count == 0 && ( !this.layerObj.firstChild || this.layerObj.firstChild.rel != "slide_child" ) )
			{
				var absLayer = document.createElement( 'DIV' );
				absLayer.style.position = 'absolute';
				absLayer.style.top = '0px';
				absLayer.style.left = '0px';
					
				if ( this.layerObj.style.display == 'none' ) this.layerObj.style.display = '';
					
				absLayer.innerHTML = this.layerObj.innerHTML;
				absLayer.className = this.layerObj.className;
				absLayer.id = this.layerObj.id;
				absLayer.rel = "slide_child";
					
				if ( jc.getStyle( this.layerObj, 'position' ) != "absolute" ) this.layerObj.style.position = 'relative';
				
				this.layerObj.style.borderTop = '0px';
				this.layerObj.style.borderRight = '0px';
				this.layerObj.style.borderBottom = '0px';
				this.layerObj.style.borderLeft = '0px';
				
				this.layerObj.style.overflow = 'hidden';
				this.layerObj.style.background = 'none';
				if ( jc.is_ie ) this.layerObj.style.filter = '';
				this.layerObj.innerHTML = "";
				this.layerObj.appendChild(absLayer);
			}
			else
			{
				var absLayer = this.layerObj.firstChild;
				
				if ( this.frame_count == 0 && this.layerObj.style.display == 'none' )
				{
					this.layerObj.style.display = '';
				}
			}
			
			if ( this.useEase && this.useEase != "false" )
			{
				var offset = this.Easing.use( this.easeType, this, this.frame_count, 0, this.attribsArray['max'], this.max_frame );
			}
			else
			{
				var offset = Math.round( this.frame_count * this.attribsArray['fin_mult'] );
			}
			
			if ( this.attribsArray['direction'] == "right-out" )
			{
				absLayer.style.left = offset  + 'px';
			}
			else if ( this.attribsArray['direction'] == "left-out" )
			{
				absLayer.style.left = -offset + 'px';
			}
			else if ( this.attribsArray['direction'] == "right-in" )
			{
				absLayer.style.left = Math.round( this.attribsArray['max'] - offset ) + 'px';
			}
			else if ( this.attribsArray['direction'] == "left-in" )
			{
				absLayer.style.left = Math.round( -this.attribsArray['max'] + offset ) + 'px';
			}
			else if ( this.attribsArray['direction'] == "top-out" )
			{
				absLayer.style.top = -offset + 'px';
			}
			else if ( this.attribsArray['direction'] == "bottom-out" )
			{
				absLayer.style.top = offset + 'px';
			}
			else if ( this.attribsArray['direction'] == "top-in" )
			{
				absLayer.style.top = Math.round( -this.attribsArray['max'] + offset ) + 'px';
			}
			else if ( this.attribsArray['direction'] == "bottom-in" )
			{
				absLayer.style.top = Math.round( this.attribsArray['max'] - offset ) + 'px';
			}
			
			this.frame_count++;
			
			if ( typeof this.onAfterRedraw == "function" ) this.onAfterRedraw();
			
			var me = this;
			window.setTimeout( function(){ me.slide() }, this.fms );
		}
		else
		{
			this.frame_count = 0;
			
			if ( typeof this.onAfterFinish  == "function" ) this.onAfterFinish();
			
			this.running = false;
		}
	}
	
	this.grow = function()
	{
		// ...
	}
	
	this.scroll = function()
	{
		if ( this.stop ) return;
		
		if ( this.frame_count <= this.max_frame )
		{
			if ( this.frame_count == 0 )
			{
				this.attribsArray['startOffsetX']    = parseInt(this.layerObj.scrollLeft);
				this.attribsArray['startOffsetY']    = parseInt(this.layerObj.scrollTop);
				this.attribsArray['startTop']        = parseInt(jc.getStyle( this.layerObj, 'top' )) || 0;
				this.attribsArray['startLeft']       = parseInt(jc.getStyle( this.layerObj, 'left' )) || 0;
				
				var re = /rect\s*\(\s*([0-9]+)(?:px)?\s*[\s,]\s*([0-9]+)(?:px)?\s*[\s,]\s*([0-9]+)(?:px)?\s*[\s,]\s*([0-9]+)(?:px)?\s*\)/i;
				
				if ( this.layerObj.style.clip != null && this.layerObj.style.clip != "" )
				{
					var regExec = re.exec( this.layerObj.style.clip );
				}
				else
				{
					var regExec = re.exec( this.attribsArray['clip'] );
				}
				
				if ( regExec != null )
				{
					this.attribsArray['startClipTop']    = parseInt(RegExp.$1);
					this.attribsArray['startClipRight']  = parseInt(RegExp.$2);
					this.attribsArray['startClipBottom'] = parseInt(RegExp.$3);
					this.attribsArray['startClipLeft']   = parseInt(RegExp.$4);
				}
			}
			
			if ( this.useEase && this.useEase != "false" )
			{
				var offset = this.Easing.use( this.easeType, this, this.frame_count, 0, this.attribsArray['by'], this.max_frame );
			}
			else
			{
				var offset = Math.round( this.frame_count * this.attribsArray['fin_mult'] );
			}
			
			if ( this.attribsArray['type'] == "clip" )
			{
				var clipTop    = this.attribsArray['startClipTop'];
				var clipRight  = this.attribsArray['startClipRight'];
				var clipBottom = this.attribsArray['startClipBottom'];
				var clipLeft   = this.attribsArray['startClipLeft'];
				var offTop     = this.attribsArray['startTop'];
				var offLeft    = this.attribsArray['startLeft'];
				
				if ( this.attribsArray['direction'] == "up" )
				{
					clipTop -= offset;
					clipBottom -= offset;
					offTop += offset;
				}
				else if ( this.attribsArray['direction'] == "right" )
				{
					clipLeft += offset;
					clipRight += offset;
					offLeft -= offset;
				}
				else if ( this.attribsArray['direction'] == "down" )
				{
					clipTop += offset;
					clipBottom += offset;
					offTop -= offset;
				}
				else if ( this.attribsArray['direction'] == "left" )
				{
					clipLeft -= offset;
					clipRight -= offset;
					offLeft += offset;
				}
				
				this.layerObj.style.clip = "rect(" + clipTop + "px," + clipRight + "px," + clipBottom + "px," + clipLeft + "px)";
				this.layerObj.style.top = offTop + 'px';
				this.layerObj.style.left = offLeft + 'px';
			}
			else
			{
				if ( this.attribsArray['direction'] == "up" )
				{
					this.layerObj.scrollTop = this.attribsArray['startOffsetY'] - offset;
				}
				else if ( this.attribsArray['direction'] == "right" )
				{
					this.layerObj.scrollLeft = this.attribsArray['startOffsetX'] + offset;
				}
				else if ( this.attribsArray['direction'] == "down" )
				{
					this.layerObj.scrollTop = this.attribsArray['startOffsetY'] + offset;
				}
				else if ( this.attribsArray['direction'] == "left" )
				{
					this.layerObj.scrollLeft = this.attribsArray['startOffsetX'] - offset;
				}
			}
			
			this.frame_count++;
			
			if ( typeof this.onAfterRedraw == "function" ) this.onAfterRedraw();
			
			var me = this;
			window.setTimeout( function(){ me.scroll() }, this.fms );
		}
		else
		{
			this.frame_count = 0;
			
			if ( typeof this.onAfterFinish  == "function" ) this.onAfterFinish();
			
			this.running = false;
		}
	}
	
	this.getBgColor = function( layerObj )
	{
		var bgColor = "";
		
		if ( layerObj.style.backgroundColor )
		{
			bgColor = layerObj.style.backgroundColor;
		}
		else
		{
			if ( jc.getStyle(layerObj, 'backgroundColor') )
			{
				bgColor = jc.getStyle(layerObj, 'backgroundColor');
			}
			else if ( jc.getStyle(layerObj, 'background-color') )
			{
				bgColor = jc.getStyle(layerObj, 'background-color');
			}
		}
		
		if ( bgColor.toLowerCase().indexOf('rgb') > -1 )
		{
			var re = /rgb\s*\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/i;
			
			if ( re.exec( bgColor ) != null )
			{
				bgColor = this.rgbToHex( RegExp.$1, RegExp.$2, RegExp.$3 );
			}
		}
		
		return bgColor.toUpperCase();
	}
	
	// =============================
	// Returns the Opacity of a given layer
	// =============================
	
	this.getOpac = function( layerObj )
	{
		var opacVal = 0;
		
		if ( layerObj.style.opacity != null )
		{
			opacVal = ( layerObj.style.opacity * 100 );
		}
		else if ( layerObj.style.filter != null )
		{
			var opacReg = /opacity=([0-9]{1,3})/i;
			if ( opacReg.exec( layerObj.style.filter ) != null ) opacVal = parseInt( RegExp.$1 );
		}
		else
		{
			return -1;
		}
		
		return opacVal;
	}
	
	// =============================
	// Sets the Opacity of a given layer
	// =============================
	
	this.setOpac = function( layerObj, opacVal )
	{
		if ( layerObj.style.opacity != null )
		{
			layerObj.style.opacity = ( opacVal / 100 );
		}
		else if ( layerObj.style.filter != null )
		{
			var filterStr = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=' + opacVal + ')';
			if ( this.attribsArray['extrafilter'] ) filterStr += ' progid:' + this.attribsArray['extrafilter'];
			layerObj.style.filter = filterStr;
		}
		else
		{
			return -1;
		}
	}
	
	this.hexToRgb = function( hex )
	{
		var hex = ( hex.charAt(0) == "#" ) ? hex.substring(1,7) : hex;
		var hex = ( hex.length == 3 ) ? hex+hex : hex;
		
		var rgb = Array();
		
		rgb['r'] = parseInt( hex.substring(0,2), 16 );
		rgb['g'] = parseInt( hex.substring(2,4), 16 );
		rgb['b'] = parseInt( hex.substring(4,6), 16 );
		
		return rgb;
	}
	
	this.rgbToHex = function( r, g, b )
	{
		this.toHex = function( n )
		{
			if ( n == null ) return "00";
			
			n = parseInt(n);
			
			if ( n == 0 || isNaN(n) ) return "00";
			
			n = Math.max( 0, n );
			n = Math.min( n, 255 );
			n = Math.round( n );
			
			return "0123456789ABCDEF".charAt( (n-n%16)/16 ) +
				   "0123456789ABCDEF".charAt( n%16 );
		}
		
		return '#' + this.toHex(r) + this.toHex(g) + this.toHex(b);
	}
	

	/*
	TERMS OF USE - EASING EQUATIONS
	Open source under the BSD License.
	Copyright © 2001 Robert Penner
	All rights reserved.
	
	Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
	
	* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
	* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
	* Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
	
	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
	*/
	
	this.Easing = 
	{
		/**
		* t Current Time (frame count)
		* b Beginning position (min)
		* c Total Change in position (max)
		* d Duration (max frame)
		* a Amplitude (optional) - for elastic easing
		* p Period (optional) - for elastic easing
		* s Overshoot amount (optional) - for back easing
		*/
		
		use: function( easeType, parObj, t, b, c, d )
		{
			try
			{
				eval( "var v = this." + easeType + "(" + t + "," + b + "," + c + "," + d + ")" );
			}
			catch(e)
			{
				parObj.error( easeType + ': Invalid Easing Type' );
			}
			
			return Math.round( v );
		},
		
		/**
		* quadratic easing in - accelerating from zero velocity
		*/
		easeIn: function ( t, b, c, d )
		{
			return c*(t/=d)*t + b;
		},
		
		/**
		* quadratic easing out - decelerating to zero velocity
		*/
		easeOut: function ( t, b, c, d )
		{
			return -c *(t/=d)*(t-2) + b;
		},
		
		/**
		* quadratic easing in/out - acceleration until halfway, then deceleration
		*/
		easeInOut: function ( t, b, c, d )
		{
			if ((t/=d/2) < 1) return c/2*t*t + b;
			return -c/2 * ((--t)*(t-2) - 1) + b;
		},
		
		/**
		* quartic easing in - accelerating from zero velocity
		*/
		easeInStrong: function ( t, b, c, d )
		{
			return c*(t/=d)*t*t*t + b;
		},
		
		/**
		* quartic easing out - decelerating to zero velocity
		*/
		easeOutStrong: function ( t, b, c, d )
		{
			return -c * ((t=t/d-1)*t*t*t - 1) + b;
		},
		
		/**
		* quartic easing in/out - acceleration until halfway, then deceleration
		*/
		easeInOutStrong: function ( t, b, c, d )
		{
			if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
			return -c/2 * ((t-=2)*t*t*t - 2) + b;
		},
		
		/**
		* back easing in - backtracking slightly, then reversing direction and moving to target
		*/
		easeInBack: function ( t, b, c, d, s )
		{
			if (typeof s == 'undefined') s = 1.70158;
			return c*(t/=d)*t*((s+1)*t - s) + b;
		},
		
		/**
		* back easing out - moving towards target, overshooting it slightly, then reversing and coming back to target
		*/
		easeOutBack: function ( t, b, c, d, s )
		{
			if (typeof s == 'undefined') s = 1.70158;
			return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
		},
		
		/**
		* back easing in/out - backtracking slightly, then reversing direction and moving to target,
		* then overshooting target, reversing, and finally coming back to target
		*/
		easeInOutBack: function ( t, b, c, d, s )
		{
			if (typeof s == 'undefined') s = 1.70158; 
			if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
			return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
		},
		
		/**
		* snap in elastic effect
		*/
		easeInElastic: function ( t, b, c, d, a, p )
		{
			if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
			if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
			else var s = p/(2*Math.PI) * Math.asin (c/a);
			return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		},
	
		/**
		* snap out elastic effect
		*/
		easeOutElastic: function ( t, b, c, d, a, p )
		{
			if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
			if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
			else var s = p/(2*Math.PI) * Math.asin (c/a);
			return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
		},
		
		/**
		* snap both elastic effect
		*/
		easeInOutElastic: function ( t, b, c, d, a, p )
		{
			if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
			if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
			else var s = p/(2*Math.PI) * Math.asin (c/a);
			if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
			return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
		},
		
		/**
		* bounce in
		*/
		easeInBounce: function ( t, b, c, d )
		{
			return c - this.easeOutBounce(d-t, 0, c, d) + b;
		},
		
		/**
		* bounce out
		*/
		easeOutBounce: function ( t, b, c, d )
		{
			if ( (t/=d) < (1/2.75) )
			{
				return c*(7.5625*t*t) + b;
			}
			else if ( t < (2/2.75) )
			{
				return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
			}
			else if ( t < (2.5/2.75) )
			{
				return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
			}
			else
			{
				return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
			}
		},
		
		/**
		* bounce both
		*/
		easeInOutBounce: function ( t, b, c, d )
		{
			if (t < d/2) return this.easeInBounce(t*2, 0, c, d) * .5 + b;
			return this.easeOutBounce(t*2-d, 0, c, d) * .5 + c*.5 + b;
		}
	};
}
