@@ -0,0 +1,167 @@
1+window.onload = function(){
2+ if (typeof jQuery === 'undefined') {
3+ alert("ERROR: parallax.js requires jQuery.");
4+ } else {
5+ var updateparallax = function(){
6+ parallax.width = window.innerWidth;
7+ parallax.height = window.innerHeight;
8+ }
9+ updateparallax();
10+ $(window).resize(function(){updateparallax();});
11+ }
12+}
13+
14+var parallaxPage = function(name, htmlObject){
15+ return{
16+ key: name,
17+ page : htmlObject,
18+
19+ right : function(callback){return this.transition({left:parallax.width,top:0} ,{left:-parallax.width,top:0} ,callback);},
20+ left : function(callback){return this.transition({left:-parallax.width,top:0} ,{left:parallax.width,top:0} ,callback);},
21+ top : function(callback){return this.transition({left:0,top:-parallax.height},{left:0,top:parallax.height} ,callback);},
22+ bottom : function(callback){return this.transition({left:0,top:parallax.height} ,{left:0,top:-parallax.height},callback);},
23+
24+ transition : function(locationNew, locationOld, callback){
25+ if(!parallax.sliding){
26+ parallax.sliding = true;
27+ var thisPage = this;
28+ if(parallax.current !== this){
29+ this.hide(locationNew);
30+ if(typeof parallax.preload === 'function'){ parallax.preload(); }
31+ if(typeof this.preload === 'function'){ this.preload(); }
32+ this.slide({left:0,top:0}, function(){
33+ thisPage.makeCurrent();
34+ if(typeof callback === 'function'){ callback(); }
35+ });
36+ if(typeof parallax.current !== 'undefined'){
37+ parallax.current.slide(
38+ locationOld,
39+ function(){parallax.sliding = false;}
40+ );
41+ }
42+ parallax.slideBackground(locationNew);
43+ }
44+ }
45+ return this;
46+ },
47+
48+ slide : function(css, callback){
49+ this.page.css("display", "block");
50+ this.page.stop().animate(css, parallax.speed, parallax.easing,
51+ function(){if(typeof callback === "function"){callback();}
52+ });
53+ },
54+
55+ hide : function(newLocation){
56+ newLocation = newLocation || {left:parallax.width,top:0}; //defaults left off screen
57+ this.page.css("display", "none");
58+ this.page.css(newLocation);
59+ return this;
60+ },
61+
62+ show : function(newLocation){
63+ newLocation = newLocation || {left:0,top:0}; //defaults on screen
64+ if(typeof parallax.current !== 'undefined'){
65+ parallax.current.hide();
66+ }
67+ this.makeCurrent();
68+ this.page.css("display", "block");
69+ this.page.css(newLocation);
70+ return this;
71+ },
72+
73+ makeCurrent : function(){
74+ if(this === parallax.current){
75+ return false;
76+ }else{
77+ if(typeof parallax.current !== 'undefined'){
78+ parallax.current.hide();
79+ parallax.last = parallax.current;
80+ }
81+ if(parallax.updateUrl === true){ this.updateUrl(); }
82+ if(typeof parallax.onload == 'function'){ parallax.onload();}
83+ if(typeof this.onload === 'function'){ this.onload();}
84+ parallax.current = this;
85+ }
86+ return true;
87+ },
88+
89+ updateUrl : function(){
90+ var url = document.URL;
91+ url = (url.lastIndexOf("#") === -1)? url : url.substring(0, url.lastIndexOf("#"));
92+ window.location.href = url + "#" + this.key;
93+ },
94+
95+ ackbar : function(){ alert(this.key + " thinks it's a trap!"); return this;},
96+ };
97+};
98+
99+
100+var parallax = {
101+
102+ speed : 800,
103+ easing : 'swing',
104+ sliding : false,
105+ unusableNames : ["last", "current", "background","onload","updateUrl", "preload"],
106+ scaling : 0.15,
107+
108+ add : function(key,object) {
109+ var check = true;
110+ if(typeof key === 'object'){
111+ try{
112+ object = key
113+ key = key.attr('id');
114+ } catch(err){
115+ check = false;
116+ alert("ERROR:Page object lacks an id");
117+ }
118+ }else if(typeof key !== 'string'){
119+ check = false;
120+ alert("ERROR:undefined key");
121+ }
122+
123+ if(typeof object !== 'object'){
124+ check = false;
125+ alert("ERROR:undefined page");
126+ }
127+
128+ if(check){
129+ validKeyName = true;
130+ for(propName in this){
131+ if(propName === key) {
132+ validKeyName = false;
133+ }
134+ }
135+ if($.inArray(key, this.unusableNames) !== -1){
136+ validKeyName = false;
137+ }
138+ if(validKeyName){
139+ this[key] = parallaxPage(key,object);
140+ this[key].hide();
141+ this[key].page.css("position","absolute");
142+ }else{
143+ alert("ERROR:'"+key+"' cannot be used as a page identifier");
144+ }
145+ }
146+ return this;
147+ },
148+
149+ fromUrl : function(){
150+ var temp = document.URL.lastIndexOf("#")
151+ if(temp !== -1){
152+ pageName = document.URL.substring(temp + 1, document.URL.length);
153+ if(parallax.hasOwnProperty(pageName)){
154+ return parallax[pageName];
155+ }
156+ }
157+ },
158+
159+ slideBackground : function(newLocation){
160+ if(typeof this.background !== 'undefined' && typeof newLocation !== 'undefined'){
161+ $(this.background).animate({
162+ 'background-position-x': '+=' + -newLocation.left * parallax.scaling + 'px',
163+ 'background-position-y': '+=' + -newLocation.top * parallax.scaling + 'px',
164+ }, parallax.speed, parallax.easing);
165+ }
166+ },
167+};