/*!
 #####################################################################
 # 
 # Phenotype HTML5 Boilerplate Template
 # JavaScript setup routines
 #
 # Hand-crafted by Phenotype (phenotype.net)
 #
 #####################################################################
 */
	
	/* =Assign 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
	------------------------------------------------------------------- */
	
	
	/* =Declare setup routines
	------------------------------------------------------------------- */
	
	/**
	 * domSetup()
	 *
	 * All JavaScript requiring initialisation on DOM LOAD should be called
	 * from this routine.
	 */
	function domSetup() {

		/* =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');
			
			
			$("a[rel='ga']").ga_track();
			
		/* =Forms
		------------------------------------------------------------------- */
		
			/**
			 * Form element enhancements
			 */
			
			// Replace submit buttons
			$('input[type=submit]').each( function() {
				// Make reference
				var $this = $(this);
				// Replace with span
				$this.replaceWith( '<span class="' + $this.attr('type') +'" id="' + $this.attr('id') +'" title="'+ $this.attr('value') +'">'+ $this.attr('value') +'</span>' );
				// Bind click event to submit form
				$('span#'+$this.attr('id') ).bind( 'click', function() {
					$(this).parents('form').submit();
				});
			
			});
			
			/**
			 * Only required for IE6 compatibility
			
			// Add classes to represent types
			$('input, button').each( function() {
				// Make reference
				var $this = $(this);
				// Add class	
				$this.addClass( $this.attr('type') );
			}); */
	
	}
	
	/**
	 * 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() {

	
	}
	
	/**
	 * domUnload()
	 *
	 * Called when page/DOM is unloaded
	 */
	function domUnload() {

	}
	
	function fn.ga_track () {    
      this.each(function() { 
        $(this).click(function() {          
          var pageName = $(this).attr('title') ? $(this).attr('title') : $(this).text();          
          _gaq.push(['_trackPageview', "/" + pageName + ".html"]);
          
        }); 
      }); 
 	 };
