/*
 * Homepage
 *
 * Nivo Slider (image slideshow)
 * http://nivo.dev7studios.com
 *
 * BX Slider (content slideshow)
 * http://bxslider.com
 */

$(document).ready(function() {

	/* highlight boxes
	 * loop through the boxes to get the tallest one and set all to that height
	 */
	if ($('#highlights').length) {
		var height = 0;
		$('#highlights .item').each(function() {
			if ($(this).height() > height) {
				height = $(this).height();
			}
		});
		
		// the more links are abs positioned, so grab their bottom margin to add to
		// the height of the boxes
		height = parseInt(height) + parseInt($('#highlights .item a.more').css('bottom').substr(0, 1));
		$('#highlights .item').css('height', height);
	}
	
	/*
	 * Nivo Slider
	 */
	var slider = $('#slider');
  
	if (slider.length) {
		// initialize home feature area
		slider.nivoSlider({
			effect:'fade',
			slices:1,
			animSpeed:500,
			pauseTime:7000,
			directionNav:true,
			directionNavHide:true,
			controlNav:true,
			keyboardNav:true,
			pauseOnHover:true,
			captionOpacity:0.4
		});
		
		// position video controls (position so left edge is against right column)	
		//var margin_left = $('#left').outerWidth() - slider.find('.nivo-caption').outerWidth();
		//slider.find('.nivo-caption').css('margin-left', $('#left').outerWidth() - slider.find('.nivo-caption').outerWidth());
		
		// combine the next/prev arrows with the pager nav
		slider.find('.nivo-controlNav').before('<div class="controls"></div>');
		var controls = slider.find('.controls');
		controls.append('<span class="caption">&nbsp;</span>');
		controls.append($('#slider .nivo-prevNav'));
		controls.append($('#slider .nivo-controlNav'));
		controls.append($('#slider .nivo-nextNav'));
		
		// update caption
		//controls.find('.caption').css('left', margin_left + 7);
		
		/* usually title attributes are used for the caption text, but we're just
		 * going to use static text. but we still want to keep the alt/title
		 * attributes unique to each image */
		//slider.find('.nivo-caption').prepend('<span class="text">Excellence in Evidence Management</span>');
		slider.find('.nivo-caption').prepend('<span class="text">&nbsp;</span>');
		slider.find('.nivo-caption p').remove();
		
		// rounded corners
		//slider.find('.nivo-caption').corner('10px tr');
	}

	/*
	 * BX Slider (http://bxslider.com)
	 */
	var slider = $('#case-studies-slides');
	if (slider.length) {
		slider.bxSlider({
			pause: 9000,
			speed: 1500,
			auto:true,
			autoHover:true,
			pager:true
		});
		
		/* combine the next/prev arrows with the pager nav */
		var pager = $('.bx-pager');
		pager.before('<div class="controls"></div>');
		var controls = $('.bx-wrapper .controls');
		controls.prepend($('.bx-prev'));
		controls.append(pager);
		controls.append($('.bx-next'));
	}
	
	/* if right is shorter than left, set right height to same as left (for css/bg) */
	/*if ($('#right').height() < $('#left').height()) {
		$('#right').height($('#left').height());
	}*/
	
});
