
YUI().use("anim", "node-base", "transition", "async-queue", function(Y) {
	// Annimations //
	var testimonial_animation = new Y.Anim ({
		node: '#testimonial_bubble',
		to: { top:-170,
			opacity:0 },
		easing: Y.Easing.easeInStrong,
		duration: 0.5
	});
	var testimonial_reset = new Y.Anim ({
		node: '#testimonial_bubble',
		to: { top:0,
			opacity:1 },
		easing: Y.Easing.easeOutStrong,
		duration: 1
	});
	// Event Functions //
	var on_testimonial = function(e) {
		testimonial_animation.run();
	};
	var on_end = function(e) {
		if ( i==testimonials_count-1 ) {
			i = 0;
		} else {
			i++;
		}
		testimonial_text.setStyle( "top", testimonials[i]["margin-top"] );
		testimonial_text.setStyle( "text-align", testimonials[i]["text-align"] );
		testimonial.setY( [testimonial.getY()+200] );
		if ( testimonials[i]["HIGHLIGHT"]=="ALL" ) {
			testimonial_text.setContent( testimonials[i]["QUOTE"] );
		} else {
			testimonial_text.setContent( testimonials[i]["HIGHLIGHT"] );
		}
		testimonial_text_author.setContent( testimonials[i]["NAME"]+", "+testimonials[i]["LOCATION"] );
		Y.all('.testimonial').setStyle( "opacity", 1 );
		testimonial_reset.run();
	};
	var load_it_up = function() {
		testimonial_text.setStyle( "top", testimonials[i]["margin-top"] );
		testimonial_text.setStyle( "text-align", testimonials[i]["text-align"] );
		testimonial_text_author.setContent( testimonials[i]["NAME"]+", "+testimonials[i]["LOCATION"] );
		if ( testimonials[i]["HIGHLIGHT"]=="ALL" ) {
			testimonial_text.setContent( testimonials[i]["QUOTE"] );
		} else {
			testimonial_text.setContent( testimonials[i]["HIGHLIGHT"] );
		}
	};
	var on_pagination = function(e) {
		e.preventDefault();
		var on = Y.one('.quotepage.on');
		on.hide();
		on.replaceClass( 'quotepage on', 'quotepage off' );
		var target_div = Y.one( '#quotepage'+e.target.getContent() );
		target_div.replaceClass( 'quotepage off', 'quotepage on' );
		target_div.show();
	};
	// Annimation Instantiation //
	var i = 0;
	var testimonial = Y.one('#testimonial_bubble');
	var testimonial_text = Y.one('#testimonial_text');
	var testimonial_text_author = Y.one('#testimonial_text_author');
	var testimonials_count = testimonials.length;
	testimonial_animation.on( 'end', on_end );
	// Pagination //
	Y.one('#pagelinks').delegate('click', on_pagination, 'a');
	// Start the Async Queue //
	var q = new Y.AsyncQueue();
	q.add( {fn: load_it_up()
			},
			{
				fn: on_testimonial,
				timeout: 8000, // this callback will be executed asynchronously
				iterations: 500
			}
		);
	q.run();
});

$(window).load(function(){
	$('ul#trybutton').imgbubbles({factor:1.12}); //add bubbles effect to UL id="squares"
	$('ul#buybutton').imgbubbles({factor:1.12}); //add bubbles effect to UL id="squares"
	$('ul#buybutton-2').imgbubbles({factor:1.12}); //add bubbles effect to UL id="squares"
});
