var g_arrMousePos	= []
, g_arrMouseOffset	= []
, g_arrAccordions	= []
, g_arrAni			= []
, g_oAniToolTip
, g_iDrag
, domReady			= false
, ie				= navigator.appName == 'Microsoft Internet Explorer' && (!window.opera)
, ie6				= false /*@cc_on || @_jscript_version < 5.7 @*/
, userAgent			= navigator.userAgent.toLowerCase()
, Event, MouseEvent, KeyboardEvent // Need these variables as an IE fix for getType
, Events = [] //Saves event hooks as Events[Dom Element][Event Name][Function]
, Browser = 
{
	version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
	safari: /webkit/.test(userAgent),
	opera: /opera/.test(userAgent),
	msie: (/msie/.test(userAgent)) && (!/opera/.test(userAgent)),
	mozilla: (/mozilla/.test(userAgent)) && (!/(compatible|webkit)/.test(userAgent)),
	mobileSafari: (/(mobile safari|iphone|ipad)/.test(userAgent)),
	ios: (/(iphone|ipad)/.test(userAgent))
};


Array.prototype.inArray = function(value)
{
	var i;
	for (i=0; i < this.length; i++)
	{
		if (this[i] === value)
			return true;
	}
	return false;
};

Array.prototype.addEach = function(p_Array2)
{
	var l_Array1 = this.slice();
	for(var i = 0; i < l_Array1.length; i++)
	{
		l_Array1[i] += p_Array2[i];
	}
	return l_Array1;
};

Array.prototype.substractEach = function(p_Array2)
{
	var l_Array1 = this.slice();
	for(var i = 0; i < l_Array1.length; i++)
	{
		l_Array1[i] -= p_Array2[i];
	}
	return l_Array1;
};

Function.prototype.bind = function(obj)
{
	var method = this,
	temp = function()
	{
		return method.apply(obj, arguments);
	};
	return temp;
};

Object.prototype.merge = function(b, overwrite)
{
	var b = b || {};
	for(var k in b)
	{
		if(overwrite != undefined && k in this) 
			continue;
		this[k] = b[k];
	}
	return this;
}

Object.prototype.clone = function() 
{
	var newObj = (this instanceof Array) ? [] : {};
	for(i in this)
	{
		if(i == 'clone')
			continue;
		if(this[i] && typeof this[i] == "object")
			newObj[i] = this[i].clone();
		else 
			newObj[i] = this[i]
	}
	return newObj;
};

function getAni(p_varElement, p_strFriendlyName, p_bUseClone)
{
	p_varElement = getElement(p_varElement);
	if(notNull(p_varElement.oAni))
		return p_varElement.oAni;
	else
		return new animatio(p_varElement, p_strFriendlyName, p_bUseClone);
}

function getAnimatioByName(p_strName)
{
	for(var i = 0; i < g_arrAni.length; i++)
	{
		if(g_arrAni[i].strFriendlyName == p_strName)
			return g_arrAni[i];
	}
	return false;
}

function getAnimatioByGuid(p_strGuid)
{
	for(var i = 0; i < g_arrAni.length; i++)
	{
		if(g_arrAni[i].strGuid == p_strGuid)
			return g_arrAni[i];
	}
	return false;
}

