// Element.measure
MooTools.More={version:"1.3.0.1",build:"6dce99bed2792dffcbbbb4ddc15a1fb9a41994b5"};(function(){var a=function(d,c){var e=[];Object.each(c,function(f){Object.each(f,function(g){d.each(function(h){e.push(h+"-"+g+(h=="border"?"-width":""));
});});});return e;};var b=function(e,d){var c=0;Object.each(d,function(g,f){if(f.test(e)){c=c+g.toInt();}});return c;};Element.implement({measure:function(h){var d=function(j){return !!(!j||j.offsetHeight||j.offsetWidth);
};if(d(this)){return h.apply(this);}var g=this.getParent(),i=[],e=[];while(!d(g)&&g!=document.body){e.push(g.expose());g=g.getParent();}var f=this.expose();
var c=h.apply(this);f();e.each(function(j){j();});return c;},expose:function(){if(this.getStyle("display")!="none"){return function(){};}var c=this.style.cssText;
this.setStyles({display:"block",position:"absolute",visibility:"hidden"});return function(){this.style.cssText=c;}.bind(this);},getDimensions:function(c){c=Object.merge({computeSize:false},c);
var h={x:0,y:0};var g=function(i,e){return(e.computeSize)?i.getComputedSize(e):i.getSize();};var d=this.getParent("body");if(d&&this.getStyle("display")=="none"){h=this.measure(function(){return g(this,c);
});}else{if(d){try{h=g(this,c);}catch(f){}}}return Object.append(h,(h.x||h.x===0)?{width:h.x,height:h.y}:{x:h.width,y:h.height});},getComputedSize:function(c){if(c&&c.plains){c.planes=c.plains;
}c=Object.merge({styles:["padding","border"],planes:{height:["top","bottom"],width:["left","right"]},mode:"both"},c);var e={},d={width:0,height:0};if(c.mode=="vertical"){delete d.width;
delete c.planes.width;}else{if(c.mode=="horizontal"){delete d.height;delete c.planes.height;}}a(c.styles,c.planes).each(function(f){e[f]=this.getStyle(f).toInt();
},this);Object.each(c.planes,function(g,f){var h=f.capitalize();e[f]=this.getStyle(f).toInt();d["total"+h]=e[f];g.each(function(j){var i=b(j,e);d["computed"+j.capitalize()]=i;
d["total"+h]+=i;});},this);return Object.append(d,e);}});})();

