/*!
#######################################################################
# 
# !newzevents
# JavaScript setup routines
#
# Hand-crafted by Phenotype (phenotype.net)
#
#######################################################################
*/
	
	////////////////////////////////////////////////////////////////////
	//	Initialise setup routines
	////////////////////////////////////////////////////////////////////
	
		// Called when DOM is ready
		$(document).ready( domSetup );
		
		// Called when entire page is loaded
		$(window).load( pageSetup );
		
		// Called when DOM is unloaded
		$(window).unload( domUnload );
	
	////////////////////////////////////////////////////////////////////
	//	Global variables
	////////////////////////////////////////////////////////////////////
	
		// Set site root
		var siteRoot = '/suki/newzevents/';
		//var siteRoot = '/';
			
	////////////////////////////////////////////////////////////////////
	//	Define setup routines
	////////////////////////////////////////////////////////////////////
	
	/* 
	domSetup()
	
	All JavaScript requiring initialisation on DOM LOAD should be called
	from this routine.
	-----------------------------------------------------------------------
	*/
	
	function domSetup() {

		////////////////////////////////////////////////////////////////////
		//	Enhancements
		////////////////////////////////////////////////////////////////////
		
			// Set JS enabled flag for CSS
			$('html').addClass('js-enabled');
			
			// Hide elements for animation
			$('#page-background img, #content, #header h3 a, #navigation ul.menu').hide();
			
			// Position content area for animation
			$('#content').css({'right' : '-520px'});
			
			// Position logo for animation
			$('#header h3 a').css({'top' : '-500px'});
			
			// Position navigation for animation
			$('#navigation ul.menu').css({'top' : '-500px'});

			// Add spans for colour-coding
			$('#navigation ul.menu ul a, #content h1.entry-title, #content h2').append( '<span />' );
		
		////////////////////////////////////////////////////////////////////
		//	/Enhancements
		////////////////////////////////////////////////////////////////////

		////////////////////////////////////////////////////////////////////
		//	Navigation
		////////////////////////////////////////////////////////////////////
			
			/*
			Setup external links (target attribute not allowed by XHTML 1.1)
			(see http://www.sitepoint.com/article/standards-compliant-world/)
			*/
			$('a[rel="external"]').attr('target','blank');
		
		////////////////////////////////////////////////////////////////////
		//	/Navigation
		////////////////////////////////////////////////////////////////////
		
		////////////////////////////////////////////////////////////////////
		//	Images
		////////////////////////////////////////////////////////////////////

			// Add relationships to create galleries
			$('img.size-thumbnail').parent('a').attr('rel', 'gallery')
			// Colorbox image viewer
			.colorbox({
				maxWidth: '960px',
				maxHeight: '600px',
				opacity: '0.8',
				rel: 'gallery',
				current: '',
				title: function() {
					var img = $(this).find('img');
					var title =  ( img.attr('title') ) ? img.attr('title') : img.attr('alt');
					
					return title;
				}
			});
	
		////////////////////////////////////////////////////////////////////
		//	/Images
		////////////////////////////////////////////////////////////////////

	} // End domSetup()
	
	/* 
	pageSetup()
	
	All JavaScript requiring initialisation on PAGE LOAD should be called
	from this routine (all images and elements should be loaded and ready to
	manipulate by this point)
	-----------------------------------------------------------------------
	*/
	
	function pageSetup() {
			
		////////////////////////////////////////////////////////////////////
		//	Animations
		////////////////////////////////////////////////////////////////////
			
			// Resize and fade in page background
			$('#page-background img')
			.delay( 1000 )
			.fullbleed( {
				minSize: 0.5
			} )
			.fadeIn( 1000, 'easeOutSine', function() {

				$('#content').show().delay( 800 ).animate( { 'right' : '0' }, 800, 'easeOutExpo' );
				$('#header h3 a').show().delay( 800 ).animate( { 'top' : '0' }, 800, 'easeOutExpo' );
				$('#navigation ul.menu').show().delay( 800 ).animate( { 'top' : '80px' }, 800, 'easeOutExpo' );
			} );
		
		////////////////////////////////////////////////////////////////////
		//	/Animations
		////////////////////////////////////////////////////////////////////


	} // End pageSetup()
	
	/* 
	domUnload()
	
	Called when page/DOM is unloaded
	-----------------------------------------------------------------------
	*/
	
	function domUnload() {

	} // End domUnload()
