function addEvents() {
	window.addEvent('domready',function() {
		new SmoothScroll({duration:1000});
		new gciFormValidation('contact-form'); //form validation

		//Open any anchor with external window in a new browser window
		$$('a.externalwindow').each(function(e){e.setProperty('title',e.title+' - opens in a new browser window');e.addEvent('click',function() {window.open(e.href);return false;});});
		//Index page effects
		if (document.getElementById('index')) {
			//light box for current newsletter
			new pmgLightBox('pmglb',[new Hash({anchor:$('ia'),baseClass:'article',divId:'article-item'})],{getDiv:true,opacity:1});
			//logo line transition
			var myHeader = $('header').getElement('h1 span').setStyle('width',0);
			(function(){new Fx.Tween(myHeader, {property:'width',duration:750,transition:Fx.Transitions.Sine.easeInOut}).start(myHeader.getParent('h1').getSize().x);}).delay(250);			
			//view programs button transition
			var myViewBtn = $('viewbutton').addEvents({'mouseenter':function() {myViewFx.start(myViewBtn.getSize().x);},'mouseleave':function() {myViewFx.start(0);}});
			var myViewFx = new Fx.Tween(createSpan(myViewBtn,'0px -28px'),{property:'width',duration:250,transition:Fx.Transitions.Sine.easeIn});
		}				
		//Contact page effects
		if (document.getElementById('contact')) {
			var myContactSpan = $('submit');
			var myContactBtn = myContactSpan.getElement('button').setStyles({'width':0,'background-position':'-170px -28px'}).addEvents({'click':function(event){event.stopPropagation();},'mousedown':function(){this.blur();this.hideFocus=true;},'mouseup':function(){this.blur();this.hideFocus=false;}});
			myContactSpan.addEvents({'click':function(event){myContactBtn.click();},'mouseenter':function(){myContactFx.start(myContactSpan.getSize().x);},'mouseleave':function(){myContactFx.start(0);}});			
			var myContactFx = new Fx.Tween(myContactBtn,{property:'width',duration:250,transition:Fx.Transitions.Sine.easeIn});
		}
	});
}
function createSpan(e,pos) {return new Element ('span',{'styles':{'position':'absolute','height':e.getSize().y,'width':0,'left':0,'top':0,'background-image':e.getStyle('background-image'),'background-position':pos}}).injectInside(e);};
var gciFormValidation =  new Class({	
	Implements: [Events, Options],	
	options: {fields: ['input', 'textarea']},	
	initialize: function(form, options) {this.setOptions(options);this.submitted = false;if (document.getElementById(form) == null) return;this.form = $(form);this.form.addEvent('submit',this.onSubmit.bind(this));},
	onSubmit: function(event){if (this.submitted) {this.preventDefault(event,true);} else {this.submitted = true;if (!this.checkRequired()) {this.preventDefault(event,false);}if (!this.checkEmail()) {this.preventDefault(event,false);}}},	
	preventDefault:function(event,submitted) {this.submitted = submitted;event.preventDefault();},		
	getFields:function(type) {var myArray = new Array();this.options.fields.each(function(f){myArray.extend($A(this.form.getElements(f+'.'+type)));}.bind(this));return myArray;},		
	checkRequired:function() {var returnValue = true;this.getFields('required').each(function(e){var myError = this.createErrorMsg(e);if (this.isEmpty(e.get('value'))) {this.setErrorMsg(myError,'Required Field');returnValue = false;} else {myError.setStyle('visibility','hidden');}}.bind(this));return returnValue;},	
	checkEmail:function() {var returnValue = true;this.getFields('validate-email').each(function(e){var myError = this.createErrorMsg(e);if (!this.isValidEmail(e.get('value'))) {this.setErrorMsg(myError,'Please enter a valid email address.  For example "jsmith@domain.com"');returnValue = false;} else {myError.setStyle('visibility','hidden');}}.bind(this));return returnValue;},	
	createErrorMsg:function(e){return $(e.get('name')+'-validation-error');},
	setErrorMsg:function(e,message){if (e.getStyle('visibility')=='hidden') {e.set('text',message);e.setStyle('visibility','visible');}},		
	isValidEmail:function(value) {var emailRegEx = /^[A-Z0-9!#$%._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;	value = value.trim();return !this.isEmpty(value) && value.match(emailRegEx)!=null;},			
	isEmpty:function(value) {value = value.trim();return(value == null || value.length == 0);}	
});
var pmgLightBox =  new Class({	
	Implements: [Events, Options],	
	options: {getDiv:false,opacity:1,zindex:9999},	
	initialize: function(baseClass, lbItems, options) {this.setOptions(options);this.content=null;this.wrapper=null;this.index=-1;if (lbItems.length==0) return;this.lbItems=$A(lbItems);if (!this.lbItems.every(function(h,index){if (h.getLength()!=3 || !$defined(h.get('anchor')) || !h.get('anchor').match('a') ) return false;return true;})) return;this.baseClass = baseClass.clean();if (this.baseClass.length == 0) return;this.lbItems.each(function(h,index){h.get('anchor').addEvent('click',this.openLB.pass(index,this));this.createContentWindows(h.get('baseClass'));},this);this.createOverlay();},	
	openLB: function(index){this.index = index;this.wrapper = $(this.baseClass+'-wrapper-'+this.lbItems[index].get('baseClass'));this.content = $(this.baseClass+'-content-'+this.lbItems[index].get('baseClass'));if (!this.content.retrieve('loaded')) this.loadContent();this.overlay.fade(0.7);return false;},
	loadContent: function() {var req = new Request ({url:this.lbItems[this.index].get('anchor').href,method:'get',onSuccess: function(responseText) {var myElement = new Element('div').set('html',responseText);if (this.options.getDiv) {myElement.getElements('div').each(function(e){if (e.get('id') == this.lbItems[this.index].get('divId')) {e.set('id',this.baseClass+'-inner-'+this.lbItems[this.index].get('baseClass'));this.content.adopt(e);this.content.store('loaded',true);return;}},this);} else {myElement.set('id',this.baseClass+'-inner-'+this.lbItems[this.index].get('baseClass'));this.content.adopt(myElement);this.content.store('loaded',true);}this.content.getElements('a.externalwindow').each(function(e){e.setProperty('title',e.title+' - opens in a new browser window');e.addEvent('click',function() {window.open(e.href);return false;});});}.bind(this),onFailure: function() {this.closeLB();}.bind(this)}).send();},
	closeLB: function() {this.index = -1;if ($defined(this.content)) this.content.setStyle('display','none');if ($defined(this.wrapper)) this.wrapper.setStyle('display','none');this.overlay.fade('out');},
	createOverlay: function() {this.overlay = new Element('div',{'id':this.baseClass+'-overlay','styles': {'display':'none','position':'absolute','top':0,'left':0,'height':window.getScrollHeight()+'px','width':window.getScrollWidth()+'px','opacity':0,'zIndex':this.options.zindex},'events': {'click':function() {this.closeLB();}.bind(this)}}).injectInside(document.body);this.overlay.set('tween',{duration:500,link:'cancel',onComplete:function() {if (this.index != -1) this.showContentWindow();}.bind(this),onStart:function() {if (this.index != -1) this.overlay.setStyles({display:'block',opacity:0});}.bind(this)});},		
	createContentWindows: function(className) {if (document.getElementById(this.baseClass+'-wrapper-'+className)) return;var myBox = new Element('div',{'id':this.baseClass+'-content-'+className,'styles': {'position':'absolute','display':'none'}}).store('loaded',false).injectInside(document.body);new Element('a',{'id':'lb-close','class':'small lbmenu','href':'close','text':'Close','events': {'click':function(){this.closeLB();return false;}.bind(this)}}).injectInside(myBox);new Element('a',{'id':'lb-rssemail','class':'small lbmenu','href':'#Feedburner Email Subscription Service','title':'Feedburner Email Subscription Service','text':'Subscribe by Email','events':{'click':function(event) {window.open('http://feedburner.google.com/fb/a/mailverify?uri=PureMindGolfQuarterlyNewsletter&amp;loc=en_US');event.stop();}}}).injectInside(myBox);new Element('a',{'id':'lb-rss','class':'small lbmenu','title':'Feedburner Reader Subscription Service','href':'#Feedburner Reader Subscription Service','rel':'alternate','type':'application/rss+xml','text':'Subscribe in a Reader','events':{'click':function(event) {window.open('http://feeds.feedburner.com/PureMindGolfQuarterlyNewsletter');event.stop();}}}).injectInside(myBox);new Element('div',{'id':this.baseClass+'-wrapper-'+className,'styles': {'position':'absolute','display':'none','overflow':'hidden','zIndex':this.options.zindex+100,'opacity':this.options.opacity}}).wraps(myBox);},	
	showContentWindow: function() {this.wrapper.setStyle('display','block');var scrollx = this.content.getStyle('overflowX');var scrolly = this.content.getStyle('overflowY');this.content.setStyles({display:'block',height:0,overflow:'hidden'});new Fx.Tween(this.content,{property:'height',duration:500,link:'cancel',transition:Fx.Transitions.Expo.easeInOut,onComplete:function() {this.content.setStyles({'overflowX':scrollx,'overflowY':scrolly});}.bind(this)}).start(this.wrapper.getSize().y);}
});


