/**
 * Mootools stuff
 */
var Site = {

	/**
	 * Calls whatever functions are required by making sure certain elements exist
	 */
	start: function(){
		
		if ($('givenow')) Site.giveNow();
		
		if ($('testimonials')) Site.testimonialSlideshow();
		
	},

	/**
	 * This handles the springy "Give Now" button in the header
	 */
	giveNow: function(){
		
		var size_closed = 56;
		var size_open = 110;
		
		var gn = $('givenow-a');
		
		var fx = new Fx.Styles(gn, {wait: false, duration: 300, transition: Fx.Transitions.Quad.easeOut});
				
		gn.addEvent('mouseenter', function(){
			fx.start({'width': size_open});
		});
			
		
		gn.addEvent('mouseleave', function(){
			fx.start({'width': size_closed});
		});
		
	},
	
	/**
	 * Sets up the testimonial slideshows on "Opportunities" pages
	 */
	testimonialSlideshow: function(){
		
		new SmoothScroll();
	
		var scroll = new Fx.Scroll('testimonials', {
			wait: false,
			duration: 250,
			offset: {'x': -0, 'y': -0 },
			//transition: Fx.Transitions.Back.easeInOut
			transition: Fx.Transitions.linear
		});
		var pos = 0;
		var frames = $$('#testimonials .frame');
		//var random_frame = Math.floor(Math.random()*frames.length);
		
		scroll.toElement(frames[0].id);
		
		$$('#testimonials-nav .next-frame').each(function(next, i) {
			next.addEvent('click', function(event) {
				event = new Event(event).stop();
				if(pos < frames.length -1) {
					pos++;
					scroll.toElement(frames[pos].id);
				} else {			        
					pos = 0;
					scroll.toElement(frames[pos].id);
				}
			});
		});
		
	}

};

window.addEvent('domready', Site.start);