window.addEvent('domready', function(){

	// by default, change location
	if (location.hash == ''){
		loc = location.href.replace('http://www.chrisfrazersmith.com/', '');
		if (loc == '') loc = 'index.php';
		window.location = 'index.php#!/' + loc;
		$(document.body).setStyle('display', 'none');
		return;
	} else {
		$(document.body).setStyle('display', 'block');
	}

	NAVANIMATING = false;

	// native anchor or page?
	nativeAnchor = function(hash){
		return (hash.indexOf('!') == -1);
	};
	
	// page title
	pageTitle = function(s){
		document.title = s + ' : Chris Frazer Smith';
	};
	
	// page error
	pageError = function(){
		
		// set page title
		pageTitle('Error');
		
		// load in error page
		changePage('!/error.php');
		
	};
	
	// change section
	changeSection = function(s){
	
		$('container').getElements('.top .gallery li').removeClass('selected')[s-1].addClass('selected');
	
	};

	// animate top bar in
	animateTopIn = function(){
			
		if ($('container').getElement('.top').getSize().y > 1) return;
		
		NAVANIMATING = true;
	
		// bring height in
		$('container').getElement('.top')
		.set('morph', { duration: 1200 })
		.setStyles({
			'height': 0,
			'opacity' : 0,
			'margin-bottom': 40
		})
		.morph({
			'height': 50,
			'opacity': 1,
			'margin-bottom': 83
		});
		
		// hide all nav elements
		$('container').getElements('ul.nav li')
		.each(function(el, i){
			
			// set height
			el.setStyles({
				'opacity' : 0
			});
			
			// tween
			(function(){
				el.tween('opacity', 1);
			}.delay(2200 + (i * 150)));
			
		});

		// hide all cat elements
		$('container').getElements('ul.gallery li')
		.each(function(el, i){
			
			// set height
			el.setStyles({
				'opacity' : 0
			});
			
			// tween
			(function(){
				el.tween('opacity', 1);
			}.delay(1200 + (i * 150)));
			
		});
		
		(function(){ NAVANIMATING = false; }.delay(2000));
	
	};
	
	// animate top bar out
	animateTopOut = function(faster){
		
		(function(){
	
			// bring height in
			$('container').getElement('.top')
			.set('morph', { duration: 1200 })
			.setStyles({
				'height': 50,
				'opacity' : 1,
				'margin-bottom': 83
			})
			.morph({
				'height': 0,
				'opacity': 0,
				'margin-bottom': 40
			});
		
		}.delay(faster ? 1000 : 2000));
		
		len = $('container').getElements('ul.nav li').length;
		
		// hide all nav elements
		$('container').getElements('ul.nav li')
		.each(function(el, i){
			
			// set height
			el.setStyles({
				'opacity' : 1
			});
			
			// tween
			(function(){
				el.tween('opacity', 0);
			}.delay(((len-i) * (faster ? 50 : 150) )));
			
		});
		
		len2 = $('container').getElements('ul.nav li').length;

		// hide all cat elements
		$('container').getElements('ul.gallery li')
		.each(function(el, i){
			
			// set height
			el.setStyles({
				'opacity' : 1
			});
			
			// tween
			(function(){
				el.tween('opacity', 0);
			}.delay((faster ? 500 : 1000) + (len2-i) * (faster ? 50 : 150)));
			
		});
	
	};
	
	// animate bottom bar out
	animateBottomOut = function(){
	
		// take strip out
		$('container').getElement('div.strip')
		.morph({
			'margin-bottom': -64,
			'height': 0
		}); 
		
	};
	
	// animate bottom bar to FS
	animateBottomToFS = function(){
	
		// take strip out
		$('container').getElement('div.strip')
		.morph({
			'margin-bottom': 0,
			'height': 20
		}); 
		
	};
	
	// animate bottom bar in
	animateBottomIn = function(){
		
		// bring strip in
		$('container').getElement('div.strip')
		.morph({
			'margin-bottom': 0,
			'height': 80
		});
	
	};
	
	// to full screen mode
	toFullScreen = function(){
	
		$('container').addClass('fullscreen');
		$('container').getElement('.viewer').setStyle('opacity', 0);
	
		// animate bars out
		animateBottomOut();
		animateTopOut(true);
		animateBottomToFS.delay(2500);
		
		// resize viewer
		resizeViewer.delay(2000);
		
		// toggle buttons
		$('container').getElement('.strip .toFs').setStyle('display', 'none');
		(function(){ $('container').getElement('.strip .fromFs').setStyle('display', 'block'); }.delay(2000));
	
	};
	
	ANIMATEIMAGES = false;
	DONTANIMATEIMAGES = false;
	
	// from fullscreen mode
	fromFullScreen = function(){
	
		$('container').removeClass('fullscreen');
		ANIMATEIMAGES = true;
		DONTANIMATEIMAGES = false;
		(function(){ ANIMATEIMAGES = false; }.delay(2300));
	
		// animate bars in
		animateTopIn();
		animateBottomIn();

		// resize viewer
		resizeViewer.delay(2000);
		
		// toggle buttons
		(function(){ $('container').getElement('.strip .toFs').setStyle('display', 'block'); }.delay(2000));
		$('container').getElement('.strip .fromFs').setStyle('display', 'none');
	
	}
		
	// resize the main viewing window
	resizeViewer = function(){
		
		if ($('container').getElement('.content').getSize().y >= 2) return;
			
		// padding from viewer
		takeOffWidth = 78;
	
		// whats our avail width
		availWidth = $('container').getSize().x - takeOffWidth;
		if ( availWidth < parseInt($(document.body).getSize('min-width')) ){
			availWidth = parseInt($(document.body).getSize('min-width'))
		}
		
		// take off height
		takeOffHeight = $('container').hasClass('fullscreen') ? 127 : 107;
				
		// top height
		if (!$('container').hasClass('fullscreen') && $('container').getElement('.top').getSize().y > 5){
			takeOffHeight += 41;//$('container').getElement('.top').getSize().y;
		}
				
		// bottom height
		if (!$('container').hasClass('fullscreen') && $('container').getElement('.strip') && $('container').getElement('.strip').getSize().y > 5){
			takeOffHeight += $('container').getElement('.strip').getSize().y + 40;
		}
				
		// whats our avail height
		availHeight = window.getSize().y - takeOffHeight;
		if ( availHeight < parseInt($(document.body).getSize('min-height')) ){
			availHeight = parseInt($(document.body).getSize('min-height'))
		}
				
		// home page
		if ($('container').getElement('.fs')){
		
			$('container').getElements('.fs img, .fs .ipad-img')
			.each(function(el){
			
				// vars
				mywidth = width = $('container').getElement('.fs').getSize().x;
				myheight = height = $('container').getElement('.fs').getSize().y;
			
				// maintain proportions
				if (el.getProperty('width') > el.getProperty('height')){
					
					// landscape
					myheight = (width / el.getProperty('width')) * el.getProperty('height');
					
					if (myheight < height){
						myheight = height;
						mywidth = (height / el.getProperty('height')) * el.getProperty('width');
					}
				
				} else {
				
					// portrait
					mywidth = (height / el.getProperty('height')) * el.getProperty('width');
					
					if (mywidth < width){
						mywidth = width;
						myheight = (width / el.getProperty('width')) * el.getProperty('height');
					}

								
				}
			
				// morph size
				el.setStyles({
					'width' : mywidth,
					'height' : myheight
				});	
			
			});			
		}
		
		// width, height
		width = availWidth;//856;
		height = availHeight;//430;
		
		// landscape or portrait?
		if ((availWidth/width) < (availHeight/height)){
		
			// landscape
			height = (availWidth / width ) * height;
			width = availWidth;
			
		} else {
		
			// portrait
			width = (availHeight / height ) * width;
			height = availHeight;
			
		}
						
		// resize me
		if ($('container').getElement('.viewer')){
		
			// viewer box
			$('container').getElement('.viewer')
			.morph({
				'width' : availWidth,
				'height' : availHeight
			});
			
			// viewer images
			$('container').getElements('.viewer img, .viewer .ipad-img')
			.each(function(el){
			
				// vars
				mywidth = width;
				myheight = height;
			
				// maintain proportions
				if (parseInt(el.getProperty('width')) >= parseInt(el.getProperty('height'))){
					
					// landscape
					myheight = (width / el.getProperty('width')) * el.getProperty('height');
					
					if (myheight > height){
						myheight = height;
						mywidth = (height / el.getProperty('height')) * el.getProperty('width');
					}
				
				} else {
				
					// portrait
					mywidth = (height / el.getProperty('height')) * el.getProperty('width');
					
					if (mywidth > width){
						mywidth = width;
						myheight = (width / el.getProperty('width')) * el.getProperty('height');
					}

								
				}
				
				if (el.hasClass('ipad-img')){
					el.setStyles({
						'width' : width,
						'height' : height
					});	
					el.setStyle('background-size', (parseInt(mywidth)) + 'px ' + (parseInt(myheight)) + 'px');
				}
							
				// morph size
				if (($('container').hasClass('fullscreen') || ANIMATEIMAGES) && !DONTANIMATEIMAGES){
					el.morph({
						'width' : mywidth,
						'height' : myheight
					});	
				} else {
					el.setStyles({
						'width' : mywidth,
						'height' : myheight
					});					
				}
			});	
			
			// viewer objects
			$('container').getElements('.viewer iframe, .viewer object')
			.each(function(el){
			
				// vars
				mywidth = width;
				myheight = height;
			
				// maintain proportions
				if (el.getProperty('width') > el.getProperty('height')){
					
					// landscape
					myheight = (width / el.getProperty('width')) * el.getProperty('height');
					
					if (myheight > height){
						myheight = height;
						mywidth = (height / el.getProperty('height')) * el.getProperty('width');
					}
				
				} else {
				
					// portrait
					mywidth = (height / el.getProperty('height')) * el.getProperty('width');
					
					if (mywidth > width){
						mywidth = width;
						myheight = (width / el.getProperty('width')) * el.getProperty('height');
					}

								
				}
			
				// morph size
				if (($('container').hasClass('fullscreen') || ANIMATEIMAGES) && !DONTANIMATEIMAGES){
					el.morph({
						'width' : mywidth,
						'height' : myheight
					});	
				} else {
					el.setStyles({
						'width' : mywidth,
						'height' : myheight
					});					
				}
			});	

			
		}
		
		// measure strip
		measureStrip();
	
	}
	
	// replace paths
	replacePaths = function(el){
	
		// replace links
		el.getElements('a')
		.each(function(a){
			if ((a.getProperty('href').indexOf('http://www.chrisfrazersmith.com') != -1 || a.getProperty('href').indexOf('http://') == -1) && a.getProperty('href').indexOf('#') == -1){
				a.addEvent('click', function(ev){
				
					if (ev) ev.stop();
					location.href = 'index.php#!/' + this.getProperty('href').replace('http://www.chrisfrazersmith.com/', '');
					
				});
			}
		});
		
		// replace forms
		el.getElements('form')
		.each(function(f){
		
			if (f.getParent('div.search')) return;
		
			f.set('send', { method: 'post', onSuccess: function(j){ pageLoaderSuccess(JSON.decode(j)); }, headers: { 'HTTP_ACCEPT' : 'application/json' } });
			f.addEvent('valid', function(){
				f.send();
			})
			f.addEvent('submit', function(ev){
				ev.stop();
			});
		
		});
	
	};
	
	// called on json receipt
	pageLoaderSuccess = function(j){
								
		if (j){
		
			DONTANIMATEIMAGES = false;
		
			// root el
			el = $('container');
			
			el.getElement('.fs').setStyle('display', 'none');
			el.getElement('.strip').setStyle('display', 'block');
			el.getElement('.viewer').setStyle('display', 'block');
			el.getElement('.top').removeClass('white');
			$('container').getElements('.gallery li, .top .nav li').fireEvent('mouseleave');
			
			$(document.body).setStyle('overflow', 'auto');
					
			// full screen mode works differently
			if (!el.hasClass('fullscreen')){
					
				// clear homerotate
				try { clearInterval(homeRotate); } catch(e){ }
			
				animateTopIn();
						
				// change page title?
				if (j.title) pageTitle(j.title);
				
				if (j.section) changeSection(j.section);
								
				// content?
				if (j.content){
				
					// fade out viewer if necessary
					el.getElement('.viewer').tween('height', 0);
					if (Browser.ie7){
						el.getElement('.viewer').setStyle('display', 'none');
					}
					
					// fade out content
					el.getElement('.content').tween('height', 0);
					
					// animate out bottom bar
					animateBottomOut();
					
					(function(){
									
						el.getElement('.content').set('html', j.content);
						el.getElement('.content-sizer').set('html', j.content);
						
						$(document.body).setStyle('overflow', 'hidden');
						
						el.getElements('.content img, .content .ipad-img')
						.each(function(i){
							i.set('src', i.get('src') + '?' + String.uniqueID());
							i.addEvent('load', function(){
								(function(){
									var size = el.getElement('.content-sizer').measure(function(){
									    return this.getScrollSize();
									});
									el.getElement('.content').setStyle('height', size.y + 100);
								}.delay(150));
							});
						});
											
						var size = el.getElement('.content-sizer').measure(function(){
						    return this.getScrollSize();
						});
											
						el.getElement('.content').tween('height', size.y + 100);
						
						(function(){
							$(document.body).setStyle('overflow', 'auto');
						}.delay(1200));
						
					}.delay(800))
				
				// either content or we have images
				} else if (j.images){
				
					if (location.hash.indexOf('photo.php') == -1){
						$('container').getElement('.strip').scrollTo(0,0);
					}
							
					// fade out viewer if necessary
					el.getElement('.viewer').tween('opacity', 0);
					
					// fade out content
					el.getElement('.content').tween('height', 0);
					
					// animate out bottom bar
					animateBottomIn();
									
					// main image
					if (j.image){
						
						(function(){
							el.getElement('.viewer').set('html', j.image).tween('opacity', 1);
							el.getElements('.viewer img, .ipad-img').set('morph', { duration: 300 });
							if (/iPad/i.test(navigator.userAgent)){
								ANIMATEIMAGES = false;
							}
							window.fireEvent('resize');
						}.delay(800));
	
					}
					
					if (j.imagetitle){
						el.getElement('.title').set('html', j.imagetitle);
					} else {
						el.getElement('.title').set('html', '');
					}
				
					// strip needs to be emptied
					$('container').getElements('.strip li')
					.each(function(el){
						if (!el.hasClass('nav')){
							el.destroy();
						}
					});
					
					//$('container').getElement('.strip').scrollTo(0,0);
					
					// adopt new elements
					j.images.each(function(el, i){
					
						if (/iPad/i.test(navigator.userAgent)){
							var newel = new Element('li', { html: '<a href="photo.php?id=' + el.id + '"><span class="ipad-img2" style="background-image:url(\'' + el.thumb + '\'); height:' + el.height + 'px; width:' + el.width + 'px;" width="' + el.width + '" height="' + el.height + '" /></a>' });
						} else {
							var newel = new Element('li', { html: '<a href="photo.php?id=' + el.id + '"><img src="' + el.thumb + '" /></a>' });
						}
						if (i == 0) newel.addClass('selected');
						
						// newel click event
						newel.addEvent('click', function(ev){
							
							this.getParent('ul').getElements('li').removeClass('selected');
							this.addClass('selected');
							
						});
						
						// inject after first nav
						newel.inject($('container').getLast('.strip li.nav'), 'before');
						
						if (j.id){
							if (el.id == j.id){
								newel.fireEvent('click');
							}
						}
											
						// preload
						if (!(/iPad/i.test(navigator.userAgent)) && el.big){
							var i = new Image();
							i.src = 'http://chrisfrazersmith.com' + el.big;
						}
					
					});
					
					// total images
					$('container').getElement('.strip .pages .tp').set('html', j.images.length);
					
					// current image
					$('container').getElement('.strip .pages .cp').set('html', j.counter ? j.counter : 1);
					
					// measure
					measureStrip();
					
					// replace paths
					replacePaths($('container').getElement('.strip'));
				
				} else if (j.himages){ // home images
				
					$(document.body).setStyle('overflow', 'hidden');
								
					el.getElement('.viewer').setStyle('display', 'none').empty();
					el.getElement('.strip').setStyle('display', 'none');
					el.getElement('.fs').setStyle('display', 'block').empty().adopt(new Element('ul'));
					el.getElement('.top').addClass('white');
					el.getElements('.top li').removeClass('selected').fireEvent('mouseleave');
					$('container').getElements('.gallery li, .top .nav li').fireEvent('mouseenter');
					
					j.himages.each(function(e, i){
						el2 = new Element('li', { html: e });
						el.getElement('.fs ul').adopt(el2);
						if (i != 0){
							el2.setStyle('opacity', 0);
						}
					});
					
					//(function(){
						el.getElements('.fs img, .ipad-img')
						.set('morph', { duration: 300 });
						window.fireEvent('resize');
					//}.delay(800));
					
					// homepage rotating function
					var f = function(){
						var els = $('container').getElements('.fs li');
						var c = 0;
						els.each(function(el, i){
							if (el.getStyle('opacity') > 0){
								c = i;
							}
						});
						c++;
						if (c >= els.length) c = 0;
						els.each(function(el, i){
							if (i==c){
								el.setStyle('z-index', 2).tween('opacity', 1);
							} else {
								el.setStyle('z-index', 1).tween('opacity', 0);
							}
						});
					};
					
					homeRotate = f.periodical(7000);
									
				}
			
			} else {
				// special rules for full screen mode
			
				el.getElement('.viewer').tween('opacity', 0);
				
				(function(){
					if (j.imagetitle){
						el.getElement('.title').set('html', j.imagetitle);
					} else {
						el.getElement('.title').set('html', '');
					}
					el.getElement('.viewer').set('html', j.image).tween('opacity', 1);
					window.fireEvent('resize');
				}.delay(1000));
				
				DONTANIMATEIMAGES = true;
				
				// adopt new elements
				j.images.each(function(el, i){
				
					var newel = new Element('li', { html: '<a href="photo.php?id=' + el.id + '"><img src="' + el.thumb + '" /></a>' });
					if (i == 0) newel.addClass('selected');
					
					// newel click event
					newel.addEvent('click', function(ev){
						
						this.getParent('ul').getElements('li').removeClass('selected');
						this.getParent('li').addEvent('selected');
						
					});
				
					// inject after first nav
					newel.inject($('container').getLast('.strip li.nav'), 'before');
					
					// preload
					if (el.big){
						var i = new Image();
						i.src = 'http://chrisfrazersmith.com' + el.big;
					}
				
				});
				
				// total images
				$('container').getElement('.strip .pages .tp').set('html', j.images.length);
				
				// current image
				$('container').getElement('.strip .pages .cp').set('html', j.counter ? j.counter : 1);
				
				// measure
				measureStrip();
				
				// replace paths
				replacePaths($('container').getElement('.strip'));
				
				// current image
				$('container').getElement('.strip .pages .cp').set('html', j.counter ? j.counter : 1);
				$('container').getElement('.strip .pages .tp').set('html', j.images.length);
			
			}
			
			// set cache
			cache.set(location.hash.replace('#!/', ''), j);
					
		}
		
	};
	
	// strip click events
	if ($('container').getElement('.strip')){
		$('container').getElement('.strip .toFs')
		.addEvent('click', function(ev){ 
			if (ev) ev.stop(); 
			if (location.hash.indexOf('photo.php') != -1){
				window.location = 'index.php' + location.hash.replace('!/', '!/fullscreen/');
			} else {
				var h = $('container').getElement('.strip .line ul li a').getProperty('href');
				if (h) window.location = 'index.php#!/fullscreen/' + h;
			}
			//toFullScreen(); 
		});
		$('container').getElement('.strip .fromFs')
		.addEvent('click', function(ev){ 
			if (ev) ev.stop();
			window.location = 'index.php' + location.hash.replace('!/fullscreen/', '!/'); 
			//fromFullScreen(); 
		});
	}
	
	// measure strip
	measureStrip = function(){
	
		if ($('container').getElement('.strip')){
			
			// remove nav links
			$('container').getElements('.strip .nav').setStyle('display', 'none');
			
			// scroll size - do we need nav links?
			if ($('container').getElement('.strip .line').getScrollSize().y > $('container').getElement('.strip .line').getSize().y){
				$('container').getElements('.strip .nav').setStyle('display', 'block');
				$('container').getElement('.strip ul').setStyle('padding-left', 58);
			} else {
				$('container').getElement('.strip ul').setStyle('padding-left', 0);
			}
			
		};
	
	};
	
	// js to run on content
	jsOnContent = function(el){
	
	};
	
	// store last hash
	lastHash = [];
	
	// page change handler
	changePage = function(hash){
	
		// replace !/ from start
		hash = hash.replace('!/', '');
		
		// full screen
		if (hash.indexOf('fullscreen/') != -1){
			if (!$('container').hasClass('fullscreen')){
				toFullScreen();
				changePage.delay(2000, this, hash);
				return;
			}
			hash = hash.replace('fullscreen/', '');
		} else {
			if ($('container').hasClass('fullscreen')){
				fromFullScreen();
			}
		}
		
		// add to last hash
		lastHash.push(hash);
		
		// initial animation
		if (!$('container').hasClass('fullscreen') && parseInt($('container').getElement('.top').getStyle('height')) < 1){
			animateTopIn();
		}
		
		// hash to array
		hashArray = hash.split('/');
		
		// set up initial link - should only do this if not another section
		if (hashArray.length > 0){
								
			$('container').getElements('.top ul a').each(function(a){
												
				if (('/' + a.getProperty('href')).indexOf('/' + hashArray[0] + (hashArray.length > 1 ? '/' : '')) != -1){
					$('container').getElements('.top li.selected').each(function(e){
						if (e != a.getParent('li')) e.removeClass('selected').fireEvent('mouseleave');
					});
					a.getParent('li').addClass('selected').fireEvent('mouseenter');
				}
			
			});
			
		}

		// try to load from cache
		if (c = cache.get(hash)){
			pageLoaderSuccess(c);
		} else {
			pageLoader.setOptions({ 'url': hash + ( hash.indexOf('?') == -1 ? '?' : '&' ) + new Date().getTime() + (lastHash.length > 0 ? '&lh=' + lastHash[lastHash.length - 2] : '') }).send('');
		}
		
	};

	// hover effect on strip nav
	$('container').getElements('.strip .nav')
	.addEvent('mouseenter', function(){
		this.tween('background-color', '#fff');
	})
	.addEvent('mouseleave', function(){
		this.tween('background-color', this.retrieve('bgcolor'));
	})
	.addEvent('click', function(){
	
		// get offset
		var o = $('container').getElement('.strip .line').getScroll().y;
		var f = $('container').getElement('.strip .line').getScrollSize().y;
		var h = 60;//$('container').getElement('.strip .line').getSize().y;
		
		// left or right?
		if (this.hasClass('left')){
			if (o > 0){
				o -= h;
			}
		} else {
			if (o < f-h){
				o +=h;
			}
		}
		
		// set scroll
		$('container').getElement('.strip .line').scrollTo(0, o);
		
	})
	.each(function(el){
		this.store('bgcolor', el.getStyle('background-color'));
	});
	
	// make right left arrows click
	$('container').getElements('.strip .pages a')
	.addEvent('click', function(ev){
		
		if (ev) ev.stop();
		
		var els = $('container').getElements('.strip .line li a');
		var c = parseInt($('container').getElement('.strip .pages .cp').get('html'));
		var t = parseInt($('container').getElement('.strip .pages .tp').get('html'));
		
		if (this.hasClass('right')){
			if (c < t){
				l = 'index.php#!/' + els[c].getProperty('href');
				if ($('container').hasClass('fullscreen')){
					l = l.replace('!/', '!/fullscreen/');
				}
				window.location = l;
			};
		} else if (this.hasClass('left')){
			if (c-1 >= 1){
				l = 'index.php#!/' + els[c-2].getProperty('href');
				if ($('container').hasClass('fullscreen')){
					l = l.replace('!/', '!/fullscreen/');
				}
				window.location = l;
			}
		}
		
	});
	
	// hover effect on gallery links
	$('container').getElements('.gallery li, .top .nav li')
	.addEvent('mouseenter', function(){
		if (NAVANIMATING) return;
		if (!this.hasClass('selected') && !this.getParent('.white')){
			this.tween('border-color', '#aaa');
			this.getElement('a').tween('color', '#aaa');
		} else {
			this.tween('border-color', '#fff');
			this.getElement('a').tween('color', '#fff');
		}
	})
	.addEvent('mouseleave', function(){
		if (NAVANIMATING) return;
		if (!this.hasClass('selected') && !this.getParent('.white')){
			this.tween('border-color', '#666');
			this.getElement('a').tween('color', '#666');
		}
	});
	
	// hijack main links and make them json-ified
	$('container').getElements('.top a')
	.each(function(a){
		if ((a.getProperty('href').indexOf('http://') == -1) && a.getProperty('href').indexOf('#') == -1){
			a.addEvent('click', function(ev){
			
				if (ev) ev.stop();
								
				// hijack link
				location.href = 'index.php#!/' + this.getProperty('href');
				
			});
		}
	});
		
	// initial stuff
	$('container').getElement('.top')
	.setStyles({
		'height': 0,
		'opacity' : 0
	});	
	
	$('container').getElement('.viewer')
	.setStyles({
		'height': 0
	});
	
	// resize main window
	window.addEvent('resize', resizeViewer);
	
	// set up cache
	cache = new Cache();
	
	// set up json request
	pageLoader = new Request.JSON({ url: '/json.php', method: 'get' }).addEvent('success', pageLoaderSuccess).addEvent('failure', pageError);
	
	// add hash change event
	window.addEvent('hashchange', function(hash){
		
		// by default, change location
		if (location.hash == ''){
			window.location = 'index.php#!/index.php';
		}
	
		// native anchor, so scroll to it
		if (nativeAnchor(hash)){
			//alert('scroll to: ' + hash);
		} else {
			changePage(hash);
		}
	
	});
	
	// add touch events
	new MooSwipe($('container').getElement('.viewer'), {
	  	onSwiperight: function(){
	  		$('container').getElement('.strip .pages .arrows .left').fireEvent('click');
    	},
    	onSwipeleft: function(){
	  		$('container').getElement('.strip .pages .arrows .right').fireEvent('click');
		}
	});
	
});

window.addEvent('load', function(){

	window.fireEvent('hashchange', location.hash.replace('#', ''));

});
