// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

$(document).ready(function () {
	// Add browser/platform ID class to facilitate cross-browser hacks
	$('body').addClass(BrowserDetect.browser + BrowserDetect.version + " " + BrowserDetect.OS)
	
	// Start testimonial animation
	setupTestimonials();
	
	$.localScroll();
});


//-=-=-=-=-=-=-=-=-=-= Testimonial animation =-=-=-=-=-=-=-=-=-=-=-=-=- */
function setupTestimonials() {  
//	$('#testimonials .testimony').cycle({
//	    fx:         'fade',
//	    speed:      1000,
//	    timeout:    6000
//	});
  $('.testimonies').newsticker(8000);
}


function validateMessageForm (f) {
	var toValidate = getElementsByClass('required_field', f);
	var valid = true;
	
	for (var i = 0; i < toValidate.length; i++) {		
		if(toValidate[i].className.indexOf("comboBox") != -1) {
			if(toValidate[i].selectedIndex == 0 || toValidate[i].selectedIndex == 1) {
				valid = false;
			}
		}
		else if(toValidate[i].className.indexOf("checkbox") != -1) {
			if(toValidate[i].checked != true) {
				valid = false;
			}
		}
		else {
			if(toValidate[i].value == null || toValidate[i].value == '') {			
				valid = false;	
			}
		}
	}
	
	if(!valid) {
		alert("You have not entered information in all the required fields.\nPlease enter any missing information and try again.");
	}
	
	return valid;
}


// Library functions
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
