/*  
 * Custom modifications for UB - idfive LLC 2010 for ContentFlow, version 1.0.2 
 */
 
// Setup imageFlow utilities namespace
var cfUtils = {};

cfUtils.startSlide = 0;
cfUtils.currentSlide =  0;
cfUtils.captionSelector = '.fbcaption'
cfUtils.headerImgContainer = ".asHeaderImages";

cfUtils.selector = function(index){return cfUtils.headerImgContainer+" > li:eq("+index+")"};
cfUtils.headerSwap = function(item){
	if 	(cfUtils.currentSlide !== item.index) {
		$(cfUtils.selector(cfUtils.currentSlide)).fadeOut(250);
		$(cfUtils.selector(item.index)).stop(true, true).fadeIn(250);
		cfUtils.currentSlide = item.index;
	};
};
cfUtils.clickAction = function() {
	$(".asHeaderGallery:eq("+cfUtils.currentSlide+") a.fbactive:eq(0)").trigger('click');
	return false;
};

var asImageFlow = new ContentFlow("imageFlow", { "reflectionHeight": 0, "startItem":cfUtils.startSlide, "relativeItemPosition":"top center", "onMoveTo": cfUtils.headerSwap, "onclickActiveItem": cfUtils.clickAction  });

$(function(){
//Initialize fancybox for all 'a' with class 'fbactive'

// = function(item) {console.log('clicked thumbnail')};
	$("a.fbactive").fancybox({
			onComplete		:	function() {
								//Setup video.js on only the video tag within the fancybox modal each time fancybox has completed it's setup. This is...suboptimal but it works across all browsers.
								var currentPlayer = $("#fancybox-inner video");
								var myCurrentPlayer = VideoJS.setup(currentPlayer);
							},
			'transitionIn'	: 	'none',	 
			'transitionOut'	:   'none', 
			'titlePosition' :   'inside',
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	true,
			'changeSpeed' 	: 	150,
			'titleFormat'	: 	formatTitle
		});

		function formatTitle(title, currentArray, currentIndex, currentOpts) {
				var currentTitle = ( this.orig.siblings(cfUtils.captionSelector).html() );
				return currentTitle;
		}
		//ContentFlow removes and creates the caption for the current slide as you flip to it, so we use .live() to essentially rebind these actions everytime we flip to a new thumb.
	$("#imageFlow").delegate(".button", "click", function(ev) {
			$(".asHeaderGallery:eq("+cfUtils.currentSlide+") a.fbactive:eq(0)").trigger('click');
	});

	$(cfUtils.headerImgContainer+" li:gt("+cfUtils.startSlide+")").each(function(){
	  $(this).css("display","none");
	});

});

