// Grad2007 Javascript functions

if(window.addEventListener) {
	window.addEventListener('load', initSite, false); // W3C DOM
} else if(window.attachEvent) {
	window.attachEvent('onload', initSite);
}

function initSite() {
	// Add rollover effects to main nav buttons
	//navRollovers();
}	

// -------------------------------------------------------------------------------------
// Add rollover effects to Main Nav buttons
// -------------------------------------------------------------------------------------
function navRollovers() {
	$$('.nav').addEvent('mouseover', 
		function() {
			this.effect('opacity', {duration: 300, wait: true}).custom(1, .8);
		})
		.addEvent('mouseout', function() {					
			this.effect('opacity', {duration: 800, wait: true}).custom(.8, 1);
		});	
}
 

// -------------------------------------------------------------------------------------
// Create the animated testimonials and GradFacts
// -------------------------------------------------------------------------------------
function testimonials() {
	// function called from embedded script in column-l template
	// show the testimonial every 15 seconds
	var testimonialIntervalId = setInterval(getTestimonial, 15000);
	// stop showing testimonials after 10 minutes
	var testimonialTimeout = setTimeout(function() {clearInterval(testimonialIntervalId);}, 600000);

}


function promos() {
	// function called from embedded script in column-l template
	// show the testimonial every 15 seconds
	var promoIntervalId = setInterval(getPromo, 10000);
	// stop showing banners after 5 minutes
	var promoTimeout = setTimeout(function() {clearInterval(promoIntervalId);}, 300000);
	getPromo();
}

// -------------------------------------------------------------------------------------
// Ajax/Fading callback function, suggested by Chris on the Mootools forums.
//http://forum.mootools.net/topic.php?id=189#post-976
// -------------------------------------------------------------------------------------

function getTestimonial() {
	var randNum = Math.random();
	var el = $('testimonial');
	var myFader = el.effect('opacity', {duration: 500});

	myFader.chain(function() {
		var myAjax = new Ajax ('/services.php?p=testimonial&rand=' + randNum, {
			method: 'get',
			onComplete: myFader.custom.pass([0,1], myFader),
			update: el
		}).request();
	}).custom(1,0);
}


function getPromo() {
	var randNum = Math.random();
	var el = $('promo');
	var myFader = el.effect('opacity', {duration: 200});

	myFader.chain(function() {
		var myAjax = new Ajax ('/services.php?p=promo&rand=' + randNum, {
			method: 'get',
			onComplete: myFader.custom.pass([0,1], myFader),
			update: el
		}).request();
	}).custom(1,0);
}

// -----------------------------------------------------------------------------	
// Helper function to echo debug info.
// -----------------------------------------------------------------------------

// a little utility function 
function d(txt) {
	if(!$('debug')) {
		var myDebug = new Element('div');
		myDebug.setProperty('id', 'debug');
		myDebug.injectAfter($('enclosing-element'));
	}
	var line = new Element('div');
	line.setProperty('className', 'notice');
	line.injectInside($('debug'));
	line.setHTML(txt);
}

