/*
 *	Frontpage Slider Functions
 *	This script is used on the frontpage only.
*/


$(document).ready(function(){

	/* ------------------------------------------------------------------------ 
	 Cycle functions
	------------------------------------------------------------------------ */

	var activeIndex = 9999; // counter used
	
	// redefine Cycle's updateActivePagerLink function 
	$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
		if (activeIndex == currSlideIndex) {
			var anchor = $(pager).find('li').filter('li:eq('+currSlideIndex+')').find('a');
			if (anchor.attr('target') == '_blank') {
				window.open(anchor.attr('href'));
			} 
			else {
				location.href = anchor.attr('href');
			}
		}
		$(pager).find('li')
			.filter('li:not('+currSlideIndex+')')
			.animate({height: '41', width: '330', backgroundColor: 'black'},600)
			.removeClass('on')
			.filter('li:eq('+currSlideIndex+')')
			.animate({height: '160', width: '522', backgroundColor: 'blue'},850,'easeOutBack') // Colors allowed here are Blue or Red. Take a look at the file jquery.colors.js for your own color values.
			.addClass('on');
		activeIndex = currSlideIndex;
	};

	// Give extra tease time for slides with class of "delay"
	var animTimeout = 8000;
	var animDelayMultiplier = 2;
	 
	function onBefore(curr,next,opts) {
		if(next.className == 'delay') { 
			opts.timeout = animTimeout * animDelayMultiplier;
		} else if(opts.timeout != animTimeout) {
			opts.timeout = animTimeout;
		}
	}

	$('#slides ul').after('<div id="slidesitems"><ol>').cycle({
		fx: 'fade',
		speed: 1400,
		timeout: animTimeout,
		pager: '#slidesitems ol',
		pagerEvent: 'click',
		pagerAnchorBuilder: function(idx, slide) {
			var $content = $('#slides ul li:eq(' + (idx) + ') div.nav').html();
			return '<li><div class="default">' + $content + '</div><div class="extended">' + $content + '</div></li>';
		},
        before: onBefore
	});
	
	// Pause SLideshow on hover of slide nav
	$('#slidesitems').hover(
		function(){ 
			$('#slides ul').cycle('pause'); 
		}, 
		function(){ 
			$('#slides ul').cycle('resume'); 
		}
	);

	// Set Opacity of slide nav
	$('#slidesitems li').css('opacity','0.90');

	/* ------------------------------------------------------------------------ 
	 End Cycle functions
	------------------------------------------------------------------------ */

});