function initAccordion()
{
	var i, n, l_iGroup = -1, l_iItem = -1, _oAnimatio, l_arrAccordions = [], l_arrDivs;
	l_arrDivs = getElementsByClass('accordionGroup', document, 'DIV');
	
	for (i = 0; i < l_arrDivs.length; i++)
	{
		l_iGroup++;
		g_arrAccordions[l_iGroup] = -1;
		l_arrAccordions = getElementsByClass('accordionItem', l_arrDivs[i], 'DIV');
		for(n = 0; n < l_arrAccordions.length; n++)
		{
			if(notNull(l_arrAccordions[n].oAni))
				break;
				
			l_iItem++;
			l_arrAccordions[n].className += " closed";
			_oAnimatio = new animatio(l_arrAccordions[n], "accordionItem_" + l_iGroup + "_" + l_iItem, false);
			_oAnimatio.oAniHeader = new animatio(l_arrAccordions[n].getElementsByTagName("H3")[0], "accordionHeader_" + l_iGroup + "_" + l_iItem, false);
			_oAnimatio.setStyle('color', '#FFFFFF');
			_oAnimatio.oAniHeader.setStyle('color', '#969696');
			_oAnimatio.iAccordionGroup = l_iGroup;
			_oAnimatio.iAccordionItem = l_iItem;
			_oAnimatio.iFullHeight = _oAnimatio.oNewElement.offsetHeight-40;
			_oAnimatio.setStyle('overflow', 'hidden');
			
			var l_iTargetHeight = 17;
			if(_oAnimatio.hasClass('applicationCharts'))
				l_iTargetHeight = 34;
			
			// Some hacking for IE7 
			_oAnimatio.setStyle('height', l_iTargetHeight);
			_oAnimatio.setStyle('height', _oAnimatio.iFullHeight);
			_oAnimatio.setStyle('height', 0);
			_oAnimatio.setStyle('paddingTop', 0);
			_oAnimatio.setStyle('paddingRight', 15);
			_oAnimatio.setStyle('paddingBottom', 0);
			_oAnimatio.setStyle('paddingLeft', 15);
			_oAnimatio.animate(['height', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft'], [l_iTargetHeight, 15, 15 ,15, 15], 25, easeOutCirc);
			
			hookEvent(l_arrAccordions[n].getElementsByTagName("h3")[0], 'click', aniEVENT_onclickAccordion);
		}
		
	}
}

function aniShowAccordion()
{
	if(!this.hasClass('open'))
	{
		var l_iFrames = 25;
		var l_iLastAccordion = g_arrAccordions[this.iAccordionGroup];
		this.enqueue('animate', [['[\'overflow\']'], ['[\'visible\']'], 1, linearTween], 1);
		this.enqueue('animate', [['[\'height\']'], ['[\'auto\']'], 1, linearTween], 1);
		this.stop().animate(['height', 'color'], [this.iFullHeight, '#353535'], l_iFrames, easeInCirc);
		this.oAniHeader.animate(['color'], ['#E95D0E'], l_iFrames, easeInCirc);
		this.removeClass('closed');
		this.addClass('open');
		if(l_iLastAccordion != -1 & l_iLastAccordion != this.iAccordionItem)
		{
			var l_oBgDivLastAccordion = getAnimatioByName("accordionItem_" + this.iAccordionGroup + "_" + l_iLastAccordion);
			l_oBgDivLastAccordion.hideAccordion();
		}
		g_arrAccordions[this.iAccordionGroup] = this.iAccordionItem;
	}
}

function aniHideAccordion()
{
	var l_iFrames = 25;
	if(this.bInProgress)
		this.stop(true);
	else
		this.setStyle('height', this.iFullHeight);
	var l_iTargetHeight = 17;
	if(this.hasClass('applicationCharts'))
		l_iTargetHeight = 34;
	this.stop().animate(['height', 'overflow', 'color'], [l_iTargetHeight, 'hidden', '#FFFFFF'], l_iFrames, easeOutCirc);
	this.oAniHeader.stop();
	this.oAniHeader.animate(['color'], ['#969696'], l_iFrames, easeInCirc);
	this.removeClass('open');
	this.addClass('closed');
	g_arrAccordions[this.iAccordionGroup] = -1;
}

function aniToggleAccordion()
{
	if(this.hasClass('open'))
		this.hideAccordion();
	else
		this.showAccordion();
}

function aniEVENT_onclickAccordion(e)
{
	var l_oElement = getEventTarget(e);
	while(!notNull(l_oElement.oAni) | l_oElement.tagName == "H3")
		l_oElement = l_oElement.parentNode;
	if(notNull(l_oElement.oAni))
	{
		var l_oBgDivAccordion = l_oElement.oAni
		l_oBgDivAccordion.toggleAccordion();
		//hookEvent(l_oElement, 'animationEnd', aniEVENT_onanimationEndAccordion, l_oBgDivAccordion);
	}
}

function aniEVENT_onanimationEndAccordion()
{
	if(this.hasClass('open'))
		ss.smoothScroll(this.oNewElement);
	//animationEnd
}


function getZoomImages()
{
	var l_arrImages = document.getElementsByTagName('img');
	var l_arrLargeImages = new Array();
	var l_strLargeImage;
	var l_iPos;
	var l_arrClassNames;
	for (i = 0; i < l_arrImages.length; i++)
	{
		l_arrClassNames = l_arrImages[i].className.split(' ');
		for (n = 0; n < l_arrClassNames.length; n++)
		{
			l_iPos = l_arrClassNames[n].indexOf('zoom-');
			if (l_iPos != -1) 
			{
				l_strLargeImage = l_arrClassNames[n].substring(l_iPos + 5);
				l_arrLargeImages[n] = new Image();
				l_arrLargeImages[n].onload = setZoom;
				l_arrLargeImages[n].src = l_strLargeImage;
				l_arrLargeImages[n].oThumbnail = l_arrImages[i];
			}
			l_iPos2 = l_arrClassNames[n].indexOf('morph-');
			if (l_iPos2 != -1) 
			{
				l_strLargeImage = l_arrClassNames[n].substring(l_iPos2 + 6);
				l_arrLargeImages[n] = new Image();
				l_arrLargeImages[n].onload = setMorph;
				l_arrLargeImages[n].src = l_strLargeImage;
				l_arrLargeImages[n].oThumbnail = l_arrImages[i];
			}
		}
	}
}

function setZoom()
{
	if(notNull(this.oThumbnail))
	{
		var l_oThumbnail = this.oThumbnail;
		l_oThumbnail.style.cursor = 'pointer';
		l_oThumbnail.style.cursor = 'hand';
		var l_oLargeImage = this;
		hookEvent(l_oThumbnail, 'click', function(){hoverimage(l_oThumbnail, l_oLargeImage.src, l_oLargeImage.width, l_oLargeImage.height)});
	}
}

function hoverimage(p_oThumbnail, p_strHighResImageSrc, p_iTargetWidth, p_iTargetHeight)
{
	var l_animatio = new animatio(p_oThumbnail);
	l_animatio.setStyle('margin', 0);
	l_animatio.setStyle('zIndex', 101);
	l_animatio.zoom(p_iTargetHeight, p_iTargetWidth, p_strHighResImageSrc, 0);
	hookEvent(l_animatio.oNewElement, 'mouseout', function(){l_animatio.stop();l_animatio.fadeToRestore()});
	hookEvent(l_animatio.oNewElement, 'click', function(){l_animatio.fadeToRestore()});
}

function setMorph()
{
	var l_oThumbnail = this.oThumbnail;
	var l_oLargeImage = this;
	hookEvent(l_oThumbnail, 'mouseover', function(){morphimage(l_oThumbnail, l_oLargeImage.src)});
}

function morphimage(p_oThumbnail, p_strHighResImageSrc)
{
	if(!notNull(p_oThumbnail.oAni))
	{
		var l_animatio = new animatio(p_oThumbnail);
		l_animatio.oNewElement.src = p_strHighResImageSrc;
		l_animatio.oElement.style.visibility = 'visible';
		l_animatio.setStyle('opacity', 0);
		l_animatio.animate(['opacity'], [1], 15, easeOutSine);
		hookEvent(l_animatio.oNewElement, 'mouseout', function(){l_animatio.oNewElement.oAni.fadeOut(6,true)});
	}
}

function closeToolTip()
{
	unhookEvent(document, 'keyup', aniEVENT_onEscKeyCloseTT);
	var l_oAniContainer = getAnimatioByName('ToolTip')
		,l_oAniContent = getAnimatioByName('ToolTipContent')
		,l_oAniBg = getAnimatioByName('Background');
	
	if(notNull(l_oAniBg.animate))
	{
		l_oAniBg.animate(['opacity'], [0], 10, easeInQuad);
		g_oAniToolTip = null;
		l_oAniContent.restore();
		l_oAniContainer.restore();
		l_oAniBg.enqueue('restore');
	}
}

function showToolTip(p_strUrl, p_strHeader, p_iWidth, p_iHeight, p_bScroll)
{
	if(typeof p_strUrl != 'undefined')
	{
		p_arrDimensions = [p_iWidth || 786, p_iHeight|| getPageSize()[1] - 40];
		var l_arrPageSize	= getPageSize()
		// Tooltip is not yet open
		if(!notNull(g_oAniToolTip))
		{
			var l_oContainerDiv	= document.createElement("DIV");
			l_oContainerDiv.innerHTML = '<div class="TTHeader"><a class="TTCloseBtn" onclick="closeToolTip()"></a><h2 class="TTHeadline"></h2></div><div class="TTContent" id="TTContent"></div>';
			var l_oHeader		= l_oContainerDiv.getElementsByTagName("H2")[0]
				, l_oToolTipDiv	= l_oContainerDiv.getElementsByTagName("DIV")[1]
				, l_oBgDiv		= document.createElement("DIV");
		
			window.document.body.appendChild(l_oBgDiv);
			window.document.body.appendChild(l_oContainerDiv);
		
			var l_oAniBg = new animatio(l_oBgDiv, 'Background', false)
				, l_oAniContainer = new animatio(l_oContainerDiv, 'ToolTip', false)
				, l_oAniContent	= new animatio(l_oToolTipDiv, 	'ToolTipContent', false);
			l_oAniContainer.oNewElement.id = l_oAniContainer.strGuid;
		
			//l_oAniBg.setStyle(['backgroundColor', 'position','top', 'right', 'bottom','left','zIndex','opacity','textAlign'], ['#555','fixed',0,0,0,0,100,0.0001,'center']);
			l_oAniBg.addClass('overlay');
		
			l_oAniContainer.setStyle(['width', 'top'], [p_arrDimensions[0], l_arrPageSize[1]/2]);
			l_oAniContainer.addClass('TTContainer');
			l_oAniContainer.setStyle('marginLeft', -1*p_arrDimensions[0]/2);
		
			l_oAniContent.setStyle('height', p_arrDimensions[1] - 88);
			l_oAniContainer.animate(['height', 'top'], [p_arrDimensions[1], (l_arrPageSize[1]-p_arrDimensions[1])/2], 10, linearTween);
			
			// scrollbars
			if(typeof p_bScroll == "undefined" || p_bScroll == true)
				l_oAniContainer.enqueue('setStyle', ['\'overflow\'', '\'auto\''], 10, l_oAniContent.strFriendlyName);
			
			hookEvent(document, 'keyup', aniEVENT_onEscKeyCloseTT);
			hookEvent(l_oBgDiv, 'click', closeToolTip);
			g_oAniToolTip = l_oAniContainer;
		}
		else
		{
			g_oAniToolTip.animate(['marginLeft', 'width', 'height', 'top'], [-1*p_arrDimensions[0]/2, p_arrDimensions[0], p_arrDimensions[1], (l_arrPageSize[1]-p_arrDimensions[1])/2], 40, easeInOutSine);
			if(typeof p_bScroll == "undefined" || p_bScroll == true)
				getAnimatioByName('ToolTipContent').setStyle('overflow', 'auto');
			else
				getAnimatioByName('ToolTipContent').setStyle('overflow', 'hidden');
			
			getAnimatioByName('ToolTip').animate(['height'], [p_arrDimensions[1]], 40, easeInOutSine);
			getAnimatioByName('ToolTipContent').animate(['height'], [p_arrDimensions[1] - 88], 40, easeInOutSine);
			
			var l_oHeader = g_oAniToolTip.oNewElement.getElementsByTagName("H2")[0];
		}
		
		l_oHeader.innerHTML = p_strHeader;
		l_oHeader.oldHTML = null; // Remove sIFR Class

		replaceFonts();
		
		l_oToolTipDiv = l_oToolTipDiv || g_oAniToolTip.oNewElement.getElementsByTagName("DIV")[1];
		ajaxRequest
		(
			{
				'strUrl': p_strUrl,
				'varTargetElement': l_oToolTipDiv,
				'strMethod': 'GET',
				'strBusyHTML': '<img src="images/ajax-loader.gif">',
				'onAfterLoad': function(){l_oToolTipDiv.oAni.setStyle('backgroundColor', '#FFFFFF'); l_oToolTipDiv.oAni.fadeIn(window.ie ? 12 : 7);}
			}
		);
		return false;
	}
}

function aniEVENT_onEscKeyCloseTT(e)
{
	e = getEvent(e);
	if(e.keyCode == 27)
		closeToolTip();
}

function scrollingBoxes()
{
	var i, j, k, _bIsHidden, _oWrapper, _oClip, _arrControls, _oScrollButton, _arrItems, _iContentWidth, _iPagerWidth, _iMargin, _oAniContent, _oAniWrapper, _oCfg, _iSpacing, _oPager, _oPagerItem, _oGlobalCaption
	, l_arrContainers = getElementsByClass('scrollable', document, 'DIV');
	//for(var i=0; i<l_arrContainers.length; i++)
	for(i=0;i<l_arrContainers.length; i++)
	{
		_iContentWidth = 0;
		_iPagerWidth = 0;
		_arrControls = [];
		_bIsHidden = false;
		_arrItems = getElementsByClass('item', l_arrContainers[i]);
		
		/* need to make the box visible to be able to calculate the content's width */
		if(hasClass(_oWrapper, 'Hide'))
		{
			removeClass(_oWrapper, 'Hide');
			_bIsHidden = true;
		}
		
		for(j=0; j<_arrItems.length; j++)
		{
			removeClass(_arrItems[j], 'Hide');
			if(j==0)
				_iSpacing = getStyle(_arrItems[j], 'marginRight');
			_iContentWidth += _arrItems[j].offsetWidth + _iSpacing;
		}
		
		// Wrap two layers of DIVs around the container for the clipping path and give the outermost one the classes of the original container.
		_oWrapper = createNodeBefore(l_arrContainers[i], 'DIV', l_arrContainers[i].className, '<div class="clip"></div>');
		_oClip = _oWrapper.firstChild;
		_oAniContent = new animatio(l_arrContainers[i], 'scrollContent_' + i, false);
		_oWrapper.oAniContent = _oAniContent;
		
		_oWrapper.firstChild.appendChild(l_arrContainers[i]);
		l_arrContainers[i].className="content";
		
		_oGlobalCaption = getElementsByClass('global-caption', l_arrContainers[i], 'H3');
		if(_oGlobalCaption.length > 0)
		{
			_oGlobalCaption = _oGlobalCaption[0];
			_oWrapper.appendChild(_oGlobalCaption);
			_oWrapper.insertBefore(_oGlobalCaption, _oClip);
		}
		
		
		

		
		_oAniContent.setStyle('width', _iContentWidth);
		_oCfg = _oWrapper.oScroll =
		{
			'items': _arrItems,
			'clip': _oClip,
			'content': l_arrContainers[i],
			'page': 1,
			'pageFrac': 1,
			'spacing': _iSpacing,
			'pager': [],
			'init':function()
			{
				var t = this;
				t.pageCount		= hasClass(_oWrapper, 'scrollable-horizontal') ? t.content.offsetWidth / (t.clip.offsetWidth + _iSpacing) : Math.ceil(t.content.offsetHeight / (t.clip.offsetHeight + _iSpacing));
				t.clipWidth		= t.clip.offsetWidth;
				t.clipHeight	= t.clip.offsetHeight;
				t.contentWidth	= t.content.offsetWidth;
				t.contentHeight	= t.content.offsetHeight;
				if(hasClass(_oWrapper, 'show-pager'))
				{
					_oPager = createNodeBefore(l_arrContainers[i], 'DIV', 'pager');
					for (k=0;k<t.pageCount;k++)
					{
						_oPagerItem = t.pager[k] = createNodeBefore(l_arrContainers[i], 'A', 'page-button page-button-' + (k+1));
						if(k==0) addClass(_oPagerItem, 'page-button-active');
						_iPagerWidth += (getStyle(_oPagerItem, 'width') + getStyle(_oPagerItem, 'marginRight'));
						_oPagerItem.page = k+1;
						_oPager.appendChild(_oPagerItem);
					}
					setStyle(_oPager, ['width', 'paddingLeft'], [_iPagerWidth, getStyle(t.pager[0], 'marginRight')/2]);
					_arrControls.push(_oPager);
				}
				if(hasClass(_oWrapper, 'show-nav-buttons'))
				{
					_arrControls.push(_oCfg.nextButton = createNodeBefore(l_arrContainers[i], 'A', 'nextButton'));
					_arrControls.push(_oCfg.prevButton = createNodeBefore(l_arrContainers[i], 'A', 'prevButton'));
				}
				if(hasClass(_oWrapper, 'show-scrollbar') && t.contentWidth > t.clipWidth)
				{
					_arrControls.push(_oCfg.scrollBar = createNodeBefore(l_arrContainers[i], 'DIV', 'scrollbar'));
					_oCfg.scrollBar.appendChild(_oCfg.scrollBarHandle = createNodeBefore(l_arrContainers[i], 'DIV', 'scrollbar-handle'));
					_oCfg.scrollBarHandle.style.width = (t.clipWidth / t.contentWidth) * 100 + '%';
					var oAniSBH = getAni(_oCfg.scrollBarHandle, 'SBH' + i, false);
					var oAniSB = getAni(_oCfg.scrollBar, 'SB' + i, false);
					oAniSBH.enableDrag({'varBoundary': _oCfg.scrollBar, 'funcCallback': handleScroll});
					hookEvent(_oWrapper, 
					['mouseenter', 'mouseleave'], 
					function(e)
					{
						e=getEvent(e);
						e.cancelBubble = true;
						var l_oElement = getEventTarget(e);
						if(hasClass(l_oElement, 'scrollable') && !hasClass(oAniSBH, 'dragActive'))
						{
							l_oElement = l_oElement.parentNode;
							var l_iOpacity = isMouseOutEvent(e) ? .001 : 1;
							oAniSB.stop().animate(['opacity'], [l_iOpacity], 30, easeOutSine);
						}
					});
				}
			}
		};
		_oCfg.init();
		for(j=0; j<_arrControls.length; j++)
		{
			_oWrapper.appendChild(_arrControls[j]);
			hookEvent(_arrControls[j], 'click', handleScroll);
		}
		
		if(_bIsHidden)
			addClass(_oWrapper, 'Hide');
		if(!hasClass(_oWrapper, 'disable-mousewheel'))
			hookEvent(_oWrapper, 'DOMMouseScroll', handleScroll);
	}
}


function handleScroll(e)
{
	e = getEvent(e);
	e.preventDefault();
	var l_oEventTarget	= getEventTarget(e)
	, l_oWrapper	= l_oEventTarget
	, l_bAnimate	= true;
	while(!hasClass(l_oWrapper, 'scrollable'))
		l_oWrapper = l_oWrapper.parentNode;
	var l_oAniContent = l_oWrapper.oAniContent
	, l_oScroller	= l_oWrapper.oScroll
	, l_iTargetPage
	, l_iTargetPx, l_iMouseWheelDelta = getMouseWheelDelta(e)
	, l_iFrames = 75;
	
	/*	
		Repetitive use of the mouse wheel causes the scroller to lose track of which page it's currently on, so we need to recalculate that. 
		We will also decrease the number of frames by 5%, thereby making it go faster as you keep scrolling. 
	*/
	if(l_iMouseWheelDelta != 0 && l_oAniContent.bInProgress)
	{
		l_iFrames = Math.ceil(l_oAniContent.iFrames * .95);
		l_oScroller.pageFrac = Math.abs(l_oAniContent.getStyle('left')) / l_oScroller.clipWidth + 1;
		l_oScroller.page = Math.floor(l_oScroller.pageFrac);
	}
	if(hasClass(l_oEventTarget, 'pager'))
		return;
	
	if(hasClass(l_oWrapper, 'scrollable-horizontal'))
	{
		if(hasClass(l_oEventTarget, 'page-button'))
		{
			l_iTargetPage = l_oEventTarget.page;
		}
		else 
		{
			if(hasClass(l_oEventTarget, 'scrollbar-handle'))
			{
				if(e.type != 'AnimatioDragEvent')return;
				l_iTargetPage = 1 + (l_oScroller.pageCount-1) * (e.Position[0]/(e.oAni.oDragOptions.varBoundary.offsetWidth - getDimensions(e.oAni)[0]));
				l_bAnimate = false;
			}
			else if(l_iMouseWheelDelta != 0)
			{
				l_iTargetPage = l_oScroller.pageFrac + -1 * l_iMouseWheelDelta / Math.abs(l_iMouseWheelDelta);
			}
			else if(hasClass(l_oEventTarget, 'prevButton'))
			{
				if(l_oScroller.page > 1)
					l_iTargetPage = l_oScroller.page-1;
				else 
					l_iTargetPage = l_oScroller.pageCount;
			}
			else //forward
			{
				if(l_oScroller.page < l_oScroller.pageCount)
					l_iTargetPage = l_oScroller.page + 1;
				else
					l_iTargetPage = 1;
			}
			if(l_iTargetPage > l_oScroller.pageCount)
				l_iTargetPage = l_oScroller.pageCount;
			if(l_iTargetPage < 1)
				l_iTargetPage = 1;
		}
		if(hasClass(l_oWrapper, 'show-pager'))
		{
			removeClass(l_oScroller.pager[l_oScroller.page - 1], 'page-button-active');
			addClass(l_oScroller.pager[Math.floor(l_iTargetPage - 1)], 'page-button-active');
		}

		l_iTargetPx = -l_oScroller.clipWidth * l_iTargetPage + l_oScroller.clipWidth - ((l_iTargetPage-1) * l_oScroller.spacing);
		
		l_iFrames = Math.abs((l_oAniContent.getStyle('left')-l_iTargetPx)/20);
		l_iFrames = lowerLimit(l_iFrames, 30);
		//l_iFrames = Math.floor(Math.abs(l_iTargetPage-l_oScroller.pageFrac) * l_iFrames);
		l_oScroller.pageFrac = l_iTargetPage;
		l_oScroller.page = Math.floor(l_iTargetPage);

		if(l_bAnimate && hasClass(l_oWrapper, 'show-scrollbar'))
		{
			if(!!l_oScroller.scrollBarHandle)
			{
				l_oScroller.scrollBarHandle.oAni.stop().animate(['left'], [((l_iTargetPage-1)/(l_oScroller.pageCount-1)) * (l_oScroller.scrollBar.offsetWidth - l_oScroller.scrollBarHandle.offsetWidth)], l_iFrames, easeOutSine);
			}
		}
		if(l_bAnimate)
			l_oAniContent.stop().animate(['left'], [l_iTargetPx], l_iFrames, easeOutSine);
		else
			l_oAniContent.stop().setStyle('left', l_iTargetPx);
	}
	else
	{
		l_oAniContent.animate(['top'], [l_oAniContent.getStyle('top')-440], l_iFrames, easeInOutSine);
	}
}


function ajaxRequest(p_oOptions)
{
	/*
		p_oOptions.strUrl
		p_oOptions.varTargetElement
		p_oOptions.strMethod
		p_oOptions.strPostData
		p_oOptions.strBusyHTML
		p_oOptions.onBeforeLoad
		p_oOptions.onAfterLoad
		p_oOptions.bShowThrobber
		p_oOptions.bAppendResults
	*/
	
	var l_oRequest = null;
	if(window.XMLHttpRequest) 
		l_oRequest = new XMLHttpRequest(); 
	else if(window.ActiveXObject)
	{
		try 
		{
			l_oRequest = new ActiveXObject('Msxml2.XMLHTTP'); // IE 5
		}
		catch (e)
		{
			try
			{
				l_oRequest = new ActiveXObject('Microsoft.XMLHTTP'); // IE 6	
			}
			catch (e)
			{
				return true;
			}
		}
	}
	l_oRequest.bProcessed = false;
	l_oRequest.id = new Date().getTime();
	if(notNull(p_oOptions.onBeforeLoad))
		p_oOptions.onBeforeLoad();
	if(notNull(p_oOptions.bShowThrobber))
		showThrobber(getElement(p_oOptions.varTargetElement));
	
	l_oRequest.onreadystatechange = function()
	{
		if(notNull(p_oOptions.varTargetElement))
			l_oHTML = getElement(p_oOptions.varTargetElement);

		if(l_oRequest.readyState == 1 && notNull(p_oOptions.strBusyHTML))
		{
			//ajaxResultReplace(l_oHTML, p_oOptions)
			l_oHTML.innerHTML = p_oOptions.strBusyHTML;
			
		}
		if(l_oRequest.readyState == 4 && l_oRequest.status == 200)
		{
			if(typeof l_oHTML != 'undefined')
			{
				if(notNull(l_oHTML)){
					if(notNull(p_oOptions.bAppendResults))
						ajaxResultsAppend(l_oHTML, l_oRequest)
					else
						ajaxResultReplace(l_oHTML, l_oRequest)
					//l_oHTML.innerHTML = l_oRequest.responseText;
				}
				onAfterAjaxRequestProcessResult(l_oHTML);
			}
			if(notNull(p_oOptions.onAfterLoad))
				p_oOptions.onAfterLoad(l_oRequest.responseText);
		}
	};
	
	l_oRequest.open(p_oOptions.strMethod, p_oOptions.strUrl, true);
	if(p_oOptions.strMethod == 'POST')
		l_oRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	l_oRequest.send(p_oOptions.strPostData);
	return false;
}
function ajaxResultsAppend(l_oHTML, l_oRequest)
{
	l_oHTML.innerHTML += l_oRequest.responseText;
}
function ajaxResultReplace(l_oHTML, l_oRequest)
{
	l_oHTML.innerHTML = l_oRequest.responseText;
}
function showThrobber(pTarget)
{
	var target 			= ((pTarget)?pTarget:'CONTENT_TABLE');
	var tgtCont   	  	= getElement(target);
	var ovrDIV      	= document.createElement("div");
	ovrDIV.className 	= "aixLoadOverlay";
	ovrDIV.style.height = tgtCont.offsetHeight + "px";
	ovrDIV.style.width  = tgtCont.offsetWidth + "px";
	ovrDIV.style.zIndex = 98;
	ovrDIV.style.top    = tgtCont.offsetTop + "px";
	var imgCont 	  	= document.createElement("div");
	imgCont.style.zIndex = 99;
	imgCont.innerHTML 	= '<img src="/images/ajax-pager-throbber_3.gif" style="float:left;" />';
	imgCont.className 	= "aixLoadImgCont";
	tgtCont.appendChild(imgCont);
	imgCont.style.top   = (parseInt(ovrDIV.style.top) + (parseInt(ovrDIV.style.height) / 2) - (parseInt(imgCont.offsetHeight) / 2)) + "px";
	imgCont.style.left  = (parseInt(ovrDIV.offsetLeft) + (parseInt(ovrDIV.style.width) / 2) - (parseInt(imgCont.offsetWidth) / 2)) + "px";
	tgtCont.appendChild(ovrDIV);
}
function onAfterAjaxRequestProcessResult(p_oHTML)
{
	initAccordion();
	getZoomImages();
	hideElementGroups();
	inputFieldsWatermarks();
	replaceFonts();
	sliders();
	var l_arrScriptTags = p_oHTML.getElementsByTagName("SCRIPT")
		, _oScript;
	for (var i=0; i<l_arrScriptTags.length; i++)
	{
		if(window.execScript)
		{
			window.execScript(l_arrScriptTags[i].text);
		}
		else
		{
			_oScript = document.createElement('SCRIPT'); 
			_strContent = document.createTextNode(l_arrScriptTags[i].text)
			_oScript.appendChild(_strContent);
			_oScript.type = "text/javascript";
			_oScript.defer = false;
			document.body.appendChild(_oScript); 
			//if(l_arrScriptTags[i].attributes["src"])
			//	_oScript.src = l_arrScriptTags[i].src; 
		}
	}
}

function animatio(p_varElement, p_strFriendlyName, p_bUseClone)
{
	if (typeof p_bUseClone == "undefined")
		p_bUseClone = true;
	this.id								= g_arrAni.length;
	g_arrAni[this.id]			= this;
	this.arrStart 						= [];
	this.arrCurrent 					= [];
	this.arrChange						= [];
	this.arrSteppings 					= [];
	this.arrImages 						= [];
	this.arrImagesHref 					= [];
	this.arrPlaylist 					= [];
	this.iTimeout						= -1;
	this.bDragable						= false;
	this.bInProgress					= false;
	this.strGuid	 					= guid();
	this.oElement 						= getElement(p_varElement);
	this.arrStartPos 					= getPosition(this.oElement);
	if(p_bUseClone)
	{
		this.oNewElement					= this.oElement.cloneNode(true);
		window.document.body.appendChild(this.oNewElement);
		this.oElement.style.visibility 		= 'hidden';
		with(this.oNewElement)
		{
			id 								= this.strGuid;
			className						= '';
			style.cursor 					= '';
			style.position 					= 'absolute';
			style.left 						= this.arrStartPos[0] + 'px';
			style.top 						= this.arrStartPos[1] + 'px';
			style.width						= offsetWidth + 'px';
			style.height					= offsetHeight + 'px';
			setAttribute('onclick',			null);
			setAttribute('ondblclick',		null);
			setAttribute('onmouseover',		null);
			setAttribute('onmouseout',		null);
			setAttribute('onmousedown',		null);
			setAttribute('onmouseup',		null);
			setAttribute('onkeydown',		null);
			setAttribute('onkeypress',		null);
			setAttribute('onkeyup',			null);
			setAttribute('onload',			null);
			setAttribute('onunload',		null);
			setAttribute('onbeforeunload',	null);
			setAttribute('onfocus',			null);
			setAttribute('onblur',			null);
		}
	}
	else
	{
		this.oNewElement				= this.oElement;
	}
	this.strFriendlyName	 			= p_strFriendlyName;
	this.oElement.oAni					= this;
	this.oNewElement.oAni				= this;
}
animatio.prototype.showAccordion		= aniShowAccordion;
animatio.prototype.hideAccordion		= aniHideAccordion;
animatio.prototype.toggleAccordion		= aniToggleAccordion;
animatio.prototype.animate				= aniAnimate;
animatio.prototype.next					= aniNext;
animatio.prototype.stop					= aniStop;
animatio.prototype.enqueue				= aniEnqueue;
animatio.prototype.getStyle				= aniGetStyle;
animatio.prototype.setStyle				= aniSetStyle;
animatio.prototype.hasClass				= aniHasClass;
animatio.prototype.addClass				= aniAddClass;
animatio.prototype.removeClass			= aniRemoveClass;
animatio.prototype.getHoverState		= aniGetHoverState;
animatio.prototype.getPosition			= aniGetPosition;
animatio.prototype.getAbsolutePosition	= aniGetAbsolutePosition;
animatio.prototype.setPosition			= aniSetPosition;
animatio.prototype.setOpacity			= aniSetOpacity;
animatio.prototype.enableDrag			= aniEnableDrag;
animatio.prototype.disableDrag			= aniDisableDrag;

animatio.prototype.setSrc				= aniSetSrc;
animatio.prototype.move					= aniMove;
animatio.prototype.fadeOut				= aniFadeOut;
animatio.prototype.fadeIn				= aniFadeIn;
animatio.prototype.shrinkV				= aniShrinkVertical;
animatio.prototype.shrinkH				= aniShrinkHorizontal;
animatio.prototype.pulsate				= aniPulsate;
animatio.prototype.yellowFade			= aniYellowFade;
animatio.prototype.zoom					= aniZoom;

animatio.prototype.fadeToRestore		= aniFadeToRestore;
animatio.prototype.restore				= aniRestoreElement;

function aniAnimate(p_arrProperties, p_arrValues, p_iFrames, p_funcTransition)
{
	if(this.bInProgress & notNull(this.arrProperties))
	{
		this.iTime++;
		fireEvent(this.oNewElement, 'enterFrame');
		for (var i = 0; i < this.arrProperties.length; i++)
		{
			switch(getType(this.arrCurrent[i]))
			{
				case "array":
					this.arrCurrent[i][0] = parseInt(this.funcTransition(this.iTime, this.arrStart[i][0], this.arrChange[i][0], this.iFrames));
					this.arrCurrent[i][1] = parseInt(this.funcTransition(this.iTime, this.arrStart[i][1], this.arrChange[i][1], this.iFrames));
					this.arrCurrent[i][2] = parseInt(this.funcTransition(this.iTime, this.arrStart[i][2], this.arrChange[i][2], this.iFrames));
					break;
				case "number":
					this.arrCurrent[i] = this.funcTransition(this.iTime, this.arrStart[i], this.arrChange[i], this.iFrames);
					break;
				case "string":
					break;
			}
			this.setStyle(this.arrProperties[i], this.arrCurrent[i]);
		}
		fireEvent(this.oNewElement, 'exitFrame');
		
		if (this.iTime < this.iFrames)
		{
			this.iTimeout = window.setTimeout(this.animate.bind(this), 10);
		}
		else
		{
			window.clearTimeout(this.iTimeout);
			this.arrStart 		= [];
			this.arrCurrent		= [];
			this.arrChange		= [];
			this.arrSteppings	= [];
			this.arrProperties	= [];
			this.bInProgress	= false;
			this.next();
			fireEvent(this.oNewElement, 'animationEnd');
		}
	}
	else if(!this.bInProgress & notNull(p_arrProperties))
	{
		this.bInProgress	= true;
		this.iTime			= 0;
		this.arrProperties	= p_arrProperties;
		this.arrValues		= p_arrValues;
		this.iFrames		= p_iFrames;
		this.funcTransition	= p_funcTransition || this.funcTransition || easeInOutSine;
		for (var i = 0; i < this.arrProperties.length; i++)
		{
			this.arrStart[i] = this.getStyle(this.arrProperties[i]);
			if(getType(this.arrValues[i]) == 'string')
				if(this.arrValues[i].indexOf("#") != -1)
					this.arrValues[i] = hexToRGB(this.arrValues[i]);
			switch(getType(this.arrValues[i]))
			{
				case 'array':
					this.arrValues[i]	= hexToRGB(this.arrValues[i]);
					this.arrChange[i] 	= [
						parseFloat(this.arrValues[i][0] - this.arrStart[i][0]), 
						parseFloat(this.arrValues[i][1] - this.arrStart[i][1]), 
						parseFloat(this.arrValues[i][2] - this.arrStart[i][2])
					];
					this.arrSteppings[i] = [
						this.arrChange[i][0] / this.iFrames,
						this.arrChange[i][1] / this.iFrames,
						this.arrChange[i][2] / this.iFrames,
					];
					this.arrCurrent[i] = new Array().concat(this.arrStart[i]);
					break;
				case 'string':
					this.arrChange[i] = '';
					this.arrSteppings[i] = '';
					this.arrCurrent[i] = this.arrValues[i];
					this.setStyle(this.arrProperties[i], this.arrValues[i]);
					break;
				default:
					this.arrChange[i] = this.arrValues[i] - this.arrStart[i];
					this.arrSteppings[i] = this.arrChange[i] / this.iFrames;
					this.arrCurrent[i] = this.arrStart[i];
					break;
			}
		}
		fireEvent(this.oNewElement, 'animationStart');
		this.iTimeout = window.setTimeout(this.animate.bind(this), 10);
	}
	else if(!notNull(this.arrProperties))
		return;
}

function aniNext()
{
	if(getType(this.arrPlaylist[0]) == 'array')
	{
		var l_arrNextItem	= this.arrPlaylist.shift();
		var l_strFunction	= l_arrNextItem[0];
		var l_strParams		= notNull(l_arrNextItem[1]) ? l_arrNextItem[1].join(',') : '';
		var l_iTimeout		= l_arrNextItem[2] || 0;
		var l_iElementId	= notNull(l_arrNextItem[3]) ? getAnimatioByName(l_arrNextItem[3]).id : this.id;
		if(notNull(l_iElementId))
		{
			window.setTimeout('g_arrAni[' + l_iElementId + '].' + l_strFunction + '(' + l_strParams + ');', l_iTimeout);
		}
		if(l_iElementId != this.id)
			this.next();
	}
}

function aniStop(p_bClearPlaylist)
{
	window.clearTimeout(this.iTimeout);
	this.bInProgress	= false;
	this.arrStart 		= [];
	this.arrCurrent		= [];
	this.arrChange		= [];
	this.arrSteppings	= [];
	this.arrProperties	= [];
	this.arrValues		= [];
	if(p_bClearPlaylist)
		this.arrPlaylist = [];
	return this;
}

function aniEnqueue(p_strFunction, p_arrParams, p_iTimout, p_strElement)
{
	this.arrPlaylist.push([p_strFunction, p_arrParams, p_iTimout, p_strElement]);
}

function aniGetStyle (p_strProperty)
{
	return getStyle(this.oNewElement, p_strProperty);
}

/*
Sets element styles. Can take a single property or an array.
*/
function aniSetStyle(p_varProperty, p_varValue)
{
	setStyle(this.oNewElement, p_varProperty, p_varValue);
	return this;
}

function aniSetOpacity(p_fOpacity)
{
	return setOpacity(this.oNewElement, p_fOpacity);
}

function aniGetHoverState()
{
	var l_arrScroll = getScrollOffset();
	var l_bXOver = (g_arrMousePos[0]+l_arrScroll[0] >= this.arrStartPos[0] & g_arrMousePos[0]+l_arrScroll[0] <= (this.arrStartPos[0]+this.oNewElement.offsetWidth));
	var l_bYOver = (g_arrMousePos[1]+l_arrScroll[1] >= this.arrStartPos[1] & g_arrMousePos[1]+l_arrScroll[1] <= (this.arrStartPos[1]+this.oNewElement.offsetHeight));
	if(l_bXOver & l_bYOver) return true;
	else return false;
}

function aniHasClass(p_strClass)
{
	return hasClass(this.oNewElement,p_strClass);
}

function aniAddClass(p_varClass)
{
	return addClass(this.oNewElement,p_varClass);
}

function aniRemoveClass(p_varClass)
{
	return removeClass(this.oNewElement,p_varClass);
}

function aniGetPosition()
{
	var l_iLeft = this.getStyle('left');
	var l_iTop = this.getStyle('top');
	return [l_iLeft, l_iTop];
}

function aniGetAbsolutePosition()
{
	return getPosition(this.oNewElement);
}

function aniSetPosition(p_iX, p_iY)
{
	if(getType(p_iX) == 'array')
	{
		p_iY = p_iX[1];
		p_iX = p_iX[0];
	}
	this.setStyle('left', p_iX + 'px');
	this.setStyle('top', p_iY + 'px');
}

function aniEnableDrag(p_oOptions)
{
	/*
		strDragClass
		varBoundary
		funcCallback
	*/
	var p_oOptions = p_oOptions || {};
	p_oOptions.merge({'strDragClass': 'dragActive'});

	this.bDragable = true;
	this.oDragOptions = p_oOptions;
	if(window.ie)
		hookEvent(this.oNewElement, 'dragstart', aniEVENT_ondragstart);
	hookEvent(this.oNewElement, 'mousedown', aniEVENT_onmousedownStartDrag);
}

function aniDisableDrag()
{
	this.bDragable = false;
	unhookEvent(this.oNewElement, 'mousedown', aniEVENT_onmousedownStartDrag);
	unhookEvent(document, 'mouseup', aniEVENT_onmouseupEndDrag);
}

function aniEVENT_ondragstart(e)
{
	return false;
}

function aniEVENT_onmousedownStartDrag(e)
{
	e.cancelBubble = true;
	if(e.preventDefault) 
		e.preventDefault(); //normale Browser
	else
		e.returnValue = false; //IE  
	hookEvent(document, 'mousemove', aniEVENT_onmousemoveDrag);
	hookEvent(document, 'mouseup', aniEVENT_onmouseupEndDrag);
	var l_oElement = getEventTarget(e);
	while(!l_oElement.oAni)
		l_oElement = l_oElement.parentNode;
	addClass(l_oElement, l_oElement.oAni.oDragOptions.strDragClass);
	g_iDrag = l_oElement.oAni.id;
	
	if(l_oElement.oAni.oDragOptions.hasOwnProperty('varBoundary'))
	{
		l_oElement.oAni.oDragOptions.varBoundary = getElement(l_oElement.oAni.oDragOptions.varBoundary);
		l_oElement.oAni.oDragOptions.arrBoundaryPos = getPosition(l_oElement.oAni.oDragOptions.varBoundary);
	}
	var l_arrPosition = getPosition(l_oElement);
	l_oElement.oAni.oDragOptions.arrMouseOffset = g_arrMousePos.substractEach(l_arrPosition);
	g_arrMouseOffset = l_oElement.oAni.getPosition().substractEach(g_arrMousePos);
	return false;
}

function aniEVENT_onmouseupEndDrag()
{
	if(g_iDrag != -1)
	{
		var l_oAni = g_arrAni[g_iDrag]
		l_oAni.removeClass(l_oAni.oDragOptions.strDragClass);
		g_iDrag = -1;
		unhookEvent(document, 'mousemove', aniEVENT_onmousemoveDrag);
		unhookEvent(document, 'mouseup', aniEVENT_onmouseupEndDrag);
		fireEvent(l_oAni.oNewElement, 'anidrop', l_oAni);
	}
}

function aniEVENT_onmousemoveDrag(e)
{
	if(notNull(g_arrAni[g_iDrag].oNewElement))
	{
		var l_oAni = g_arrAni[g_iDrag].stop(), l_arrTargetPosition, l_arrBoundMousePos, l_arrMouseBoundary, l_arrMouseBoundary2;
		var l_oOptions = l_oAni.oDragOptions;
		var l_oBoundary = l_oOptions.varBoundary;
		if(notNull(l_oBoundary))
		{
			l_arrBoundMousePos = g_arrMousePos.slice();
			l_arrMouseBoundary = l_oOptions.arrBoundaryPos.addEach(l_oOptions.arrMouseOffset);
			l_arrMouseBoundary2 = l_arrMouseBoundary.addEach(getDimensions(l_oBoundary)).substractEach(getDimensions(g_arrAni[g_iDrag]));
			
			if(l_arrBoundMousePos[0] < l_arrMouseBoundary[0])
				l_arrBoundMousePos[0] = l_arrMouseBoundary[0];
			else if(l_arrBoundMousePos[0] > l_arrMouseBoundary2[0])
				l_arrBoundMousePos[0] = l_arrMouseBoundary2[0];
				
			if(l_arrBoundMousePos[1] < l_arrMouseBoundary[1])
				l_arrBoundMousePos[1] = l_arrMouseBoundary[1];
			else if(l_arrBoundMousePos[1] > l_arrMouseBoundary2[1])
				l_arrBoundMousePos[1] = l_arrMouseBoundary2[1];

		}
		l_arrTargetPosition = l_arrBoundMousePos.addEach(g_arrMouseOffset);
		g_arrAni[g_iDrag].setPosition(l_arrTargetPosition);
		if(l_oOptions.hasOwnProperty('funcCallback'))
		{
			// Simulate an Event object
			l_oOptions.funcCallback
			(
				{
					'oAni': g_arrAni[g_iDrag],
					'Position': l_arrTargetPosition,
					'preventDefault': function(){},
					'target': getElement(g_arrAni[g_iDrag]),
					'type': 'AnimatioDragEvent'
				}
			);
		}
	}
	else
	{
		g_iDrag = -1;
		unhookEvent(document, 'mousemove', aniEVENT_onmousemoveDrag);
	}
}

/*

Slider function

Usage example:
<div class="slider" data-slider="{'name':'users','increment':5,'minValue':5,'maxValue':420,'maxLabel':'Unlimited','initialValue':150}"></div>

*/
function sliders()
{
	var i
	, _oField
	, _oSlider
	, _oSliderHandle
	, _oAniSlider
	, _oCfg
	, _iInitialPositionPx
	, _iInitialValue
	, l_arrSliders = getElementsByClass('slider', null, 'DIV');
	
	for (i=0;i<l_arrSliders.length;i++)
	{
		_oSlider = l_arrSliders[i];
		if(!notNull(_oSlider.oSliderCfg))
		{
			_oSlider.appendChild(_oSliderHandle = createNodeBefore(_oSlider, 'DIV', 'slider-handle'))
			_oAniSlider = new animatio(_oSliderHandle, 'slider-' + i, false);
			
			_oCfg = _oSlider.oSliderCfg = ({'increment':1, 'minValue':0, 'initialValue':0, 'range':_oSlider.offsetWidth - _oSliderHandle.offsetWidth});

			_oCfg.merge(eval('(' + _oSlider.getAttribute("data-slider") + ')'));
			_oCfg.initialValue = lowerLimit(_oCfg.initialValue, _oCfg.minValue);
			
			if(!_oCfg.hasOwnProperty('maxValue'))
				_oCfg.maxValue = _oCfg.range + _oCfg.minValue;
			
			if(_oCfg.hasOwnProperty('name'))
			{
				_oField = createNodeBefore(_oSlider, 'INPUT', null, null, {'type':'hidden', 'name':_oCfg.name});
				_oSlider.oSliderCfg.field = _oField;
			}
			
			_oAniSlider.enableDrag({'varBoundary':_oSlider, 'funcCallback':	handleSlider});

			// Set initial value
			_oAniSlider.setStyle('left', _oCfg.range);
			_iInitialPositionPx = Math.ceil((_oCfg.range/_oCfg.maxValue)*(_oCfg.initialValue-_oCfg.minValue));
			_oAniSlider.stop().animate(['left'], [_iInitialPositionPx], 150, easeInOutSine);		
			hookEvent(_oSliderHandle, 'exitFrame', slideToInitialPosition, _oAniSlider);
			hookEvent(_oSliderHandle, 'anidrop', aniEVENT_ondropSlider);
		}
	}
}

function slideToInitialPosition()
{
	this.setStyle(['top'],0);
	handleSlider({'target': this.oNewElement, 'Position': [this.getStyle('left')]});
	
	if(this.iTime == this.iFrames)
		unhookEvent(this.oNewElement, 'exitFrame', slideToInitialPosition, this);
}

function handleSlider(e)
{
	var l_oHandle	= e.target
	, l_oCfg		= l_oHandle.parentNode.oSliderCfg
	, l_iMaxValue	= (l_oCfg.maxValue || l_oCfg.range) - l_oCfg.minValue
	, l_iCurrentValue = upperLimit(Math.ceil(((l_iMaxValue/l_oCfg.range)*e.Position[0])/l_oCfg.increment) * l_oCfg.increment + l_oCfg.minValue, l_oCfg.maxValue);

	l_oCfg.value = l_iCurrentValue;
	if(l_oCfg.hasOwnProperty('field'))
		l_oCfg.field.value = l_iCurrentValue;
	
	l_oHandle.innerHTML = (l_iCurrentValue == l_oCfg.maxValue && l_oCfg.hasOwnProperty('maxLabel')) ? l_oCfg.maxLabel : l_iCurrentValue;
	if(l_oCfg.hasOwnProperty('suffix'))
		l_oHandle.innerHTML += l_oCfg.suffix;
		
	fireEvent(l_oHandle.parentNode, 'slidelive', l_oHandle.oAni);
}

function aniEVENT_ondropSlider(p_oAni)
{
	fireEvent(p_oAni.oNewElement.parentNode, 'slide', p_oAni);
}

function aniSetSrc(p_strSrc)
{
	this.oNewElement.src = p_strSrc;
	this.next();
}

function aniMove (p_iTargetX, p_iTargetY, p_iSpeed)
{
	if(!this.bInProgress)
	{
		var l_iDistanceX	= p_iTargetX - parseInt(this.getStyle('left'));
		var l_iDistanceY	= p_iTargetY - parseInt(this.getStyle('top'));
		var l_iSpeed		= p_iSpeed || 4;
		var l_iFrames		= Math.round(Math.sqrt(l_iDistanceX * l_iDistanceX + l_iDistanceY * l_iDistanceY) / l_iSpeed);
		this.animate(['left', 'top'], [p_iTargetX, p_iTargetY], l_iFrames);
	}
}

function aniFadeOut(p_iStepping, p_bRestore)
{
	if(!this.bInProgress)
	{
		p_iStepping = p_iStepping || 2;
		var l_iFrames = Math.round(this.getStyle('opacity') / (p_iStepping/100));
		this.animate(['opacity'], [0], l_iFrames);
		if(p_bRestore == 1)
		{
			this.enqueue('restore');
		}
	}
}

function aniFadeIn(p_iStepping)
{
	if(!this.bInProgress)
	{
		p_iStepping = p_iStepping || 2;
		l_fCurrentOpacity = this.getStyle('opacity');
		if(this.getStyle('display') == 'none')
			this.setStyle('display','');
		if(l_fCurrentOpacity == 1)
			this.setStyle('opacity', 0.1);		
		var l_iFrames = Math.round((1 - this.getStyle('opacity')) / (p_iStepping/100));

		this.animate(['opacity'], [1], l_iFrames);
	}
}

function aniFadeOutText(p_str)
{
	if(!this.bInProgress)
	{
		p_iStepping = p_iStepping || 2;
	}
}

function aniShrinkVertical()
{
	if(!this.bInProgress)
	{
		var l_iHeight = this.getStyle('height');
		var l_iMarginTop = this.getStyle('marginTop');
		this.animate(['height', 'marginTop'], [0, l_iHeight/2 + l_iMarginTop], 30);
		
	}
}

function aniShrinkHorizontal()
{
	if(!this.bInProgress)
	{
		var l_iWidth = this.getStyle('width');
		var l_iMarginLeft = this.getStyle('marginLeft');
		this.animate(['width', 'marginLeft'], [0, l_iWidth/2 + l_iMarginLeft], 30);
		
	}
}

function aniPulsate()
{
	if(!this.bInProgress)
	{
		this.enqueue('animate', [['[\'opacity\']'], ['[0]'], 20, easeInOutSine], 0);
		this.enqueue('animate', [['[\'opacity\']'], ['[0.8]'], 20, easeInOutSine], 0);
		this.enqueue('animate', [['[\'opacity\']'], ['[0]'], 20, easeInOutSine], 0);
		this.enqueue('animate', [['[\'opacity\']'], ['[0.8]'], 20, easeInOutSine], 0);
		this.enqueue('animate', [['[\'opacity\']'], ['[0]'], 20, easeInOutSine], 0);
		this.enqueue('animate', [['[\'opacity\']'], ['[1]'], 20, easeInOutSine], 0);
		this.next();
	}
}

function aniYellowFade()
{
	var l_arrCurrentBgColor = this.getStyle('backgroundColor');
	if(isNaN(l_arrCurrentBgColor[0]))
	{
		this.setStyle('backgroundColor', '#FFFFFF');
		l_arrCurrentBgColor = this.getStyle('backgroundColor');
	}
	this.setStyle('backgroundColor', '#FFFF00');
	this.animate(['backgroundColor'], [l_arrCurrentBgColor], 100, easeInOutSine);
}

function aniZoom(p_iTargetHeight, p_iTargetWidth, p_strImageSrc, p_bOnMouseOutClear)
{
	this.oNewElement.src = p_strImageSrc;
	var l_arrCurrPos = this.getPosition();
	var l_arrPageSize = getPageSize();
	var l_iDifferenceX = (p_iTargetWidth - this.getStyle('width')) / 2;
	var l_iDifferenceY = (p_iTargetHeight - this.getStyle('height')) / 2;
	var l_iTargetX	= l_arrCurrPos[0] - l_iDifferenceX;
	var l_iTargetY = l_arrCurrPos[1] - l_iDifferenceY;
	if((l_iTargetX + p_iTargetWidth) > l_arrPageSize[0])
		l_iTargetX = l_arrPageSize[0] - p_iTargetWidth - 20;
	/*if((l_iTargetY + p_iTargetHeight) > l_arrPageSize[1])
		l_iTargetY = l_arrPageSize[1] - p_iTargetHeight - 20;*/
	if(l_iTargetX < 0)
		l_iTargetX = 20;
	if(l_iTargetY < 0)
		l_iTargetY = 20;
	this.animate(['width', 'height', 'left', 'top'], [p_iTargetWidth, p_iTargetHeight, l_iTargetX, l_iTargetY], 30, easeInOutSine);
}


function aniFadeToRestore()
{
	if(!this.bInProgress)
	{
		var l_iFrames = 30;
		var l_iLeft = this.arrStartPos[0];
		var l_iTop = this.arrStartPos[1];
		var l_iWidth = this.oElement.offsetWidth;
		var l_iHeight = this.oElement.offsetHeight;
		this.animate(['opacity', 'left', 'top', 'width', 'height'], [0.5, l_iLeft, l_iTop, l_iWidth, l_iHeight], l_iFrames, easeInOutSine);
		this.enqueue('restore');
	}
}

function aniRestoreElement()
{
	if (this.iTimeout != null)
	{
		window.clearTimeout(this.iTimeout);
		this.iTimeout = null;
	}
	if(notNull(this.oNewElement))
	{
		this.oNewElement.parentNode.removeChild(this.oNewElement);
		this.oElement.oAni = null;
		g_arrAni[this.id].strFriendlyName = null;
		g_arrAni[this.id] = -1;
	}
	this.oElement.style.visibility = 'visible';
}

var HELPER	= new helper();

function helper()
{
	hookEvent(window, 'load', getZoomImages);
	hookEvent(window, 'domready', function()
	{
		initAccordion();
		scrollingBoxes();
		replaceFonts();
		inputFieldsWatermarks();
		sliders();
	});
	hookEvent(document, 'mousemove', getMousePosition);
	removeClass(document.getElementsByTagName('HTML')[0], 'no-js');
}


helper.prototype.getType		= getType;
helper.prototype.notNull		= notNull;
helper.prototype.getElement		= getElement;
helper.prototype.getPosition	= getPosition;
helper.prototype.getPageSize	= getPageSize;
helper.prototype.getScrollOffset= getScrollOffset;
helper.prototype.guid			= guid;
helper.prototype.random			= randomNumber;
helper.prototype.hookEvent		= hookEvent;
helper.prototype.unhookEvent	= unhookEvent;
helper.prototype.getEvent		= getEvent;
helper.prototype.getEventTarget	= getEventTarget;
helper.prototype.hexToRGB		= hexToRGB;
helper.prototype.getFormData	= getFormData;
helper.prototype.oc				= oc;
helper.prototype.getElementsByClass	= getElementsByClass;

function getType(p_varObject)
{
	if (!notNull(p_varObject))
		return false;
	if (p_varObject.htmlElement)
		return 'element';
		
	var l_strType = typeof p_varObject;
	if (l_strType == 'object' && p_varObject.nodeName)
	{
		switch(p_varObject.nodeType)
		{
			case 1: return 'element';
			case 3: return (/\S/).test(p_varObject.nodeValue) ? 'textnode' : 'whitespace';
			
		}
	}
	if (l_strType == 'object' || l_strType == 'function')
	{
		switch(p_varObject.constructor)
		{
			case Array: return 'array';
			case RegExp: return 'regexp';
			case Event: return 'event';
			case MouseEvent: return 'event';
			case KeyboardEvent: return 'event';
			//default:alert(p_varObject.constructor);
		}
		if (typeof p_varObject.length == 'number')
		{
			if (p_varObject.item) return 'collection';
			if (p_varObject.callee) return 'arguments';
		}
		if(p_varObject.srcElement)
			return 'event';
	}
	return l_strType;
}

function notNull(p_varObject)
{
	return (p_varObject != undefined);
}

function getElement(p_varElement)
{
	switch (getType(p_varElement))
	{
		case 'element': return p_varElement;
		case 'string' : return document.getElementById(p_varElement);
		case 'event'  : return getEventTarget(p_varElement);
		case 'function': if(p_varElement.tagName == 'EMBED')return p_varElement;
		case 'object' : if(p_varElement.hasOwnProperty('oNewElement')) return p_varElement.oNewElement;
	}
}

function getPosition(p_oElement)
{
	var l_iLeft = l_iTop = 0
		,l_oElement = p_oElement
		,l_bAddScrollOffset = true;
	if(l_oElement.style.position == 'fixed')
		return [getStyle(l_oElement, 'left'), getStyle(l_oElement, 'top')]
	if (l_oElement.offsetParent) 
	{
		l_iLeft	= l_oElement.offsetLeft;
		l_iTop	= l_oElement.offsetTop;
		while(l_oElement = l_oElement.offsetParent)
		{
			l_iLeft	+= parseInt(l_oElement.offsetLeft) || 0;
			l_iLeft	+= parseInt(getStyle(l_oElement, 'borderLeftWidth')) || 0;
			l_iTop	+= parseInt(l_oElement.offsetTop) || 0;
			l_iTop	+= parseInt(getStyle(l_oElement, 'borderTopWidth')) || 0;
			if(l_oElement.style.position == 'fixed')
				l_bAddScrollOffset = true;
			if (l_oElement.offsetParent == document.body && l_oElement.style.position == 'absolute')
				break;
		}
		if(l_bAddScrollOffset)
		{
			l_oElement = p_oElement;
			do
			{
				//if (l_oElement.offsetParent != document.body  && !Browser.Opera)
				if ((l_oElement.tagName && l_oElement.tagName.toUpperCase() != 'BODY') && !Browser.Opera)
				{
					l_iLeft -= l_oElement.scrollLeft  || 0;
					//l_iTop += l_oElement.scrollTop || 0;
				}
			} while(l_oElement = l_oElement.parentNode);
		}
	}
	/*
	if(hasClass(p_oElement, 'small-campaign'))
	{
		var l_oDiv	= document.createElement("DIV");
		l_oDiv.style.width = l_iLeft + 'px';
		l_oDiv.style.height = l_iTop + 'px';
		l_oDiv.style.left = '0px';
		l_oDiv.style.top = '0px';
		l_oDiv.style.position = 'absolute';
		l_oDiv.style.border = '1px solid green';
		window.document.body.appendChild(l_oDiv);
	}*/

	return [l_iLeft,l_iTop];
}


function isHover(p_varElement, p_arrCoordinates)
{
	if(!notNull(p_varElement))
		return false;
		
	var l_arrCoordinates = p_arrCoordinates || g_arrMousePos.addEach(getScrollOffset());
	var p_oElement = getElement(p_varElement);
	var l_arrPos = getPosition(p_oElement);
	/*
	//Overlay Element
	var l_oDiv	= document.createElement("DIV");
	l_oDiv.style.width = p_oElement.offsetWidth + 'px';
	l_oDiv.style.height = p_oElement.offsetHeight + 'px';
	l_oDiv.style.left = l_arrPos[0] + 'px';
	l_oDiv.style.top = l_arrPos[1] + 'px';
	l_oDiv.style.position = 'absolute';
	l_oDiv.style.backgroundColor = 'green';
	window.document.body.appendChild(l_oDiv);
	
	//Draw Coordinates
	var l_oDiv	= document.createElement("DIV");
	l_oDiv.style.width = '1px';
	l_oDiv.style.height = '1px';
	l_oDiv.style.left = l_arrCoordinates[0] + 'px';
	l_oDiv.style.top = l_arrCoordinates[1] + 'px';
	l_oDiv.style.position = 'absolute';
	l_oDiv.style.backgroundColor = 'red';
	window.document.body.appendChild(l_oDiv);
	*/
	
	return ((l_arrCoordinates[1] < l_arrPos[1] || l_arrCoordinates[1]> parseInt(l_arrPos[1] + p_oElement.offsetHeight)
		  || l_arrCoordinates[0] < l_arrPos[0] || l_arrCoordinates[0]> parseInt(l_arrPos[0] + p_oElement.offsetWidth)))?false:true;
}

function getPageSize()
{
	var l_iWidth, l_iHeight;
	// mozilla/netscape/opera/IE7
	if (typeof window.innerWidth != 'undefined')
	{
	  l_iWidth = window.innerWidth,
	  l_iHeight = window.innerHeight
	}
	// IE6 in standards compliant mode
	else if (typeof document.documentElement != 'undefined'
	 && typeof document.documentElement.clientWidth !=
	 'undefined' && document.documentElement.clientWidth != 0)
	{
	   l_iWidth = document.documentElement.clientWidth,
	   l_iHeight = document.documentElement.clientHeight
	}
	// older versions of IE
	else
	{
	   l_iWidth = document.getElementsByTagName('body')[0].clientWidth,
	   l_iHeight = document.getElementsByTagName('body')[0].clientHeight
	}
	return [l_iWidth, l_iHeight];
}

function getScrollOffset()
{
	return [window.pageXOffset ?
			window.pageXOffset :
			document.documentElement.scrollLeft ?
				document.documentElement.scrollLeft :
				document.body.scrollLeft,
			window.pageYOffset ?
			window.pageYOffset :
				document.documentElement.scrollTop ?
				document.documentElement.scrollTop :
				document.body.scrollTop];
}


function changePositionMethod(p_oElement, p_strNewPositionMethod, p_oNewParent)
{
	p_oElement = getElement(p_oElement);
	var l_strCurrentPositionMethod = getStyle(p_oElement, 'position');
	
	if(notNull(p_strNewPositionMethod))
		p_strNewPositionMethod = l_strCurrentPositionMethod;
	if(notNull(p_oNewParent))
	{
		p_oNewParent = getElement(p_oNewParent);
		p_oElement.oCalculatedPosition = {};
	}
	if(p_strNewPositionMethod != l_strCurrentPositionMethod || notNull(p_oNewParent))
	{
		if((!notNull(p_oNewParent)) && p_oElement.oCalculatedPosition && p_oElement.oCalculatedPosition[p_strNewPositionMethod])
		{
			l_arrCompensatedPosition = p_oElement.oCalculatedPosition[p_strNewPositionMethod];
		}
		else
		{
			var l_arrCurrentAbsolutePosition = getPosition(p_oElement);
			//var l_arrScrollOffset = [document.body.scrollLeft, document.body.scrollTop];
			var l_arrScrollOffset = getScrollOffset();
			setStyle(p_oElement, 'position', p_strNewPositionMethod);
			p_oNewParent.appendChild(p_oElement);
			
			var l_arrNewPosition = getPosition(p_oElement);
			var l_arrCurrentCoordinates = [parseInt(getStyle(p_oElement, 'left')), parseInt(getStyle(p_oElement, 'top'))];
			var l_arrCompensatedPosition = l_arrCurrentCoordinates.addEach(l_arrCurrentAbsolutePosition.substractEach(l_arrNewPosition))
			if(p_strNewPositionMethod == 'fixed')
			{
				l_arrCompensatedPosition = l_arrCompensatedPosition.substractEach(l_arrScrollOffset);
				l_arrCompensatedPosition = l_arrCompensatedPosition.substractEach([getStyle(p_oElement, 'marginLeft'), getStyle(p_oElement, 'marginTop')]);
			}
			else if(l_strCurrentPositionMethod == 'fixed')
			{
				l_arrCompensatedPosition = l_arrCompensatedPosition.addEach(l_arrScrollOffset);
				l_arrCompensatedPosition = l_arrCompensatedPosition.addEach([getStyle(p_oElement, 'marginLeft'), getStyle(p_oElement, 'marginTop')]);
			}
			if(l_strCurrentPositionMethod != 'fixed')
			{
				p_oElement.oCalculatedPosition = p_oElement.oCalculatedPosition || {};
				p_oElement.oCalculatedPosition[l_strCurrentPositionMethod] = l_arrCurrentCoordinates;
			}
		}
		setStyle(p_oElement, 'position', p_strNewPositionMethod);
		setStyle(p_oElement, ['left', 'top'], l_arrCompensatedPosition);
	}
}


function guid()
{
	var strGuid, i, j;
	strGuid = '';
	for(j = 0; j < 32; j++)
	{
		if(j == 8 || j == 12 || j == 16 || j == 20)
			strGuid = strGuid + '-';
		i = Math.round(Math.random() * 16).toString(16).toUpperCase();
		strGuid = strGuid + i;
	}
	return strGuid;
}

function randomNumber(p_iMinValue, p_iMaxValue)
{
	var l_iNumber = Math.random() * (p_iMaxValue - p_iMinValue);
	return Math.round(p_iMinValue + l_iNumber);
}

function getEventIndex(p_oElement,p_strEvent,p_funcCallback,p_oBinding)
{
	if(p_oElement && p_strEvent)
	{
		var l_oListener = Events[p_oElement][p_strEvent];
		if(l_oListener)
		{
			for(var i = l_oListener.length-1;i >= 0;i--)
			{
				if(l_oListener[i].callback == p_funcCallback && l_oListener[i].binding == p_oBinding)
				{
					return i;
				}
			}
		}
		else
		{
			return -1;
		}
	}
	return -1;
}

function isNativeEvent(p_strName)
{
	if(Browser.msie && ['mouseenter', 'mouseleave'].inArray(p_strName))
		return true;
	
	var NativeEvents =
	{
		click: 2, dblclick: 2, mouseup: 2, mousedown: 2, contextmenu: 2, //mouse buttons
		mousewheel: 2, DOMMouseScroll: 2, //mouse wheel
		mouseover: 2, mouseout: 2, mousemove: 2, selectstart: 2, selectend: 2, //mouse movement
		keydown: 2, keypress: 2, keyup: 2, //keyboard
		orientationchange: 2, // mobile
		touchstart: 2, touchmove: 2, touchend: 2, touchcancel: 2, // touch
		gesturestart: 2, gesturechange: 2, gestureend: 2, // gesture
		focus: 2, blur: 2, change: 2, reset: 2, select: 2, submit: 2, //form elements
		load: 2, unload: 1, beforeunload: 2, resize: 1, move: 1, DOMContentLoaded: 1, readystatechange: 1, //window
		error: 1, abort: 1, scroll: 1 //misc
	};
	return NativeEvents.hasOwnProperty(p_strName);
}

function isMouseOverEvent(e)
{
	return ['mouseover', 'mouseenter'].inArray(getEvent(e).type);
}
function isMouseOutEvent(e)
{
	return ['mouseout', 'mouseleave'].inArray(getEvent(e).type);
}

function EVENT_mouseLeaveOrEnter(p_varElement, e, p_funcCallback, p_oBinding)
{
	var e = getEvent(e)
	, l_oTarget = getEventTarget(e)
	, l_oRelativeTarget = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	//if ( !l_oRelativeTarget || (l_oRelativeTarget !== l_oTarget && !isContainedIn(l_oRelativeTarget, l_oTarget))) 
	if ( !l_oRelativeTarget || (l_oRelativeTarget !== l_oTarget && !isContainedIn(l_oRelativeTarget, l_oTarget) && !isContainedIn(l_oRelativeTarget, p_varElement))) 
	{
		p_funcCallback.bind(p_oBinding)(e);
	}
	
	/*
	//relatedtarget darf kein Kind von p_varElement sein!!
	while (l_oRelativeTarget && l_oRelativeTarget != p_varElement && l_oRelativeTarget.nodeName != 'BODY' && l_oRelativeTarget.parentNode)
	{
		l_oRelativeTarget = l_oRelativeTarget.parentNode;
	}
	
	if (l_oRelativeTarget==p_varElement)
		return false;
	
	// Mouse event actually took place
	p_funcCallback.bind(p_oBinding)(e);*/
}


function isContainedIn(p_varElement, p_varAssertedParent)
{
	p_varElement = getElement(p_varElement);
	p_varAssertedParent	= getElement(p_varAssertedParent);
	
	if(p_varAssertedParent && p_varAssertedParent.contains)
		return p_varAssertedParent.contains(p_varElement);
	else if (document.documentElement.compareDocumentPosition)
		return !!(p_varAssertedParent.compareDocumentPosition(p_varElement) & 16);
	
	while (p_varElement && p_varElement != p_varAssertedParent && p_varElement.nodeName != 'BODY' && p_varElement.parentNode)
	{
		p_varElement = p_varElement.parentNode;
	}
	if (p_varElement == p_varAssertedParent)
		return true;
	return false;
}


function hookEvent(p_varElement, p_varEvents, p_funcCallback, p_oBinding)
{
	if(p_varElement == null)return;
	if(typeof(p_varElement) == 'string')
		p_varElement = getElement(p_varElement);
	if(getType(p_varEvents) == 'string')
		p_varEvents = [p_varEvents]
	for(var i=0; i<p_varEvents.length; i++)
	{
		if(isNativeEvent(p_varEvents[i]))
		{
			if(p_varEvents[i] == 'mousewheel' | p_varEvents[i] == 'DOMMouseScroll')
			{
				p_varEvents[i] = Browser.mozilla ? 'DOMMouseScroll' : 'mousewheel';
			}
			if(p_oBinding)
				p_funcCallback = p_funcCallback.bind(p_oBinding);
			if(p_varElement.addEventListener)
				p_varElement.addEventListener(p_varEvents[i], p_funcCallback, false);
			else if(p_varElement.attachEvent)
			{
				p_varElement.attachEvent('on' + p_varEvents[i], p_funcCallback);
			}
		}
		else if(['mouseenter','mouseleave'].inArray(p_varEvents[i]))
		{
			hookEvent(p_varElement, (p_varEvents[i] == 'mouseenter') ? 'mouseover' : 'mouseout', function(e){EVENT_mouseLeaveOrEnter(p_varElement, e, p_funcCallback, p_oBinding)});
		}
		// Hooking a custom Event
		// Credits to http://www.josh-davis.org/2007/04/10/custom-event-listeners/ 
		else
		{
			if(domReady && p_varEvents[i] == 'domready')
			{
				p_funcCallback();
			}
			else if(Events[p_varElement])
			{
				if(Events[p_varElement][p_varEvents[i]])
				{
					if(getEventIndex(p_varElement,p_varEvents[i],p_funcCallback,p_oBinding) == -1)
					{
						var l_arrListener = Events[p_varElement][p_varEvents[i]];
						l_arrListener[l_arrListener.length] = {callback:p_funcCallback,binding:p_oBinding};
					}
				}
				else
				{
					Events[p_varElement][p_varEvents[i]] = [];
					Events[p_varElement][p_varEvents[i]][0] = {callback:p_funcCallback,binding:p_oBinding};
				}
			}
			else
			{
				Events[p_varElement] = [];
				Events[p_varElement][p_varEvents[i]] = [];
				Events[p_varElement][p_varEvents[i]][0] = {callback:p_funcCallback,binding:p_oBinding};
			}
		}
		
	}
}

function unhookEvent(p_varElement, p_strEvent, p_funcCallback, p_oBinding)
{
	if(isNativeEvent(p_strEvent))
	{
		if(p_strEvent == 'mousewheel' | p_strEvent == 'DOMMouseScroll')
		{
			p_strEvent = Browser.mozilla ? 'DOMMouseScroll' : 'mousewheel';
		}
		if(p_varElement == null) return;
		if(typeof(p_varElement) == 'string')
			p_oElement = getElement(p_varElement);
		if(p_varElement.removeEventListener)
			p_varElement.removeEventListener(p_strEvent, p_funcCallback, false);
		else if(p_varElement.detachEvent)
			p_varElement.detachEvent('on' + p_strEvent, p_funcCallback);
	}
	else
	{
		if(Events[p_varElement])
		{
			if(Events[p_varElement][p_strEvent])
			{
				// getEventIndex
				var l_iIndex = getEventIndex(p_varElement,p_strEvent,p_funcCallback,p_oBinding);
				if(l_iIndex >= 0)
				{
					Events[p_varElement][p_strEvent].splice(l_iIndex,1);
				}
			}
		}
	}
}


function fireEvent (p_varElement, p_strEvent, e, p_arrArguments)
{
	var e = this.getEvent(e);
	if(p_varElement)
	{
		if(isNativeEvent(p_strEvent))
		{
			if(p_strEvent == 'mousewheel' | p_strEvent == 'DOMMouseScroll')
			{
				p_strEvent = Browser.mozilla ? 'DOMMouseScroll' : 'mousewheel';
			}
			p_varElement = getElement(p_varElement);
			if (document.createEvent)
			{ 
				var evt = document.createEvent("Events"); 
				evt.initEvent(p_strEvent, true, true); 
				p_varElement.dispatchEvent(evt); 
			} 
			else if (document.createEventObject)
			{
				var evt = document.createEventObject(); 
				p_varElement.fireEvent('on' + p_strEvent, evt); 
			}
		}
		else if(Events)
		{
			var l_arrEvents = Events[p_varElement];
			if(l_arrEvents)
			{
				var l_arrListener = l_arrEvents[p_strEvent];
				if(l_arrListener)
				{
					for(var act in l_arrListener)
					{
						if(l_arrListener[act].callback)
						{
							var l_oCallback = l_arrListener[act].callback;
							if(l_oCallback)
							{
								if(typeof p_varElement.oAni != "undefined" && typeof p_varElement.oAni.strFriendlyName != "undefined")
								// p_varElement.oAni.strFriendlyName
								if(l_arrListener[act].binding && p_strEvent != 'slide')
								{
									l_oCallback = l_oCallback.bind(l_arrListener[act].binding);
								}
								l_oCallback(e, p_arrArguments);
							}
						}
					}
				}
			}
		}
	}
}


function getEvent(e)
{
	if(!e)
		e = ((this.ownerDocument || this.document || this).parentWindow || window).event;
	if(e && !e.preventDefault)
		e.preventDefault = function(){this.returnValue = false};
	if(e && !e.stopPropagation)
		e.stopPropagation = function(){this.cancelBubble = true};
	return e;
}

function getEventTarget(e)
{
	var e = this.getEvent(e);
	if(e.target)
		return e.target;
	return e.srcElement;
}

function triggerEvent (p_varElement, p_strEvent)
{ 
	fireEvent(p_varElement, p_strEvent);
}

(function()
{
	var EVENT_DOMREADY = function(){if(!domReady){fireEvent(window, 'domready'); domReady = true}};
	if (document.addEventListener)
	{
		document.addEventListener("DOMContentLoaded", EVENT_DOMREADY, false);
	}
	else if (Browser.safari)
	{ // sniff
		var _timer = setInterval(
			function()
			{
				if (/loaded|complete/.test(document.readyState))
				{
					clearInterval(_timer);
					EVENT_DOMREADY()
				}
			}
			, 10
		);
	}
	else if(Browser.msie)
	{
		(function()
		{
			try 
			{
				// If IE is used, use the trick by Diego Perini
				// http://javascript.nwbox.com/IEContentLoaded/
				document.documentElement.doScroll("left");
			} catch(error) {
				setTimeout(arguments.callee, 0);
				return;
			}
			// and execute any waiting functions
		    EVENT_DOMREADY();
		})();
	}
})();


function getMousePosition(e)
{
	e = getEvent(e);
	g_arrMousePos = [e.clientX, e.clientY];
}

function getMouseWheelDelta(e)
{
	var l_iDelta = 0;
	e = getEvent(e);
	//if (e.wheelDelta) 
	if(e.type == 'mousewheel')
	{ /* IE/Opera. */
		l_iDelta = e.wheelDelta/120;
		/** In Opera 9, delta differs in sign as compared to IE.
		 */
		if (window.opera)
			l_iDelta = -l_iDelta;
	} 
	//else if (e.detail) 
	else if(e.type == 'DOMMouseScroll')
	{ /** Mozilla case. */
		/** In Mozilla, sign of delta is different than in IE.
		 * Also, delta is multiple of 3.
		 */
		l_iDelta = -e.detail/3;
	}
	return l_iDelta;
}

function hexToRGB(p_strHexColor)
{
	if(getType(p_strHexColor) == "array")
		return p_strHexColor;
	if(p_strHexColor.indexOf("rgb") != -1)
	{
		p_strHexColor = p_strHexColor.match(/(\d+, ?\d+, ?\d+){1}/)[0];
		var l_arrRGB = p_strHexColor.split(",")
		l_arrRGB[0] = parseInt(l_arrRGB[0]);
		l_arrRGB[1] = parseInt(l_arrRGB[1]);
		l_arrRGB[2] = parseInt(l_arrRGB[2]);
		return l_arrRGB;
	}
	p_strHexColor = p_strHexColor.replace("#", "");
	if(p_strHexColor.length == 3)
		p_strHexColor = p_strHexColor + p_strHexColor;
	var l_arrRGB = [parseInt(p_strHexColor.substring(0,2),16), 
					parseInt(p_strHexColor.substring(2,4),16), 
					parseInt(p_strHexColor.substring(4,6),16)];
	return l_arrRGB;
}

function RGBToHex(r,g,b)
{
	var rgb = [r.toString(16),g.toString(16),b.toString(16)]
	for(var i=0;i<3;i++)
	{
		if (rgb[i].length==1) rgb[i]=rgb[i]+rgb[i];
	}
	return '#'+rgb[0]+rgb[1]+rgb[2];
}

function RGBArrayToHex(p_arrRGB)
{
	return RGBToHex(p_arrRGB[0],p_arrRGB[1],p_arrRGB[2]);
}

function getValue(p_varElement)
{
	var l_oElement = getElement(p_varElement);
	var l_strType = (l_oElement.type || '');
	if(l_oElement.nodeName.match(/^textarea$/i) || l_strType.match(/^(text|hidden|textarea|password)$/i) || (l_strType.match(/^(radio|checkbox)$/i) && l_oElement.checked))
	{
		return l_oElement.value;
	}
	else if(l_oElement.nodeName.match(/^select$/i))
	{
		for(var i=0; i<l_oElement.options.length; i++)
		{
			return l_oElement.options[l_oElement.selectedIndex].value;
		}
	}
}

function getFormData(p_oForm, p_bAsArray)
{
	var l_varReturn;
	var add = function(p_strName, p_varValue)
	{
		if(p_bAsArray)
		{
			if(l_varReturn == null) l_varReturn = new Array();
			l_varReturn[p_strName] = escape(p_varValue);
		}
		else
		{
			l_varReturn = (l_varReturn == null ? '' : l_varReturn+'&') + p_strName +'='+ escape(p_varValue);
		}
	};
	for(var i=0; i<p_oForm.elements.length; i++)
	{
		var _oElem = p_oForm.elements[i];
		var type = (_oElem.type || '');
		if(type.match(/^(text|hidden|textarea)$/i) || (type.match(/^(radio|checkbox)$/i) && _oElem.checked))
		{
			add(_oElem.name, _oElem.value);
		}
		else if(_oElem.nodeName.match(/^select$/i))
		{
			for(var j=0; j<_oElem.options.length; j++)
			{
				if(_oElem.options[j].selected)
				{
					add(_oElem.name, _oElem.options[j].value);
				}
			}
		}
		else if(_oElem.nodeName.match(/^textarea$/i))
		{
			add(_oElem.name, _oElem.value);
		}
	}
	return l_varReturn != null ? l_varReturn : (p_bAsArray ? new Array() : '');
}

function oc(a)
{
	var o = {};
	for(var i=0; i<a.length; i++)
	{
		o[a[i]] = '';
	}
	return o;
}


function getDimensions(p_varElement)
{
	p_varElement = getElement(p_varElement);
	return [p_varElement.offsetWidth, p_varElement.offsetHeight];
}

function getStyle (p_oElement, p_strProperty)
{
	if(!notNull(p_oElement)) return;
	if(p_strProperty == 'float')
		p_strProperty = (window.ie) ? 'styleFloat' : 'cssFloat';
	var l_strValue = "";
	
	if(p_oElement.style[p_strProperty])//try and get inline style
		l_strValue = String(p_oElement.style[p_strProperty]);
	else if (p_oElement.currentStyle) //IE
		l_strValue = String(p_oElement.currentStyle[p_strProperty]);
	else if (document.defaultView && document.defaultView.getComputedStyle) //Firefox
		l_strValue = String(document.defaultView.getComputedStyle(p_oElement, "")[p_strProperty]);

	//var l_strValue = String(p_oElement.style[p_strProperty]);
	if(l_strValue.indexOf("px") != -1 | p_strProperty == "zIndex" | p_strProperty == "fontWeight")
		return parseInt(l_strValue);
	if(p_strProperty == 'backgroundColor' || p_strProperty == 'borderColor')
		p_strProperty = 'color';
	switch (p_strProperty)
	{
		case 'opacity': 
			if(isNaN(parseFloat(l_strValue)))
				return 1;
			return parseFloat(l_strValue) || 1;
		case 'width':
			if(!notNull(l_strValue) || l_strValue == 'auto')
				l_strValue = p_oElement.offsetWidth;
			return l_strValue;
		case 'height': 
			if(!notNull(l_strValue) || l_strValue == 'auto')
				l_strValue = p_oElement.offsetHeight;
			return l_strValue;
		case 'color':
			return hexToRGB(l_strValue);
		default:
			return l_strValue || 0;
	}
}

/*
Sets element styles. Can take a single property or an array.
*/
function setStyle(p_oElement, p_varProperty, p_varValue)
{
	if(getType(p_varProperty) == 'string' || p_varProperty == 'backgroundColor' || p_varProperty == 'color')
	{
		p_varProperty = [p_varProperty];
		p_varValue = [p_varValue];
	}
	for (var i=0; i<p_varProperty.length; i++)
	{
		switch(p_varProperty[i])
		{
			case 'opacity':
				return setOpacity(p_oElement, p_varValue[i]);
				break;
			case 'float':
				p_varProperty[i] = (window.ie) ? 'styleFloat' : 'cssFloat';
				break;
			case 'width':
				if(p_varValue[i] < 0)
					p_varValue[i] = 0;
				break;
			case 'height':
				if(p_varValue[i] < 0)
					p_varValue[i] = 0;
				break;
		}
		if (getType(p_varValue[i]) == 'array')
			p_varValue[i] = 'rgb(' + p_varValue[i][0] + ',' + p_varValue[i][1] + ',' + p_varValue[i][2] + ')';
		
		else if(getType(p_varValue[i]) == 'number' & p_varProperty[i] != "zIndex" & p_varProperty[i] != "fontWeight")
			p_varValue[i] += 'px';
		p_oElement.style[p_varProperty[i]] = p_varValue[i];
	}
}

function setOpacity(p_oElement, p_fOpacity)
{
	if (window.ie)
	{
		p_oElement.runtimeStyle.filter = 'Alpha(opacity=' + p_fOpacity * 100 + ')';
		if(notNull(p_oElement.src))
		{
			var pattern = /.png/i;
			if(pattern.test(p_oElement.src))
			{
				if([0,1].inArray(p_fOpacity) && this.getStyle('background') == 'white')
					setStyle(p_oElement, 'background', 'transparent');
				else
					setStyle(p_oElement, 'background', 'white');
			}
		}
	}
	p_oElement.style.opacity = p_fOpacity;
	if (p_fOpacity == 0)
		p_oElement.style.visibility = 'hidden';
	else if (p_oElement.style.visibility != 'visible') 
		p_oElement.style.visibility = 'visible';
}

function getElementsByClass(searchClass,node,tag) 
{
	if (node == null)
		node = document;
	if (tag == null)
		tag = '*';
	var i,j, classElements = new Array()
		, els = node.getElementsByTagName(tag)
		, elsLen = els.length
		, pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++)
	{
		if (pattern.test(els[i].className))
		{
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function hasClass(p_varObject, p_strSearchClass)
{
	var l_oElement = getElement(p_varObject);
	if(l_oElement)
		return (new RegExp('\\b'+p_strSearchClass+'\\b').test(l_oElement.className));
	else
		return false;
}

function addClass(p_varObject, p_varClasses)
{
	if(getType(p_varClasses) != 'array')
		p_varClasses = [p_varClasses];
	
	var l_oField = getElement(p_varObject);
	for(var i=0; i<p_varClasses.length; i++)
	{
		if(!hasClass(l_oField, p_varClasses[i]))
			l_oField.className = trim(l_oField.className + " " + p_varClasses[i]);
	}
}

function removeClass(p_varObject, p_varClasses)
{
	if(getType(p_varClasses) != 'array')
		p_varClasses = [p_varClasses];
		
	var l_oField = getElement(p_varObject);
	for(var i=0; i<p_varClasses.length; i++)
	{
		if(hasClass(l_oField, p_varClasses[i]))
			l_oField.className = trim(l_oField.className.replace(p_varClasses[i], ""));
	}
}

function hide(p_varElement)
{
	p_varElement = getElement(p_varElement);
	p_varElement.style.display = 'none';
	p_varElement.style.visibility = 'hidden';
}

function show(p_varElement)
{
	p_varElement = getElement(p_varElement);
	p_varElement.style.display = '';
	p_varElement.style.visibility = '';
}

/** 
* CrossBrowser trim() 
*/
if(typeof String.prototype.trim !== 'function') 
{
	String.prototype.trim = function() 
	{
		return this.replace(/^\s+|\s+$/g, ''); 
	}
}

function trim(s) 
{
	return getType(s) == 'string' ? s.replace(/^\s+|\s+$/g, '') : '';
}

/**
	@function insertAfter
	@description
	emulates the missing DOM insertAfter function
	@param parent
	the elements parentnode
	@param node
	the node to be inserted after 'referenceNode'
	@param referenceNode
	the referendceNode after which 'node' is to be inserted
*/
function insertAfter(parent, node, referenceNode)
{
	parent.insertBefore(node, referenceNode.nextSibling);
}

function createNodeBefore(p_oItem, p_strTagName, p_strClassName, p_strInnerHTML, p_oAttributes)
{
//	console.log("createNodeBefore" + p_strTagName);
//	console.log((!!p_oItem), (!!p_strTagName), (!!p_strClassName), (!!p_strInnerHTML), (!!p_oAttributes))
	// true true false true false
	p_oItem = getElement(p_oItem);
//	console.log(p_oItem);
	var l_oNewItem = document.createElement(p_strTagName);
	//console.info(l_oNewItem);		// in IE leer
	if(p_oAttributes)
	{
		for(var _oAtr in p_oAttributes)
		{
			if(getType(p_oAttributes[_oAtr]) == 'string')
				l_oNewItem.setAttribute(_oAtr, p_oAttributes[_oAtr]);
		}
	}
	p_oItem.parentNode.insertBefore(l_oNewItem, p_oItem);
	if(p_strClassName)
		l_oNewItem.className = p_strClassName;
	if(getType(p_strInnerHTML) == 'string')
	{
		l_oNewItem.innerHTML = p_strInnerHTML;
	}
	return l_oNewItem;
}

function wrap(p_varItem, p_strTagName, p_strClassName, p_oAttributes)
{
	if(getType(p_varItem) != 'array')
		p_varItem = [p_varItem];
	
	if(!notNull(p_strTagName))
		p_strTagName = 'DIV';
	var i, l_oNewItem = createNodeBefore(p_varItem[0], p_strTagName, p_strClassName, null, p_oAttributes);
	for(i=0; i<p_varItem.length; i++)
	{
		l_oNewItem.appendChild(p_varItem[i]);
	}
	return l_oNewItem;
}

/**
	@function DOMParent
	@description
	returns the node located at the specified number of levels higher than the given element. 
	@param p_oObject
	the item you want the parent of
	@param p_iLevels
	the number of levels you want to go up
	@param p_strTagName
	Filter to only return an element with a particular tag name. 
*/
function DOMParent(p_oObject, p_iLevels, p_strTagName)
{
	var i, l_oTempObject = l_oObject = p_oObject;
	if(typeof p_iLevels == "undefined" || p_iLevels == null)
	{
		p_iLevels = notNull(p_strTagName) ? 20 : 1;
	}
	if(getType(l_oObject) == 'element' || (getType(l_oObject) == 'function' && l_oObject.tagName == 'EMBED'))
	{
		for(i=1; i <= p_iLevels; i++)
		{
			if(notNull(l_oTempObject.parentNode))
			{
				l_oTempObject = l_oTempObject.parentNode;
				if(notNull(p_strTagName) && p_strTagName != l_oTempObject.tagName)
					continue;
				l_oObject = l_oTempObject;
				if(notNull(p_strTagName))
					break;
			}
		}
		if(l_oObject != p_oObject)
			return l_oObject;
		return false;
	}
}

/**
	@function getPositionParent
	@description
	traverses up the DOM to find the next element that isn't statically positioned
	@param p_oObject
	the item of which you want to find the positioning parent 
*/
function getPositionParent(p_oObject)
{
	do 
	{
		p_oObject = p_oObject.parentNode;
		console.log(p_oObject)
		console.log(getPosition(p_oObject))
	} while(notNull(p_oObject.parentNode) && getStyle(p_oObject, 'position') == 'static')
	return p_oObject;
}

/**
	@class Smooth Scrolling
	@description
	Smooth scrolling<br>
    Changes links that link to other parts of this page to scroll<br>
    smoothly to those links rather than jump to them directly, which<br>
    can be a little disorienting.<br>
   <br>
    sil, http://www.kryogenix.org/<br>
   <br>
    v1.0 2003-11-11<br>
    v1.1 2005-06-16 wrap it up in an object<br>
*/

var ss = 
{
	fixAllLinks: function() 
	{
		// Get a list of all links in the page
		var allLinks = document.getElementsByTagName('a');
		// Walk through the list
		for (var i=0;i<allLinks.length;i++) 
		{
			var lnk = allLinks[i];
			if ((lnk.href && lnk.href.indexOf('#') != -1) && 
			  ( (lnk.pathname == location.pathname) ||
			  ('/'+lnk.pathname == location.pathname) ) && 
			  (lnk.search == location.search)) 
			{
				// If the link is internal to the page (begins in #)
				// then attach the smoothScroll function as an onclick
				// event handler
				hookEvent(lnk,'click',ss.smoothScroll);
			}
		}
	},
	
	smoothScroll: function(p_varTarget) 
	{
		var l_oTarget = getElement(p_varTarget);
		if(getType(p_varTarget) == "element")
		{
			var l_iDestY = getPosition(l_oTarget)[1];
			var l_strAnchor  = "";
		}
		else
		{
			if (l_oTarget.nodeName.toLowerCase() != 'a')
				l_oTarget = l_oTarget.parentNode;
			if (l_oTarget.nodeName.toLowerCase() != 'a') return;
			var l_strAnchor = l_oTarget.hash.substr(1);
			var allLinks = document.getElementsByTagName('a');
			var destinationLink = null;
			for (var i=0;i<allLinks.length;i++) 
			{
				var lnk = allLinks[i];
				if (lnk.name && (lnk.name == l_strAnchor)) 
				{
					destinationLink = lnk;
					break;
				}
			}
			if (!destinationLink) destinationLink = getElement(l_strAnchor);
			if (!destinationLink) return true;
			var l_iDestY = getPosition(destinationLink)[1];
		}
		clearInterval(ss.INTERVAL);
		cypos = getScrollOffset()[1];
		
		ss_stepsize = parseInt((l_iDestY-cypos)/ss.STEPS);
		ss.INTERVAL = setInterval('ss.scrollWindow('+ss_stepsize+','+l_iDestY+',"'+l_strAnchor+'")',10);
		if (window.event) 
		{
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
		if (getType(p_varTarget) == 'event' && p_varTarget.preventDefault && p_varTarget.stopPropagation) 
		{
			p_varTarget.preventDefault();
			p_varTarget.stopPropagation();
		}
	},

	scrollWindow: function(scramount,dest,anchor) 
	{
		wascypos = getScrollOffset()[1];
		isAbove = (wascypos < dest);
		window.scrollTo(0,wascypos + scramount);
		iscypos = getScrollOffset()[1];
		isAboveNow = (iscypos < dest);
		if ((isAbove != isAboveNow) || (wascypos == iscypos)) 
		{
			// if we've just scrolled past the destination, or
			// we haven't moved from the last scroll (i.e., we're at the
			// bottom of the page) then scroll exactly to the link
			window.scrollTo(0,dest);
			// cancel the repeating timer
			clearInterval(ss.INTERVAL);
			// and jump to the link directly so the URL's right
			if(anchor != '')
				location.hash = anchor;
		}
	}
}

ss.STEPS = 25;

hookEvent(window,"domready",ss.fixAllLinks);


function lowerLimit(p_fNumber, p_fLimit)
{
	return p_fNumber >= p_fLimit ? p_fNumber : p_fLimit;
}

function upperLimit(p_fNumber, p_fLimit)
{
	return p_fNumber <= p_fLimit ? p_fNumber : p_fLimit;
}

///////////////////////////////////////////////////////////////////////////////////
// Easing Equations by Robert Penner, <http://www.robertpenner.com/easing/>
///////////////////////////////////////////////////////////////////////////////////

function linearTween(t, b, c, d)
{
	return c*t/d + b;
}

///////////// QUADRATIC EASING: t^2 ///////////////////

// quadratic easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in value, d: duration
// t and d can be in frames or seconds/milliseconds
function easeInQuad(t, b, c, d)
{
	return c*(t/=d)*t + b;
}

// quadratic easing out - decelerating to zero velocity
function easeOutQuad(t, b, c, d)
{
	return -c *(t/=d)*(t-2) + b;
}

// quadratic easing in/out - acceleration until halfway, then deceleration
function easeInOutQuad(t, b, c, d)
{
	if ((t/=d/2) < 1) return c/2*t*t + b;
	return -c/2 * ((--t)*(t-2) - 1) + b;
}


///////////// CUBIC EASING: t^3 ///////////////////////

// cubic easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in value, d: duration
// t and d can be frames or seconds/milliseconds
function easeInCubic(t, b, c, d)
{
	return c*(t/=d)*t*t + b;
}

// cubic easing out - decelerating to zero velocity
function easeOutCubic(t, b, c, d)
{
	return c*((t=t/d-1)*t*t + 1) + b;
}

// cubic easing in/out - acceleration until halfway, then deceleration
function easeInOutCubic(t, b, c, d)
{
	if ((t/=d/2) < 1) return c/2*t*t*t + b;
	return c/2*((t-=2)*t*t + 2) + b;
}


///////////// QUARTIC EASING: t^4 /////////////////////

// quartic easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in value, d: duration
// t and d can be frames or seconds/milliseconds
function easeInQuart(t, b, c, d)
{
	return c*(t/=d)*t*t*t + b;
}

// quartic easing out - decelerating to zero velocity
function easeOutQuart(t, b, c, d)
{
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
}

// quartic easing in/out - acceleration until halfway, then deceleration
function easeInOutQuart(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;
}


///////////// QUINTIC EASING: t^5  ////////////////////

// quintic easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in value, d: duration
// t and d can be frames or seconds/milliseconds
function easeInQuint(t, b, c, d)
{
	return c*(t/=d)*t*t*t*t + b;
}

// quintic easing out - decelerating to zero velocity
function easeOutQuint(t, b, c, d)
{
	return c*((t=t/d-1)*t*t*t*t + 1) + b;
}

// quintic easing in/out - acceleration until halfway, then deceleration
function easeInOutQuint(t, b, c, d)
{
	if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
	return c/2*((t-=2)*t*t*t*t + 2) + b;
}



///////////// SINUSOIDAL EASING: sin(t) ///////////////

// sinusoidal easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in position, d: duration
function easeInSine(t, b, c, d)
{
	return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
}

// sinusoidal easing out - decelerating to zero velocity
function easeOutSine(t, b, c, d)
{
	return c * Math.sin(t/d * (Math.PI/2)) + b;
}

// sinusoidal easing in/out - accelerating until halfway, then decelerating
function easeInOutSine(t, b, c, d)
{
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
}


///////////// EXPONENTIAL EASING: 2^t /////////////////

// exponential easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in position, d: duration
function easeInExpo(t, b, c, d)
{
	return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
}

// exponential easing out - decelerating to zero velocity
function easeOutExpo(t, b, c, d)
{
	return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
}

// exponential easing in/out - accelerating until halfway, then decelerating
function easeInOutExpo(t, b, c, d)
{
	if (t==0) return b;
	if (t==d) return b+c;
	if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
	return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
}


 /////////// CIRCULAR EASING: sqrt(1-t^2) //////////////

// circular easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in position, d: duration
function easeInCirc(t, b, c, d)
{
	return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
}

// circular easing out - decelerating to zero velocity
function easeOutCirc(t, b, c, d)
{
	return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
}

// circular easing in/out - acceleration until halfway, then deceleration
function easeInOutCirc(t, b, c, d)
{
	if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
	return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
}


 /////////// ELASTIC EASING: exponentially decaying sine wave  //////////////

// t: current time, b: beginning value, c: change in value, d: duration, a: amplitude (optional), p: period (optional)
// t and d can be in frames or seconds/milliseconds

function easeInElastic(t, b, c, d, a, p)
{
	if (t==0) 
		return b;
	if ((t/=d)==1)
		return b+c;
	if (!a) a=1; 
	if (!p) p=d*.3;
	if (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;
}

function easeOutElastic(t, b, c, d, a, p)
{
	if (t==0) return b;  if ((t/=d)==1) return b+c; if (!a) a=1;  if (!p) p=d*.3;
	if (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;
}

function easeInOutElastic(t, b, c, d, a, p)
{
	if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!a) a=1; if (!p) p=d*(.3*1.5);
	if (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;
}


 /////////// BACK EASING: overshooting cubic easing: (s+1)*t^3 - s*t^2  //////////////

// back easing in - backtracking slightly, then reversing direction and moving to target
// t: current time, b: beginning value, c: change in value, d: duration, s: overshoot amount (optional)
// t and d can be in frames or seconds/milliseconds
// s controls the amount of overshoot: higher s means greater overshoot
// s has a default value of 1.70158, which produces an overshoot of 10 percent
// s==0 produces cubic easing with no overshoot
function easeInBack(t, b, c, d, s)
{
	if (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
function easeOutBack(t, b, c, d, s)
{
	if (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
function easeInOutBack(t, b, c, d, s)
{
	if (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;
}


 /////////// BOUNCE EASING: exponentially decaying parabolic bounce  //////////////

// bounce easing in
// t: current time, b: beginning value, c: change in position, d: duration
function easeInBounce(t, b, c, d)
{
	return c - easeOutBounce (d-t, 0, c, d) + b;
}

// bounce easing out
function easeOutBounce(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 easing in/out
function easeInOutBounce(t, b, c, d)
{
	if (t < d/2) return easeInBounce (t*2, 0, c, d) * .5 + b;
	return easeOutBounce (t*2-d, 0, c, d) * .5 + c*.5 + b;
}
