/*
 * Tayside Children with Cancer and Leukaemia
 * Custom functions and actions
 * 
 * @author Paul Cosgrove
 */

/** Things to do once the document has finished loading */
$(document).ready(function(){
	
	//Event handlers for newsletter field
	if ($('#field-newsletter-email').length>0) {
		$('#field-newsletter-email').bind({
			focus: function(){
				if (this.value == this.defaultValue){
					this.value = '';
				}
			},
			blur: function(){
				if (this.value == ''){
					this.value = this.defaultValue;
				}
			}
		});
	}
	
	//Newsletter form validation
	if ($('#newsletterForm').length>0) {
		$('#newsletterForm').validate({
			rules: {
				'newsletter-email': { email: true } //This field is required, and will be checked for valid email address syntax
			},
			messages: {
				//turn off error messages in the markup, to prevent layout problems
				'newsletter-email': { required: '', email: '' }
			},
			invalidHandler: function(form, validator){
				//Display a popup if the email address is not valid
				alert("You did not provide a valid email address");
			}
		});
	}
	
	//Start Shadowbox
	Shadowbox.init({
		continuous: true
	});
	
	if ($('#menu').length>0) {
		$('#menu').addClass('letterspacing');
		//Replace the required sections of the page with Cufon fonts
		Cufon.replace('#menu')('#title')('h2')('.progress-donate');
		//Intialise Cufon
		Cufon.now();
	}
	
	//Homepage News Slide
	if ($('.news-teaser').length>0)
	{
		$('.news').cycle({
			slideExpr: '.news-teaser',
			fx: 'scrollUp'
		});
	}
	
	Cufon.replace('.progress-donate');
	
	
});

