//
// JQUERY
// FILE FOR Virginia Athletics Foundation
// WRITTEN BY:  James Baldys
// DATE:  9-15-2009
//
$(document).ready(function() {
	homepage_cycle();
	give_now_button();
	main_menu_expandable();
	facebook_button();
	generate_anchors();
	swap_image_cols();
	make_flash();
});
// "GIVE NOW" button that is in header of entire site.
function give_now_button() {
	$("a.donate-now").hover(function(){
		$(this).css({backgroundPosition: '0px -80px'});
	},function(){
		$(this).css({backgroundPosition: '0px 0px'});
	});
}
// APPEND "ARROW" to expandable main menu 
// NOTE: This is a "best practice" for UI design
function main_menu_expandable() {
	/* $("li.expandable").each(function(){
		$(this).prepend(								 
	}); */
}
// "FACEBOOK" button that is in footer of entire site.
function facebook_button() {
	$("a.facebook-link").hover(function(){
		$(this).css({backgroundPosition: '0px -15px'});
	},function(){
		$(this).css({backgroundPosition: '0px 0px'});
	});
}
// CYCLE FOR THE HOMEPAGE
function homepage_cycle() {
	var cycle_target = $("div.cycle-target");
	if (cycle_target.length < 1) {
		return;	
	} else {
		cycle_target.cycle({
			fx:           'fade', // name of transition effect (or comma separated names, ex: fade,scrollUp,shuffle) 
			timeout:       8000,  // milliseconds between slide transitions (0 to disable auto advance) 
			continuous:    0,     // true to start next transition immediately after current one completes 
			speed:         2000,  // speed of the transition (any valid fx speed value) 
			speedIn:       null,  // speed of the 'in' transition 
			speedOut:      null,  // speed of the 'out' transition 
			easing:        null,  // easing method for both in and out transitions 
			easeIn:        null,  // easing for "in" transition 
			easeOut:       null,  // easing for "out" transition 
			height:       'auto', // container height 
			sync:          1,     // true if in/out transitions should occur simultaneously 
			random:        0,     // true for random, false for sequence (not applicable to shuffle fx) 
			fit:           0,     // force slides to fit container 
			containerResize: 0,   // resize container to fit largest slide 
			pause:         1,     // true to enable "pause on hover" 
		});
	}
}
// AUTOMATICALLY GENERATE PAGE CONTENT LINKS FROM ANCHORS IN CONTENT
function generate_anchors() {
	$("div.two-thirds-column div.entry a").each(function(){		
		if($(this).attr("href") === undefined) {
			var targetAnchor = $(this).attr("name");
			var linkText = '<li><a href="#'+targetAnchor+'">'+targetAnchor+'</li>';
			$("ul.anchor-menu").append(linkText);
		}
	});
}
// MOVE IMAGES (POSSIBLY MORE CONTENT) FROM RIGHT COLUMN INTO LEFT!
function swap_image_cols(){
	$("div.two-thirds-column div.move-to-left").each(function(){
		var targetContent = $(this).html();
		$(this).addClass("hidden");
		$("div.one-thirds-column").append(targetContent);
	});
	$("div.two-thirds-column img.left-col-image").each(function(){
		var targetContent = $(this);
		$(this).addClass("hidden");
		$("div.one-thirds-column").append(targetContent);
	});
}
// MAKE FLASH

function make_flash() {
	var flashTarget = $("#flash-target");
	if (flashTarget.length > 0) {
		flashTarget.flash(
			  { 
				 src: 'http://www.virginiaathleticsfoundation.com/wp-content/themes/vaf/flash/vaf-video.swf',
				 width: 720,
				 height: 480
			  }
		 );	
	}
}

