﻿/*  
	Animator.js 1.1.9
	
	This library is released under the BSD license:

	Copyright (c) 2006, Bernard Sumption. 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 BernieCode nor
	the names of its 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 REGENTS 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.

*/

// http://www.berniecode.com/writing/animator.html

// Applies a sequence of numbers between 0 and 1 to a number of subjects
// construct - see setOptions for parameters
function Animator(a){this.setOptions(a);var b=this;this.timerDelegate=function(){b.onTimerEvent()};this.subjects=[];this.subjectScopes=[];this.target=0;this.state=0;this.lastTime=null}Animator.prototype={setOptions:function(a){this.options=Animator.applyDefaults({interval:20,duration:400,onComplete:function(){},onStep:function(){},transition:Animator.tx.easeInOut},a)},seekTo:function(a){this.seekFromTo(this.state,a)},seekFromTo:function(b,a){this.target=Math.max(0,Math.min(1,a));this.state=Math.max(0,Math.min(1,b));this.lastTime=new Date().getTime();if(!this.intervalId){this.intervalId=window.setInterval(this.timerDelegate,this.options.interval)}},jumpTo:function(a){this.target=this.state=Math.max(0,Math.min(1,a));this.propagate()},toggle:function(){this.seekTo(1-this.target)},addSubject:function(a,b){this.subjects[this.subjects.length]=a;this.subjectScopes[this.subjectScopes.length]=b;return this},clearSubjects:function(){this.subjects=[];this.subjectScopes=[]},propagate:function(){var b=this.options.transition(this.state);for(var a=0;a<this.subjects.length;a++){if(this.subjects[a].setState){this.subjects[a].setState(b)}else{this.subjects[a].apply(this.subjectScopes[a],[b])}}},onTimerEvent:function(){var c=new Date().getTime();var a=c-this.lastTime;this.lastTime=c;var b=(a/this.options.duration)*(this.state<this.target?1:-1);if(Math.abs(b)>=Math.abs(this.state-this.target)){this.state=this.target}else{this.state+=b}try{this.propagate()}finally{this.options.onStep.call(this);if(this.target==this.state){window.clearInterval(this.intervalId);this.intervalId=null;this.options.onComplete.call(this)}}},play:function(){this.seekFromTo(0,1)},reverse:function(){this.seekFromTo(1,0)},inspect:function(){var b="#<Animator:\n";for(var a=0;a<this.subjects.length;a++){b+=this.subjects[a].inspect()}b+=">";return b}};Animator.applyDefaults=function(c,b){b=b||{};var d,a={};for(d in c){a[d]=b[d]!==undefined?b[d]:c[d]}return a};Animator.makeArray=function(c){if(c==null){return[]}if(!c.length){return[c]}var a=[];for(var b=0;b<c.length;b++){a[b]=c[b]}return a};Animator.camelize=function(c){var e=c.split("-");if(e.length==1){return e[0]}var b=c.indexOf("-")==0?e[0].charAt(0).toUpperCase()+e[0].substring(1):e[0];for(var d=1,a=e.length;d<a;d++){var f=e[d];b+=f.charAt(0).toUpperCase()+f.substring(1)}return b};Animator.apply=function(c,b,a){if(b instanceof Array){return new Animator(a).addSubject(new CSSStyleSubject(c,b[0],b[1]))}return new Animator(a).addSubject(new CSSStyleSubject(c,b))};Animator.makeEaseIn=function(b){return function(a){return Math.pow(a,b*2)}};Animator.makeEaseOut=function(b){return function(a){return 1-Math.pow(1-a,b*2)}};Animator.makeElastic=function(a){return function(b){b=Animator.tx.easeInOut(b);return((1-Math.cos(b*Math.PI*a))*(1-b))+b}};Animator.makeADSR=function(d,b,c,a){if(a==null){a=0.5}return function(e){if(e<d){return e/d}if(e<b){return 1-((e-d)/(b-d)*(1-a))}if(e<c){return a}return a*(1-((e-c)/(1-c)))}};Animator.makeBounce=function(a){var b=Animator.makeElastic(a);return function(c){c=b(c);return c<=1?c:2-c}};Animator.tx={easeInOut:function(a){return((-Math.cos(a*Math.PI)/2)+0.5)},linear:function(a){return a},easeIn:Animator.makeEaseIn(1.5),easeOut:Animator.makeEaseOut(1.5),strongEaseIn:Animator.makeEaseIn(2.5),strongEaseOut:Animator.makeEaseOut(2.5),elastic:Animator.makeElastic(1),veryElastic:Animator.makeElastic(3),bouncy:Animator.makeBounce(1),veryBouncy:Animator.makeBounce(3)};function NumericalStyleSubject(b,c,e,d,a){this.els=Animator.makeArray(b);if(c=="opacity"&&window.ActiveXObject){this.property="filter"}else{this.property=Animator.camelize(c)}this.from=parseFloat(e);this.to=parseFloat(d);this.units=a!=null?a:"px"}NumericalStyleSubject.prototype={setState:function(f){var d=this.getStyle(f);var a=(this.property=="opacity"&&f==0)?"hidden":"";var b=0;for(var c=0;c<this.els.length;c++){try{this.els[c].style[this.property]=d}catch(g){if(this.property!="fontWeight"){throw g}}if(b++>20){return}}},getStyle:function(a){a=this.from+((this.to-this.from)*a);if(this.property=="filter"){return"alpha(opacity="+Math.round(a*100)+")"}if(this.property=="opacity"){return a}return Math.round(a)+this.units},inspect:function(){return"\t"+this.property+"("+this.from+this.units+" to "+this.to+this.units+")\n"}};function ColorStyleSubject(a,b,d,c){this.els=Animator.makeArray(a);this.property=Animator.camelize(b);this.to=this.expandColor(c);this.from=this.expandColor(d);this.origFrom=d;this.origTo=c}ColorStyleSubject.prototype={expandColor:function(b){var c,e,d,a;c=ColorStyleSubject.parseColor(b);if(c){e=parseInt(c.slice(1,3),16);d=parseInt(c.slice(3,5),16);a=parseInt(c.slice(5,7),16);return[e,d,a]}if(window.DEBUG){alert("Invalid colour: '"+b+"'")}},getValueForState:function(a,b){return Math.round(this.from[a]+((this.to[a]-this.from[a])*b))},setState:function(c){var a="#"+ColorStyleSubject.toColorPart(this.getValueForState(0,c))+ColorStyleSubject.toColorPart(this.getValueForState(1,c))+ColorStyleSubject.toColorPart(this.getValueForState(2,c));for(var b=0;b<this.els.length;b++){this.els[b].style[this.property]=a}},inspect:function(){return"\t"+this.property+"("+this.origFrom+" to "+this.origTo+")\n"}};ColorStyleSubject.parseColor=function(d){var a="#",c;if(c=ColorStyleSubject.parseColor.rgbRe.exec(d)){var b;for(var e=1;e<=3;e++){b=Math.max(0,Math.min(255,parseInt(c[e])));a+=ColorStyleSubject.toColorPart(b)}return a}if(c=ColorStyleSubject.parseColor.hexRe.exec(d)){if(c[1].length==3){for(var e=0;e<3;e++){a+=c[1].charAt(e)+c[1].charAt(e)}return a}return"#"+c[1]}return false};ColorStyleSubject.toColorPart=function(a){if(a>255){a=255}var b=a.toString(16);if(a<16){return"0"+b}return b};ColorStyleSubject.parseColor.rgbRe=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i;ColorStyleSubject.parseColor.hexRe=/^\#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function DiscreteStyleSubject(b,c,e,d,a){this.els=Animator.makeArray(b);this.property=Animator.camelize(c);this.from=e;this.to=d;this.threshold=a||0.5}DiscreteStyleSubject.prototype={setState:function(c){var a=0;for(var b=0;b<this.els.length;b++){this.els[b].style[this.property]=c<=this.threshold?this.from:this.to}},inspect:function(){return"\t"+this.property+"("+this.from+" to "+this.to+" @ "+this.threshold+")\n"}};function CSSStyleSubject(d,m,j){d=Animator.makeArray(d);this.subjects=[];if(d.length==0){return}var a,n,b;if(j){b=this.parseStyle(m,d[0]);n=this.parseStyle(j,d[0])}else{n=this.parseStyle(m,d[0]);b={};for(a in n){b[a]=CSSStyleSubject.getStyle(d[0],a)}}var a;for(a in b){if(b[a]==n[a]){delete b[a];delete n[a]}}var a,h,e,i,l,k;for(a in b){var g=String(b[a]);var c=String(n[a]);if(n[a]==null){if(window.DEBUG){alert("No to style provided for '"+a+'"')}continue}if(l=ColorStyleSubject.parseColor(g)){k=ColorStyleSubject.parseColor(c);i=ColorStyleSubject}else{if(g.match(CSSStyleSubject.numericalRe)&&c.match(CSSStyleSubject.numericalRe)){l=parseFloat(g);k=parseFloat(c);i=NumericalStyleSubject;e=CSSStyleSubject.numericalRe.exec(g);var f=CSSStyleSubject.numericalRe.exec(c);if(e[1]!=null){h=e[1]}else{if(f[1]!=null){h=f[1]}else{h=f}}}else{if(g.match(CSSStyleSubject.discreteRe)&&c.match(CSSStyleSubject.discreteRe)){l=g;k=c;i=DiscreteStyleSubject;h=0}else{if(window.DEBUG){alert("Unrecognised format for value of "+a+": '"+b[a]+"'")}continue}}}this.subjects[this.subjects.length]=new i(d,a,l,k,h)}}CSSStyleSubject.prototype={parseStyle:function(b,c){var g={};if(b.indexOf(":")!=-1){var j=b.split(";");for(var e=0;e<j.length;e++){var d=CSSStyleSubject.ruleRe.exec(j[e]);if(d){g[d[1]]=d[2]}}}else{var a,h,f;f=c.className;c.className=b;for(var e=0;e<CSSStyleSubject.cssProperties.length;e++){a=CSSStyleSubject.cssProperties[e];h=CSSStyleSubject.getStyle(c,a);if(h!=null){g[a]=h}}c.className=f}return g},setState:function(b){for(var a=0;a<this.subjects.length;a++){this.subjects[a].setState(b)}},inspect:function(){var b="";for(var a=0;a<this.subjects.length;a++){b+=this.subjects[a].inspect()}return b}};CSSStyleSubject.getStyle=function(b,c){var a;if(document.defaultView&&document.defaultView.getComputedStyle){a=document.defaultView.getComputedStyle(b,"").getPropertyValue(c);if(a){return a}}c=Animator.camelize(c);if(b.currentStyle){a=b.currentStyle[c]}return a||b.style[c]};CSSStyleSubject.ruleRe=/^\s*([a-zA-Z\-]+)\s*:\s*(\S(.+\S)?)\s*$/;CSSStyleSubject.numericalRe=/^-?\d+(?:\.\d+)?(%|[a-zA-Z]{2})?$/;CSSStyleSubject.discreteRe=/^\w+$/;CSSStyleSubject.cssProperties=["azimuth","background","background-attachment","background-color","background-image","background-position","background-repeat","border-collapse","border-color","border-spacing","border-style","border-top","border-top-color","border-right-color","border-bottom-color","border-left-color","border-top-style","border-right-style","border-bottom-style","border-left-style","border-top-width","border-right-width","border-bottom-width","border-left-width","border-width","bottom","clear","clip","color","content","cursor","direction","display","elevation","empty-cells","css-float","font","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","height","left","letter-spacing","line-height","list-style","list-style-image","list-style-position","list-style-type","margin","margin-top","margin-right","margin-bottom","margin-left","max-height","max-width","min-height","min-width","orphans","outline","outline-color","outline-style","outline-width","overflow","padding","padding-top","padding-right","padding-bottom","padding-left","pause","position","right","size","table-layout","text-align","text-decoration","text-indent","text-shadow","text-transform","top","vertical-align","visibility","white-space","width","word-spacing","z-index","opacity","outline-offset","overflow-x","overflow-y"];function AnimatorChain(c,a){this.animators=c;this.setOptions(a);for(var b=0;b<this.animators.length;b++){this.listenTo(this.animators[b])}this.forwards=false;this.current=0}AnimatorChain.prototype={setOptions:function(a){this.options=Animator.applyDefaults({resetOnPlay:true},a)},play:function(){this.forwards=true;this.current=-1;if(this.options.resetOnPlay){for(var a=0;a<this.animators.length;a++){this.animators[a].jumpTo(0)}}this.advance()},reverse:function(){this.forwards=false;this.current=this.animators.length;if(this.options.resetOnPlay){for(var a=0;a<this.animators.length;a++){this.animators[a].jumpTo(1)}}this.advance()},toggle:function(){if(this.forwards){this.seekTo(0)}else{this.seekTo(1)}},listenTo:function(a){var b=a.options.onComplete;var c=this;a.options.onComplete=function(){if(b){b.call(a)}c.advance()}},advance:function(){if(this.forwards){if(this.animators[this.current+1]==null){return}this.current++;this.animators[this.current].play()}else{if(this.animators[this.current-1]==null){return}this.current--;this.animators[this.current].reverse()}},seekTo:function(a){if(a<=0){this.forwards=false;this.animators[this.current].seekTo(0)}else{this.forwards=true;this.animators[this.current].seekTo(1)}}};function Accordion(k){this.setOptions(k);var b=this.options.initialSection,g;if(this.options.rememberance){g=document.location.hash.substring(1)}this.rememberanceTexts=[];this.ans=[];var f=this;for(var c=0;c<this.options.sections.length;c++){var a=this.options.sections[c];var d=new Animator(this.options.animatorOptions);var j=this.options.from+(this.options.shift*c);var h=this.options.to+(this.options.shift*c);d.addSubject(new NumericalStyleSubject(a,this.options.property,j,h,this.options.units));d.jumpTo(0);var e=this.options.getActivator(a);e.index=c;e.onclick=function(){f.show(this.index)};this.ans[this.ans.length]=d;this.rememberanceTexts[c]=e.innerHTML.replace(/\s/g,"");if(this.rememberanceTexts[c]===g){b=c}}this.show(b)}Accordion.prototype={setOptions:function(a){this.options=Object.extend({sections:null,getActivator:function(b){return document.getElementById(b.getAttribute("activator"))},shift:0,initialSection:0,rememberance:true,animatorOptions:{}},a||{})},show:function(b){for(var a=0;a<this.ans.length;a++){this.ans[a].seekTo(a>b?1:0)}if(this.options.rememberance){document.location.hash=this.rememberanceTexts[b]}}};
