(function($){
	window.addEvent('domready',function() {
		//element collection and settings
		var opacity = 0.5, toOpacity = 1;
		var margin = "-122px", toMargin = "-12px"; 

		$$('.formHeader > ul > li').addEvents({
			mouseenter: function() {
				this.tween('opacity',toOpacity);
				this.getChildren('.msgCopy').tween('marginTop',toMargin);
			},
			mouseleave: function() {
				this.tween('opacity',opacity);
				this.getChildren('.msgCopy').tween('marginTop',margin);
			},
			click: function() {
				var imgSrc = this.getChildren('img').getProperty('src').toString();
				var prvImg = imgSrc.replace('_140x120','');
				this.addClass('permOpac');
				$$('#prvImg').setProperty('src',prvImg);
				$$('#cardImg').setProperty('value',prvImg);
				$$('.formHeader > ul > li').tween('opacity',opacity);
				$$('.prvCard').removeClass('hide').tween('opacity',toOpacity);
			}
		});
		
		$$('#prvClose').addEvents({
			click: function() {
				this.getParent('.prvCard').tween('opacity',opacity).addClass('hide');
				$$('#cardImg').setProperty('value','');
				$$('.formHeader > ul > li').removeClass('permOpac');
				}
		});
		$$('#choseCard').addEvents({
			click: function() {
				this.getParent('.prvCard').tween('opacity',opacity).addClass('hide');
				}
		});
		/* rest assured I would not be using default browser alerts unless I had to */
		$$('#sendContactButton').addEvents({
			click: function() {
			if($$('#AuthorEmail').getProperty('value').toString()=='' || $$('#cardImg').getProperty('value').toString()=='' || $$('#fromEmail').getProperty('value').toString()=='' || $$('#AuthorName').getProperty('value').toString()=='' || $$('#toName').getProperty('value').toString()=='') {
			$$('#eErrors').set('text','Looks like you forgot something. Please make sure you picked out a card and filled out all the required fields.').removeClass('hide');
			return false;
			}
			else {
			$$('#eErrors').addClass('hide').set('text','');
			}
			}
			});	
	});
})(document.id);
