// This function extends the window object so that it can
// retrieve and return the value of the named GET parameter
// Written by Aaron Gough: http://aarongough.com
window.location.keyValue = function ( keyName ){
	
	if( window.location.href.indexOf('?') == -1) return false;	
	window.location.variablePairs = window.location.href.substr( window.location.href.indexOf('?') + 1).split('&');
	
	// Search for the key that matches the keyName supplied
	for( var x = 0; x < window.location.variablePairs.length; x++ )
	{
		// If we find the key name then we retun the value associated with it
		if( keyName == window.location.variablePairs[x].substr( 0, window.location.variablePairs[x].indexOf('='))) 
		return window.location.variablePairs[x].substr( window.location.variablePairs[x].indexOf('=') + 1);
	};
	
	// If we couldn't find the key in the GET parameters
	// then we return false
	return false;
};









//---------------------------------------------------------
// HEADER ACTIONS
//---------------------------------------------------------
var header = {
	
	init: function(e){
		
		// logo
		$('header a').click(function(event){

			var regExp = new RegExp($.application);
			SWFAddress.setValue($('header a').attr('href').replace(regExp, ""));

			return false;
		});
	}
};
//---------------------------------------------------------






//---------------------------------------------------------
// MENU ACTIONS
//---------------------------------------------------------
/*var menu = {
	
	init: function(e){
		
		// menu
		$('menu li a[target!=_blank]').each(function(index, anchor){

			// content loading (ajax)
			$(anchor).click(function(event){
					
				SWFAddress.setValue($(anchor).attr('href').replace(new RegExp($.application), "/"));
				return false;
			});
		});
		
		
		// hashing is empty, set default value from current location
		if( SWFAddress.getValue() != "/" ) return;
		
		var doc = document.location.href;
		menu.highlight( doc.slice(doc.indexOf($.application), doc.length) );
	},
	
	highlight: function(url){
		
		// deselected all items
		$('menu li.selected').removeClass('selected');
		
		url = url.replace( new RegExp($.application), "").split("/");
		if( url[url.length - 1] == "" ) url.pop();
		
		var i = 1, n = url.length, href;
		for(; i<n; i++)
		{
			href = $.application+url.slice(0, i+1).join('/');
			$('menu li:not(.selected) a[href*='+href+']:first').parent().addClass('selected');
		};
	}
};*/
//---------------------------------------------------------






//---------------------------------------------------------
// NAV ACTIONS
//---------------------------------------------------------
var nav = {
	
	init: function(e){
		
		// language menu highlight
		$('nav a.lang').each(function(index, anchor){

			$(anchor).click(function(event){

				// deep linking is empty, language changing is OK
				if( SWFAddress.getValue() == "/" ) return true;

				var path = SWFAddress.getValue().split("/");
					path.shift();
					path.shift();
					path = path.join("/");

				var language = String($(this).attr('href')).split($.application);
					language.shift();
					language = language.join("/").split("/");
					language = language[0];

				var url = $.application + language + "/" + path;

				document.location = url;
				return false;
			});
			
			if( document.location.href.indexOf( $(anchor).attr('href')) > -1 ) $(anchor).addClass('selected');
		});
		
		// newsletter form
		$('nav form').submit( function( event ) {

			var email = String($('nav form input#email').val()).replace(/^\s+/g,'').replace(/\s+$/g,'');
			if( email == "" ) return false;
			else return true;
			
			/*
			$('nav form input#email').attr('readonly', true);
			$.get($('nav form').attr('action'), {email: email, goto: ""}, function(data){
				
				$('nav form input#email').val( data.response );
				$('nav form input#email').attr('readonly', false);

			}, 'json');
			return false;
			*/
		});
		
		var index = $('body').hasClass('fr') ? 1 : 0 ;
		if( $('nav a.lang.selected').length == 0 ) $('nav a.lang:eq('+index+')').addClass('selected');		
		Cufon.replace('nav a', { fontFamily: 'GothamRoundedBook', hover: true });
		
		// target _blank
		$('nav li#facebook a, nav li#twitter a').click(function(event){

			window.open($(this).attr('href'));
			return false;

		});
				
		// popin
		$('footer a#credits').prettyPopin({width: 320});
	}
};
//---------------------------------------------------------





