/* Element JavaScript */

window.addEvent('domready', function() {
		
	// Smooth Scroll page links
	var mySmoothScroll = new SmoothScroll();
	
	
	// Open External Links in a new window
	externalLinks = function() {
		var allAnchors = $(document.body).getElements('a');
		for (var i=0; i<allAnchors.length; i++) {
			var myCurrentAnchor = allAnchors[i];
			if (myCurrentAnchor.get('href') && myCurrentAnchor.get('rel') == "externalLink") {
				myCurrentAnchor.target = "_blank";
			}
		}
	}
	externalLinks();
	
	
	
	// Validate the subscribe form fields before submitting
	
	if ($('subscribeForm')) {
	
		checkSubscribeForm = function() {
		
			var original = $('name').value;
			var o_split = original.split(" ");
			//this probably isn't a complete list of words that shouldn't be capitalized
			var special_words = new Array('and', 'the', 'to', 'for', 'is', 'in', 'a', 'at', 'an', 'from', 'by', 'if', 'of');
		
			if ($('name').value ==""){
				alert("Please provide your name.");
				$('name').focus();
				return false;
			}
			
			if ($('name').value !==""){
				for (i=0;i<o_split.length;i++) {
					if (i == 0) {
						//always capitalize the first word
						o_split[i] = (o_split[i].substring(0,1)).toUpperCase() + o_split[i].substring(1);
					}
					else if(special_words.indexOf(o_split[i]) < 0) { 
					  	o_split[i] = (o_split[i].substring(0,1)).toUpperCase() + o_split[i].substring(1);
					}
				}
				retval = o_split.join(' ');
				$('name').value = retval;
			}
		
			if ($('email').value ==""){
				alert("Please enter your email address.");
				$('email').focus();
				return false;
			}
		
		
			if ($('email').value !=""){
				var x = $('email').value;
				var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if (!filter.test(x)) {
					alert("Oops, looks like there's a problem with your email address.");
					$('email').focus();
					return false;
				}
			}
			
			if ($('companyName'))
			{
				if ($('companyName').value ==""){
					alert("Please provide the name of the company you work for.");
					$('companyName').focus();
					return false;
				}
			}
			
			return (true);
		
		} // End checkSubscribeForm
	
	} // End if subscribeForm
	
	// Rotate images with rotater.js
	if ($('rotatorContainer')) {
		var rotater = new Rotater('.rotateThis',{ 	//Class of elements that should rotate.
			slideInterval:6000, 					//Length of showing each element, in milliseconds
			transitionDuration:1500 				//Length crossfading transition, in milliseconds
		});
	}
	


	
}); // Close DomReady function




	
	




