function init(){
	var anchor			= (window.location.href.indexOf('#') != -1) ? window.location.href.split('#').pop() : null;
	content				= $('aaron-content-container');
	bottom				= $('aaron-bottom-container');
	var contents		= $$('.content');
	var bottoms			= $$('.bottom').reverse();
	for (var b = 0; b < bottoms.length; ++b) {
		bottoms[b].setStyle({'marginLeft': (b * 100) + '%'}).down('img').setStyle({'marginLeft':(100 * Math.random() - 50) + '%'});
	}
	bottom.current		= bottoms.length - 1;
	bottom.setStyle({'marginLeft': (- bottom.current * 100) + '%'});
	
	content.current		= anchor ? contents.indexOf($(anchor)) : 0;
	content.ancestors().each(function(a) { a.scrollLeft = 0; });
	content.setStyle({'marginLeft': -(content.current * 100) + '%'});
	
	links				= $$('.subnavi');
	for (var l = 0; l < links.length; ++l) {
		var id					= links[l].getAttribute('href').split('#').pop();
		anchor ? links[l][(anchor == id) ? 'addClassName' : 'removeClassName']('active') : null;
		links[l].onclick		= pan;
		links[l].cindex			= contents.indexOf($(id));
		links[l].bindex			= bottoms.indexOf($(id + '-image'));
		id						= id.split('-');
		id.pop();
		links[l].page			= id.join('-');
	}
	
	$$('a.aaron-browser').each(function(a) {
		var id					= a.getAttribute('href').split('#').pop();
		a.onclick				= pan;
		a.cindex				= contents.indexOf($(id));
		a.bindex				= bottoms.indexOf($(id + '-image'));
		id						= id.split('-');
		id.pop();
		a.page					= id.join('-');
	});
	
	$$('a.aaron-browser-internal').each(function(a){
		a.onclick				= overlay;
	});
	
	body						= $$('body')[0];
}

function pan() {
	this.blur();
	content.current		= this.cindex;
	content.morph('margin-left:-' + (content.current * 100) + '%', {'duration': trans, 'transition': Effect.Transitions.spring});
	bottom.current		= this.bindex;
	(bottom.current >= 0) ? bottom.morph('margin-left:-' + (bottom.current * 100) + '%', {'duration': trans, 'transition': Effect.Transitions.spring}) : null;
	links.each(function(link){
		link[(link.page === this.page) ? 'addClassName' : 'removeClassName']('active');
	}, this);
	return false;
}

function overlay() {
	if (!blend) {
		blend					= body.appendChild(new Element('div', {'id': 'main'})).hide();
	}
	if (!ol) {
		ol						= body.appendChild(new Element('div', {'id': 'overlay'}));
	}
	ol.hide();
	blend.appear({'duration': 0.3, 'to': 0.6});
	var params = {
		url: this.href,
		method: 'get',
		adParams: '',
		type: 667,
		extract: '',
		extractById: '',
		container:ol,
		callback: display
	}
	alAjaxRequest(params);
	return false;
}

function display(params) {
	ol.hide().update(params.res.result);
	ol[ol.down('div#mediaspace') ? 'addClassName' : 'removeClassName']('video');
	ol.appear({'duration': 0.3});
	ol.select('a.aaron-browser-close').each(function(a){
		a.removeClassName('hidden');
		a.onclick				= function(){
			ol.fade({'duration': 0.3, 'afterFinish': function() { this.update().hide(); }.bind(ol)});
			blend.fade({'duration': 0.3, 'from': 0.8});
			return false;
		}
	})
}

var content = null, bottom = null, links = null, trans = 0.5, blend = null, ol = null, body = null;
document.observe('dom:loaded', init);