/*
****************************************************
	Give a Kid a Chance
----------------------------------------------------
	jquery.functions
	Updated:	11/11/10
****************************************************
*/

$(document).ready(function () {

	/* Add class to last element ---------------- */
	$('.blog-list ul li:last-child').addClass('last');
	$('.donation .column p:last-child').addClass('last');
	$('ul#locations li:last-child').addClass('last');
	$('#volunteerform div.field:nth-child(4)').addClass('last');
	$('div.supporters ul:nth-child(3)').addClass('first');
	$('div.supporters ul li:nth-child(3)').addClass('last');
	$('div.supporters ul li:nth-child(6)').addClass('last');
	$('div.supporters ul li:nth-child(9)').addClass('last');
	$('div.supporters ul li:nth-child(12)').addClass('last');
	$('div.supporters ul li:nth-child(15)').addClass('last');
	$('div.supporters ul li:nth-child(18)').addClass('last');
	$('div.supporters ul li:nth-child(21)').addClass('last');
	$('div.supporters ul li:nth-child(24)').addClass('last');
	$('div.supporters ul li:nth-child(27)').addClass('last');
	$('div.supporters ul li:nth-child(30)').addClass('last');
	$('div.supporters ul li:nth-child(33)').addClass('last');
	$('div.supporters ul li:nth-child(36)').addClass('last');
	$('div.supporters ul li:nth-child(39)').addClass('last');
	$('div.supporters ul li:nth-child(42)').addClass('last');
	$('div.supporters ul li:nth-child(45)').addClass('last');
	$('div.supporters ul li:nth-child(48)').addClass('last');
	$('div.supporters ul li:nth-child(51)').addClass('last');
	$('div.supporters ul li:nth-child(54)').addClass('last');
	$('div.supporters ul li:nth-child(57)').addClass('last');
	$('div.supporters ul li:nth-child(60)').addClass('last');
	$('div.supporters ul li:nth-child(63)').addClass('last');

	/* Validate requestform --------------------- */
	$('#contactform,#volunteerform').validate({
		invalidHandler: function (e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1 ? 'You missed 1 field, which is highlighted above' : 'You missed ' + errors + ' fields, which have been highlighted above';
				$('div.error span').html(message);
				$('div.error').show();
				$('span.error').show();
			} else {
				$('div.error').hide();
				$('span.error').hide();
			}
		}
	});

	/* Index Panel Fade ------------------------- */
	$('#fade').cycle({
		fx: 'fade',
		timeout: 6000
	});

	/* External Links --------------------------- */
	$('.supporters .list a').attr('rel', 'external');

	$('a[rel*=external]').click(function() {
		window.open(this.href);
		return false;
	});

	/* Blog Gallery ----------------------------- */
	$('.blog .thumbs li a').fancybox({
		'transitionIn': 'fade',
		'transitionOut': 'fade'
	});
	
	/* Footer RSS ------------------------------- */
	$('h6.rss a').fancybox({
		'transitionIn': 'fade',
		'transitionOut': 'fade'
	});

	/* Video Player ----------------------------- */
	$('#videoplay a').fancybox({
		'transitionIn': 'fade',
		'transitionOut': 'fade'
	});

/* End jquery.function -------------------------- */
});