//---------------------------------------------------------
// SWFAddress ACTIONS
//---------------------------------------------------------
var hashing = {
	
	js: new RegExp("<script?\\w+(?:\\s+(?:src=\"([^\"]*)\")|[^\\s>]+|\\s+)*>","gi"),
	css: /<link[^>]*(href=\"([^\"]*)\")/gi,
	initialized: false,
	
	init: function(e){ SWFAddress.addEventListener( SWFAddressEvent.CHANGE, hashing.change); },
	change: function(e){
		
		//return false;
		if( e.path == "/" && !hashing.initialized ) return;
		hashing.initialized = true;
		
		
		// content clearing
		hashing.clear();
		
		
		// menu refreshing
		var url = SWFAddress.getValue().split('/');
			url.shift();
			
		menu.highlight( url.join('/') );
		
		
		
		if( e.path == "/" )
		{
			var index = document.location.href.indexOf("#");
				url = index > -1 ? document.location.href.slice(0, index) : document.location.href;
		}
		else url = $.application + e.path;
		
		
		// analytics tracking
		_gaq.push(['_trackPageview', url]);
		
		
		// send ajax request to server
		$.post(url, {ajax: true}, hashing.ajax, 'json');
	},
	
	clear: function(){
		
		$(document).trigger('dispose');
		loader.dispose();
		
		$('section').css('visibility', 'hidden');
		preloader.show();
		$('section').html('');
	},
	
	ajax: function(data){
		
		// write title
		if( data.title ) SWFAddress.setTitle(data.title);
			
		// append content
		$('section').append( typeof innerShiv == 'function' ? innerShiv(data.content) : data.content );
		Cufon.refresh('section article h1');
		
		
		if( data.styles ) while( matches = hashing.css.exec( data.styles ) ) loader.add_css(matches[2]);
		if( data.scripts ) while( matches = hashing.js.exec( data.scripts ) ) loader.add_js(matches[1]);
		
		
		// start loader
		if( loader.length() > 0 ) loader.download(hashing.complete);
	},
	
	complete: function(){
		
		$(document).trigger('init');
		
		preloader.hide();
		$('section').css('visibility', 'visible');
	}
};
//---------------------------------------------------------





//---------------------------------------------------------
// JS/CSS Loader
//---------------------------------------------------------
var loader = function(){
	
	var CSS = 'css';
	var JS  = 'js';
	
	
	var _disposed = false;
	var _length = 0;
	var _index = 0;
	var _current;
	var _queue = new Array();
	var _files = new Array();
	var _head  = document.getElementsByTagName('head')[0];
	var __callback;
	var __ie = $.browser.msie;
	
	
	
	// public API
	function add_css(css){ _length = _queue.push({url: css, format: CSS}); };
	function add_js(js){ _length = _queue.push({url: js, format: JS}); };
	
	
	
	function download(callback)
	{
		
		if( callback ) __callback = callback;
		
		if( _length == 0 ){ _callback(); return; };
		_current = _queue[_index];
		
		var file;
		if( _current.format == JS )
		{
			file 					= document.createElement('script');
			file.type 				= 'text/javascript';
			
			if( __ie ) file.onreadystatechange = function(){ if( this.readyState == 'complete' || this.readyState == 'loaded' ) _complete(); };
			else file.onload = _complete;
			
			file.src 				= _current.url;
			
			_files.push( file );
			_head.appendChild(file);
		}
		else if( _current.format == CSS )
		{
			$.get(_current.url, _css_callback, 'text');
		};
	};
	function dispose()
	{
		// remove all scripts and stylesheets who are not framework related
		// that were added to document by CodeIgniter Template Engine		
		if( !_disposed )
		{
			var scripts 	= document.getElementsByTagName('script');
			var stylesheets = document.getElementsByTagName('link');
			var queue		= new Array();
			
			var i = 0;
			var n = scripts.length;
			var file;
			
			for(; i<n; i++)
			{
				file = scripts[i];
				if( file.getAttribute('key') == "static" || file.getAttribute('src').indexOf("chrome-extension://") >= 0 ) continue;
				
				queue.push( file );
			};
			
			i = 0;
			n = stylesheets.length;
			
			for(; i<n; i++)
			{
				file = stylesheets[i];				
				if( file.getAttribute('key') == "static" ) continue;
				
				queue.push( file );
			};
			
			i = 0;
			n = queue.length;
			
			for(; i<n; i++) _head.removeChild( queue.pop() );			
			_disposed = true;
		}
		else // remove dynamically loaded scripts and stylesheets
		{
			while( _length >= 0 )
			{
				var file = _files.pop();
				if( file ) _head.removeChild( file );
				
				_length--;
				
				file = null;
				delete file;
			};
		};
		
		
		
		_index = 0;
		__callback = null;
		_queue = new Array();
		_files = new Array();
	};
	
	
	
	
	function _callback(){ if( __callback ) __callback(); };
	function _complete()
	{
		_index++;
		if( _index == _length ){ _callback(); return; };
		
		download();
	};
	function _css_callback(data)
	{
		var file 		= document.createElement('link');
			file.type 	= 'text/css';
			file.rel 	= 'stylesheet';
			file.rev 	= 'contents';
			file.media 	= 'all';
			file.href 	= _current.url;
		
		_files.push( file );
		_head.appendChild(file);
		
		_complete();
	};
	
	
	
	
	// read-only property
	function length(){ return _length; };
	
	
	
	
	
	return {
		
		add_css: add_css,
		add_js: add_js,
		
		download: download,
		dispose: dispose,
		
		length: length
	};
	
}();
//---------------------------------------------------------






//---------------------------------------------------------
// GALLERY
//---------------------------------------------------------
var gallery = {
	
	/* vars */
	stageWidth: 0,
	numItems: 0,
	contentWidth: 0,
	scrollWidth: 0,
	scrollerWidth: 0,
	current: null,
	
	/* dynamic UI */
	callback: null,
	content: null,
	selection: null,
	
	/* static UI */
	clipping: null,
	details: null,
	nextArrow: null,
	overlay: null,
	previousArrow: null,
	scrubber: null,
	thumbnail: null,
	
	
	init: function(options){
		
		// UI
		$('section').append('<div id="thumbnail"><img width="82" height="120" /></div>');
		$('section div#scroll').append('<div id="clipping" class="css3pie"></div><div id="scrubber"></div>');
		$('section').append('<a href="#" class="hidden" id="previous"></a><a href="#" class="hidden" id="next"></a>');
		$('section').append('<div id="galleryOverlay"></a>');
		$('section').append('<div id="detailsContent"></div>');
		
		// static UI
		gallery.clipping 		= $('section #scroll #clipping');
		gallery.details 		= $('section #detailsContent');
		gallery.nextArrow 		= $('section a#next');
		gallery.overlay 		= $('section #galleryOverlay');
		gallery.previousArrow 	= $('section a#previous');
		gallery.scrubber 		= $('section #scroll #scrubber');
		gallery.thumbnail 		= $('section #thumbnail');
		
		
		
		if( !options ) options = {};
		if( !options.content ) options.content = $('section #content');
		if( !options.selection ) options.selection = $("section #content .gallery");
		if( !options.callback ) options.callback = null;
		
		
		// dynamic UI
		gallery.callback 		= options.callback;
		gallery.content 		= options.content;
		gallery.selection 		= options.selection;
		
		
		// Variables
		gallery.stageWidth   	= $(document).width();
		gallery.numItems     	= gallery.selection.length;
		gallery.contentWidth 	= gallery.numItems * -400 - 400;
		gallery.scrollWidth  	= gallery.contentWidth + gallery.stageWidth;
		gallery.scrollerWidth 	= gallery.stageWidth - 72;
		
		
		
		// auto-width
		gallery.content.width( -gallery.contentWidth );
		
		
		
		
		// items
		$(gallery.selection).each(function(index, el){
			
			var item = $(el);
				item.find('a#details').bind('click', gallery.open);
				item.find('a#close').bind('click', gallery.close);
				item.find('#sharing').bind('mouseenter', gallery._shareOpen)
									 .bind('mouseleave', gallery._shareClose)
									 .bind('click', gallery._stopPropagation);
				
				item.find('#actions a#twitter').bind('click', gallery._blank);
				item.find('#actions a#facebook').bind('click', gallery._blank);
				item.find('#actions a#google').bind('click', gallery._blank);
				item.find('#actions a#mail').bind('click', gallery._blank);
			
			var img = item.find('img');
			var photos = img.attr('rel');
			if( !photos ) return;
			
			item.find('#actions').append('<a href="#" id="slideshow">Play</a>');
			item.find('#actions a#slideshow').bind('click', gallery.togglePlaying);
			
			item.bind('mouseenter', gallery.startSlideShow)
				.bind('mouseleave', gallery.stopSlideShow);
		});
		
		
		// scroll numbers
		$('section div#scroll ol li a').bind('mouseover', gallery._openThumbnail)
									   .bind('mouseout', gallery._closeThumbnail)
									   .bind('click', gallery.scrollTo);		
		
		
		// arrows
		gallery.nextArrow.bind('click', gallery.next);
		gallery.previousArrow.bind('click', gallery.previous);
		
		
		// closing
		gallery.overlay.bind('click', gallery.close);
		gallery.details.bind('click', gallery.close);
		
		
		
		$(window).bind('resize', gallery.resize).trigger('resize');
		$(document).bind('dispose', gallery.dispose);
		
		
		if( !options.param ) return;
		
		var param = window.location.keyValue(options.param);
		if( !param ) return;

		setTimeout(function(){

			$('section div#scroll ol li a[href=#'+param+']').trigger('click');
			setTimeout(function(){ $(gallery.selection).filter('[val='+param+']').addClass('selected').find('#actions a#details').trigger('click'); }, 800);

		}, 400);
	},
	
	
	open: function(e){
		
		gallery.current = $(this);
		
		var item = $(this).parent().parent();
			item.addClass('selected');

		var itemX 		= item.position().left;
		var contentX 	= gallery.content.position().left;
		var offset 		= contentX + itemX;
		var left 		= contentX + 400 - offset;
		var url 		= $(this).attr('href')+'/details';
		

		if( offset >= 400 )
		{
			gallery.details.css('left', offset - 400 +'px');
			gallery.overlay.add(gallery.details).fadeIn(400).addClass('visible');
		}
		else
		{
			gallery.details.css('left', '0px');

			gallery.overlay.fadeIn(400).addClass('visible');
			gallery.content.animate({left: left+'px'}, 400, 'easeInOutExpo', function(){
				gallery.details.fadeIn(400).addClass('visible');
			});
			
			gallery._scroll(left, 400);
		};
		
		// analytics tracking
		_gaq.push(['_trackPageview', url]);
		
		
		$.ajax({cache: true, dataType: 'json', url: url, success: gallery._ajax});
		return false;
	},
	close: function(e){
		
		gallery.details.fadeOut(200, function(){ gallery.details.removeClass('visible'); });
		gallery.overlay.fadeOut(200, function(){

			gallery.overlay.removeClass('visible');
			gallery.details.html('');
			gallery.current.parent().parent().removeClass('selected');
		});

		return false;
	},
	_ajax: function(data){
		
		if( !gallery.callback ) return;
		
		gallery.details.html( gallery.callback( data ) );
		Cufon.replace('section #detailsContent h1', { fontFamily: 'FreightBigProBook' });
	},
	
	
	/* navigation */
	next: function(e){
		
		// cancel if we are animated
		if( $(gallery.content).is(':animated') ) return false;

		var left = gallery.content.position().left - 400;
		if( left < gallery.scrollWidth ) left = gallery.scrollWidth;

		gallery.content.animate({left: left+'px'}, 400, 'easeInOutExpo');
		gallery._scroll(left, 400);

		return false;
	},
	previous: function(e){
		
		// cancel if we are animated
		if( $(gallery.content).is(':animated') ) return false;

		var left = gallery.content.position().left + 400;
		var mod  = left % 400;

		if( mod < 0 ) left -= 400 + mod;
		if( left > 0 ) left = 0;

		gallery.content.animate({left: left+'px'}, 400, 'easeInOutExpo');
		gallery._scroll(left, 400);

		return false;
	},
	
	
	/* sharing */
	_shareOpen: function(e){
		
		$(this).find('a#share').addClass('hover');
		$(this).find('ul').css({display: 'block'});
	},
	_shareClose: function(e){
		
		$(this).find('a#share').removeClass('hover');
		$(this).find('ul').css({display: 'none'});
	},
	
	
	/* browser behavior */
	resize: function(e){
		
		gallery.stageWidth 		= $(document).width();
		gallery.scrollWidth 	= gallery.contentWidth + gallery.stageWidth;
		gallery.scrollerWidth	= gallery.stageWidth - 72;

		var margin  = (gallery.stageWidth - 100) / (gallery.numItems - 1);
		var percent = gallery.content.position().left / gallery.scrollWidth;
		
		if( percent > 1 ) percent = 1; else if( percent < 0 ) percent = 0;
		
		var left = percent * gallery.scrollWidth; 
		
		$('section div#scroll li').css('width', margin+'px');
		$('section div#scroll li:last-child').css('width', 'auto');
		
		gallery.content.css('left', left+'px');
		gallery._scroll(left, 0);
	},
	_scroll: function(destination, speed){
		
		var selectedIndex 		= Math.ceil(destination / -400);
		var item 				= $('section div#scroll ol li:eq('+selectedIndex+')');
		
		if( item.length == 0 ){ gallery.nextArrow.add(gallery.previousArrow).addClass('hidden'); return; };
		
		var sw 					= destination == 0 ? gallery.stageWidth - 400 : gallery.stageWidth;
		var percent 			= destination == 0 ? 0 : ( destination + 400 ) / ( gallery.scrollWidth + 400 );
		var clippingWidth 		= sw / -gallery.contentWidth * gallery.scrollerWidth;
		var clippingLeft 		= percent * (gallery.scrollerWidth - clippingWidth) + 36;
		var max 				= gallery.scrollerWidth - clippingWidth + 36;
		
		if( clippingLeft >= max ){ clippingLeft = max; gallery.nextArrow.addClass('hidden'); }
		else gallery.nextArrow.removeClass('hidden');
		
		if( selectedIndex == 0 ) gallery.previousArrow.addClass('hidden');
		else gallery.previousArrow.removeClass('hidden');
		
		gallery.scrubber.animate({left: item.offset().left+(item.find('a').outerWidth()-36)*0.5+1+'px'}, speed, 'easeInOutExpo');
		gallery.clipping.animate({width: clippingWidth+'px', left: clippingLeft+'px'}, speed, 'easeInOutExpo');
	},
	
	
	/* scroll navigation */
	_openThumbnail: function(e){
		
		var offset = $(document).scrollLeft();
		var top	   = $(document).scrollTop();
		var point  = $(this).parent().offset();
		var href   = $(this).attr('rel');

		gallery.thumbnail.css({display: 'block', top: (point.top-145-top)+'px', left: (point.left-39-offset)+'px'})
						 .animate({top: (point.top-135-top)+'px'}, 600, 'easeOutExpo')
						 .find('img').attr('src', href);
	},
	_closeThumbnail: function(e){ gallery.thumbnail.css({display: 'none'}); },
	scrollTo: function(e){
		
		if( gallery.overlay.hasClass('visible') )
		{
			gallery.details.fadeOut(200, function(){ gallery.details.removeClass('visible'); });
			gallery.overlay.fadeOut(200, function(){

				gallery.overlay.removeClass('visible');
				$(gallery.selection).removeClass('selected');
			});
		};

		var index = $('section div#scroll ol li a').index($(this));
		var left  = index * -400;

		if( left < gallery.scrollWidth ) left = gallery.scrollWidth;

		gallery._scroll( left, 800 );
		gallery.content.animate({left: left+'px'}, 800, 'easeInOutExpo');

		return false;
	},
	
	
	/* slideshow */
	togglePlaying: function(e){
		
		if( $(this).hasClass('paused') )
		{
			$(this).removeClass('paused');
			slideshow.play( $(this).parent().parent() );
		}
		else
		{
			$(this).addClass('paused');
			slideshow.pause();
		};
		
		return false;		
	},
	startSlideShow: function(e){ if( !$(this).find('a#slideshow').hasClass('paused') ) slideshow.play( $(this) ); },
	stopSlideShow: function(e){ slideshow.stop(); },
	
	
	/* utils */
	_stopPropagation: function(e){ return false },
	_blank: function(e){ window.open($(this).attr('href')); return false; },
	
	
	
	/* memory management */
	dispose: function(e){
		
		// items
		$(gallery.selection).each(function(index, el){
			
			var item = $(el);
				item.find('a#details').unbind('click', gallery.open);
				item.find('a#close').unbind('click', gallery.close);
				item.find('#sharing').unbind('mouseenter', gallery._shareOpen)
									 .unbind('mouseleave', gallery._shareClose)
									 .unbind('click', gallery._stopPropagation);
				
				item.find('#actions a#twitter').unbind('click', gallery._blank);
				item.find('#actions a#facebook').unbind('click', gallery._blank);
				item.find('#actions a#google').unbind('click', gallery._blank);
				item.find('#actions a#mail').unbind('click', gallery._blank);
		});
		
		// scroll numbers
		$('section div#scroll ol li a').unbind('mouseover', gallery._openThumbnail)
									   .unbind('mouseout', gallery._closeThumbnail)
									   .unbind('click', gallery.scrollTo);
		
		// arrows
		gallery.nextArrow.unbind('click', gallery.next);
		gallery.previousArrow.unbind('click', gallery.previous);
									
		$(window).unbind('resize', gallery.resize);
		$(document).unbind('dispose', gallery.dispose);
	}
	
};
//---------------------------------------------------------







//---------------------------------------------------------
// PRELOADER
//---------------------------------------------------------
var preloader = {
	
	init: function(e){ $('#wrapper').append('<div id="preloader"></div>'); },
	show: function(){ $('#preloader').css('display', 'block'); },
	hide: function(){ $('#preloader').css('display', 'none'); }
	
}
//---------------------------------------------------------





//---------------------------------------------------------
// PRELOADER
//---------------------------------------------------------
var slideshow = {
	
	PLAYING: "playing",
	PAUSED: "paused",
	STOPPED: "stopped",
	
	element: null,
	timer: null, 
	delay: 1000, 
	pauseDelay: 2000,
	status: null,
	img: null,
	
	animate: function(){
		
		if( slideshow.status != slideshow.PLAYING ) return;
		if( slideshow.timer ) clearInterval( slideshow.timer );
		
		slideshow.img.css('left', '400px');
		slideshow.element.prepend( slideshow.img );
		
		slideshow.element.find('img').animate({left: '-=400'}, 600, 'easeInOutExpo', slideshow.animateComplete);
	},
	
	animateComplete: function(){
		
		if( slideshow.status != slideshow.PLAYING ) return;
		if( slideshow.timer ) clearInterval( slideshow.timer );
		
		slideshow.timer = setInterval( slideshow.next, slideshow.pauseDelay );
	},
	
	next: function(){
		
		if( slideshow.timer ) clearInterval( slideshow.timer );
		slideshow.timer = null;
		
		slideshow.load();		
	},
	
	load: function(){
		
		var img 	= $(slideshow.element).find('img')[0];
		var rel 	= $(img).attr('rel');
		
		var photos 	= rel.split(";");
		var index   = photos.indexOf( $(img).attr('src') );
		var nextSibling = index + 1;
		if( nextSibling == photos.length ) nextSibling = 0;
		
		var url = photos[ nextSibling ];
		
		slideshow.img = $('<img />').bind('load', slideshow.animate)
					 				.attr('rel', rel)
					 				.attr('src', url);
	},
	
	play: function(element){
		
		if( slideshow.element ) slideshow.stop();
		
		slideshow.status 	= slideshow.PLAYING;
		slideshow.element 	= element;
		slideshow.timer 	= setInterval(slideshow.next, slideshow.delay);
	},
	
	pause: function(){
		
		if( slideshow.timer ) clearInterval( slideshow.timer );
		
		slideshow.timer = null;
		slideshow.status = slideshow.PAUSED;
	},
	
	stop: function(){
		
		if( !slideshow.element ) return;
		if( slideshow.timer ) clearInterval( slideshow.timer );
		if( slideshow.img ) slideshow.img.unbind('load');
		
		slideshow.timer 	= null;
		slideshow.element 	= null;
		slideshow.img 		= null;
		slideshow.status 	= slideshow.STOPPED;
	}
}
//---------------------------------------------------------




//---------------------------------------------------------
// Fixing Array.indexOf native method for IE7
//---------------------------------------------------------
if( !Array.prototype.indexOf )
{
	Array.prototype.indexOf = function(obj)
	{
		var i = 0;
		var n = this.length;
		
		for(; i<n; i++) if( this[i] == obj ) return i;		
		return -1;
	};
};
//---------------------------------------------------------





$(document).bind('ready', header.init)
		   .bind('ready', menu.init)
		   .bind('ready', nav.init)
		   .bind('ready', preloader.init)
		   .bind('ready', hashing.init);


