/*
#####################################################
# 
# Becel
# 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.onload = pageSetup;
	
	// Called when DOM is unloaded
	$(window).unload(domUnload);
	
	////////////////////////////////////////////////////////////////////
	//	Define setup routines
	////////////////////////////////////////////////////////////////////
	
	/* 
	domSetup()
	
	All JavaScripts requiring initialisation on DOM LOAD should be called
	from this routine
	-----------------------------------------------------------------------
	*/
	
	function domSetup() {
		
		////////////////////////////////////////////////////////////////////
		//	Cufon
		////////////////////////////////////////////////////////////////////
		
		Cufon.replace('#navigation ul a', { fontFamily: 'Poplar Std', hover: true });
		Cufon.replace('#content h2', { fontFamily: 'Poplar Std' });
		Cufon.replace('#content h3:not(.related li h3, .competition h3)', { fontFamily: 'Poplar Std', hover: true });
		Cufon.replace('#content h4:not(.related li h4, .competition h4)', { fontFamily: 'Poplar Std', hover: true });
		Cufon.replace('#sub-navigation h3', { fontFamily: 'Poplar Std', hover: true });
		Cufon.replace('a.button', { fontFamily: 'Poplar Std', hover: true });
		Cufon.replace('.form fieldset legend', { fontFamily: 'Poplar Std' });
		
		////////////////////////////////////////////////////////////////////
		//	/Cufon
		////////////////////////////////////////////////////////////////////
		
		////////////////////////////////////////////////////////////////////
		//	Forms
		////////////////////////////////////////////////////////////////////
		
			// Clear default values on focus
			$('input.text, textarea').formclear({
				inactivecolor:'#999',
				activecolor: '#333'
			});
			
			// Form submit buttons
			$('form a.button').bind('click.default', function(){
				// Clear any remaining submitted flags
				$('.submitted').removeClass('submitted');
				// Add submitted flag
				$(this).parents('.form:first').addClass('submitted');
				// Submit the parent form
				$(this).parents('form:first').submit();
				// Show wait cursor
				$('*').css({'cursor' : 'wait'});
				// Don't visit link specified
				return false;
			});

		
		////////////////////////////////////////////////////////////////////
		//	/Forms
		////////////////////////////////////////////////////////////////////
		
		// Recipe print button
		$('.section.recipe-print a').bind('click.default',function(){
			// Print
			window.print();
			// Don't visit link
			return false;
		});
		
		// Setup external links
		externalLinks();
		
	} // End domSetup()
	
	/* 
	pageSetup()
	
	All JavaScripts 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() {
	
	
	} // End pageSetup()
	
	/* 
	domUnload()
	
	Called when page/DOM is unloaded
	-----------------------------------------------------------------------
	*/
	
	function domUnload() {

	} // End domUnload()