$(document).ready(function(){ 

  // cycle on home page 
  $('.cycle img').each(function(){
  	var cycleWidth = $('.cycle').width();
  	var imageWidth = $(this).width();
	var finalWidth = cycleWidth - imageWidth;
	$(this).css('margin-left', finalWidth / 2);
  });
  $('.cycle').fadeIn(2000).cycle({
        fx:     'fade',
        speed:  'slow',
        timeout: 8000,
        pager:  '#photoNavigation',
		cleartype: true,
		cleartypeNoBg: true,
		pause: true,
		paused: function(cont, opts, byHover) {
			!byHover
		},
		resumed: function(cont, opts, byHover) {
			!byHover
		}
    });

	// Validate and ajax contact form
	$('#contactForm form').validate({
		errorElement:'small',
		rules:{
			name:{required:true},
			email:{required:true, email:true},
			message:{required:true}
			},
		messages:{
			name:{required:'▲ This field is required'},
			email:{required:'▲ This field is required', email:'▲ Your email address is not valid'},
			message:{required:'▲ This field is required'}
		},
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
			target: "#thankYou"
			});
			$("#contactForm form").hide();
			$("#thankYou").show();
		}
	});

	// Archives animation
	$('.trigger').click(function(){
		$(this).next('.hide').toggle();
		$('span',this).text($('span',this).text() == '+' ? '-' : '+');
	});

	// Cover images with blank gif
	$('img').not('#share img').each(function(){
		var blankWrap = '<div class="blankWrap"></div>';
		$(this).wrap(blankWrap);
	});
	
	$('.blankWrap').each(function(){
		$(this).prepend('<div class="blank"></div>');
	});

	// fix caption
	$('.wp-caption').each(function(){
	var image = $(this).find('img').width();
	$(this).css('width', image);
	$('.wp-caption-text',this).css('width', image - 12);
	});
	
	$('.payPal').click(function(){
		$(this).closest('form').submit();
		return false;
	});

});	
