jQuery(function(){

	//Homepage slideshow
	
	//Before and after transition functions for type moving and fading
	function onBefore() {
			$('#slideshow h1').animate({
				opacity: 0,
				top: '60px',
			},400, function () {
				//Animation complete	
			});
			$('.slide a').animate({
				opacity: 0,
				right: '0px'
			}, 400, function () {
			//Animation complete	
			});
	}

	function onAfter() {
			$('#slideshow h1').animate({
				opacity: 100,
				top: '40px'
			}, 600, function () {
			//Animation complete	
			});
			$('.slide a').animate({
				opacity: 100,
				right: '12px'
			}, 600, function () {
			//Animation complete	
			});
	}

	//Cycle plugin call for home slideshow
	$('#slideshow').cycle({ 
		//before: onBefore,
		fx:     'uncover', 
		speed:   800, 
		timeout: 8000,
		prev:	 '#prev',
		next:	 '#next'
		//after: onAfter
	});  	
	//make entire div on Our Work page clickable
	$(".grantee").click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
	})
	
	//randomly selects one of three bird images for the individual grantee pages
	var totalNum = 3;
	var rndNum = Math.floor(Math.random() * totalNum);
	$("#granteeBird").html("<img class=\"png\" src=\"/wp-content/themes/woodcock/img/bird-grantee-" + rndNum  + ".png\" />");
	
	//center bottom-row divs in Our Grantees & Collaborators hub grids
		//add a id number to each div
		$('.hub-group .grantee').addClass(function() {
			var divIndex = $(this).index() + 1;
			return "item-" + divIndex;
		});

		//count the total number of divs
		var totalCurrentDivs = $('#current .grantee').length;

		//find the number of divs left remaining divided by 4 (modulus)
		var remainderCurrent = totalCurrentDivs % 4;
		
		//don't center the first row
		if (totalCurrentDivs <= 4) { remainderCurrent = 0; }
		
		//find the item number of the div whose left margin we will change
		var targetCurrentDiv = totalCurrentDivs - remainderCurrent + 1;
		var targetCurrentDivId = "#current .item-" + targetCurrentDiv;
		
		//add proper left margin to center the row based on the remainder
		if (remainderCurrent == 1) { $(targetCurrentDivId).css("margin-left","340px"); }
		if (remainderCurrent == 2) { $(targetCurrentDivId).css("margin-left","226px"); }
		if (remainderCurrent == 3) { $(targetCurrentDivId).css("margin-left","114px"); }


		//count the total number of divs
		var totalPreviousDivs = $('#previous .grantee').length;

		//find the number of divs left remaining divided by 4 (modulus)
		var remainderPrevious = totalPreviousDivs % 4;

		//don't center the first row divs
		if (totalPreviousDivs <= 4) { remainderPrevious = 0; }
		
		//find the item number of the div whose left margin we will change
		var targetPreviousDiv = totalPreviousDivs - remainderPrevious + 1;
		var targetPreviousDivId = "#previous .item-" + targetPreviousDiv;
		
		//add proper left margin to center the row based on the remainder
		if (remainderPrevious == 1) { $(targetPreviousDivId).css("margin-left","340px"); }
		if (remainderPrevious == 2) { $(targetPreviousDivId).css("margin-left","226px"); }
		if (remainderPrevious == 3) { $(targetPreviousDivId).css("margin-left","114px"); }
	
});


Cufon.replace('h1, h2, h4, #mainNav li a, #homeRightBot li a, .page-template-template_about-php h3, .page-template-template_resources-php h3' , 
							{ fontFamily: 'Dante' , hover: true }
							);
Cufon.replace('h5, a.hubButton, a.boardButton, .grantee p, #footer p#illustratedBy, #footer p#siteBy, #footer a, #slideshow .slide a' , 
							{ fontFamily: 'Benton' , hover: true }
							);
Cufon.replace('#homeLeftTop h6' , 
							{ fontFamily: 'Benton' , hover: true, textShadow: '1px 1px rgba(0,0,0,0.5)' }
							);
Cufon.replace('#homeLeftTop h1' , 
							{ fontFamily: 'Dante' , hover: true, textShadow: '2px 2px rgba(0,0,0,0.7)' }
							);

