
var timeOut = 4000;

function onAfter() {
	 
	 var currentText = $(this).children('span').first().text();
	 
	 $(this).children('span').first().slideDown( (timeOut/6), function() {
	 	$('#sliderContent > span').each( function(i) {
		    if( $(this).text() != currentText ) {
		    	$(this).hide();
		    }
		 });
	 });
}

function onBefore() {
 	
 	var currentIndex = $('li').index( $(this) );
	 
 	$('#sliderContent span').each( function(i) {
 	 	
	    if( currentIndex != i ) {
	    	$('#slider-' + (i + 1)).removeClass('current');
	    } else {
	    	$('#slider-' + (i + 1)).addClass('current');
	    }
	 });
}

$(document).ready(function() {
	
	var bc = $('#buttonContainer'); 
	
	var $container = $('#sliderContent').cycle({
		fx: 'fade',
    	before: onBefore, 
    	after: onAfter ,
    	pause: 1
	});
	
	$('.sliderImage').each(function(i) { 
	
	    // create input 
	    $('<div id="slider-'+(i+1)+'" ></div>') 
	        // append it to button container 
	        .appendTo(bc) 
	        // bind click handler 
	        .click(function() { 
	            // cycle to the corresponding slide 
	            
		        $container.cycle(i); 
		        	
	            return false; 
	        }); 
	});
	$('#slider-1').addClass('current');
	
	//pause
	$('#pause-rotator').click( function(e) {
	     e.preventDefault()

		 $('#sliderContent').cycle('toggle'); 
		 $('#pause-rotator').toggleClass('play');
		 //$('#testGo, #buttonContainer').fadeOut();
		 //$('.testLeft, .testRight, #testBack, .testMore').fadeIn();
	});

	
	//set up testimonials
	//$('.sliderTestimonial:first').show();
	
	//enter testimonials
	/*$('#testGo').click( function(e) {
	     e.preventDefault()

		 $('#sliderContent').cycle('pause'); 
		 $('#testGo, #buttonContainer').fadeOut();
		 $('.testLeft, .testRight, #testBack, .testMore').fadeIn();
	});
	//flip through testimonials
	$('.testLeft, .testRight').click(function(e){
		e.preventDefault()
		
		var currentTest = $('.sliderTestimonials ul li:visible');
		
		if( $(this).attr('class') == 'testLeft') {
			if( $(currentTest).prev().length )
				$(currentTest).prev().fadeIn();
			else 
				$('.sliderTestimonials ul li:last').fadeIn();
		} else {
			if( $(currentTest).next().length )
				$(currentTest).next().fadeIn();
			else 
				$('.sliderTestimonials ul li:first').fadeIn();			
		}
		$(currentTest).fadeOut();
	});
	//exit testimonials
	$('#testBack').click(function(e){
		 e.preventDefault()
			
		 $('#sliderContent').cycle('resume'); 
		 $('.testLeft, .testRight, #testBack, .testMore').fadeOut();
		 $('#testGo, #buttonContainer').fadeIn();
	});*/
	
});

