//++
//	Cufon replacement calls
//++
Cufon.replace('h2, #intro > p, h3, button',{hover:true});


//++
//	external link creator
//++
function makeExternalLink(link) {
	if (link.readAttribute('title')) { if ( link.readAttribute('title').indexOf('(opens in new window)') < 0 ) { link.writeAttribute('title',link.readAttribute('title')+' (opens in new window)'); } }
	link.observe('click', function(e){ e.stop(); window.open(this.readAttribute('href'), 'ge_external_link'); });
}


//++
//	Initialize page on DOM Load
//++
document.observe('dom:loaded',function(){
	
	// swf replacement
	var flashvars = {}; 
	var params = {allowScriptAccess:'always'}; 
	params.bgcolor = '#FFFFFF';
	var attributes = {}; 
	swfobject.embedSWF('http://files.gecompany.com/gecom/campaigns/santasleigh/sleigh.swf', 'flash-container', '480', '550', '9', null, flashvars, params, attributes);
	
	// taf form
	var form = $('form'), validation = new santaTafValidation();
	validation.init(form);
	form.observe('submit',
		function(e){
			e.stop();
			validation.clearErr();
			if ($('statusmsg')) $('statusmsg').remove();
			if (!validation.validate(e)) return;

			form.submit(); // <-- used in place of ajax

			// var img = new Element('img',{src:'assets/images/spinner-on-white.gif'}).setStyle({display:'block'});
			// form.insert({bottom:img});
			// var p = new Element('p',{id:'statusmsg'}).addClassName('error_msg');
			// 
			// var url = form.action+'?'+form.serialize();
			// new Ajax.Request(url,{
			// 	method:'get',
			// 	onSuccess: function(response){
			// 		img.remove();
			// 		if (response.responseText.match(/emailSent=true/)) {
			// 			p.update('Your message has been sent.  Thank you!');
			// 			form.sender_name.value = '';
			// 			form.recipient_mail.value = '';
			// 		} else {
			// 			p.update('An error occurred while trying to send your email.  Please try again later.');
			// 		}
			// 		form.insert({bottom:p});
			// 	},
			// 	onFailure: function(){
			// 		img.remove();
			// 		p.update('An error occurred submitting your request.  Please try again later.');
			// 		form.insert({bottom:p});
			// 	}
			// });
		}
	);

	// lightbox links
	$$('.lightbox').each(function(el){ el.observe("click", function(e) { e.stop(); GE_Lightbox.getInstance().start(this); } ); });
	
	// external links
	$$('a.external').each(function(el){ makeExternalLink(el); });
	
});


function santaTafValidation() { GE_form_validation.call(this); }
santaTafValidation.prototype = new GE_form_validation();
santaTafValidation.prototype.init = function(el) {
	GE_form_validation.prototype.init.call(this, el);
	this.sInvalidForm = "*Please complete the missing fields";
	this.sInvalidName = "*Please enter your name";
	this.sInvalidEmail = "*Please enter a valid email address";
	this.inputName = this.el.down('#sender_name');
	this.inputEmail = this.el.down('#recipient_mail');
};
santaTafValidation.prototype.checkFields = function() {
	if (this.IsWhitespace(this.inputName.getValue())) { this.logErr(this.inputName, $$('label[for=sender_name]')[0], this.sInvalidName); }
	if (this.IsWhitespace(this.inputEmail.getValue()) || !this.CheckEmailAddress(this.inputEmail)) { this.logErr(this.inputEmail, $$('label[for=recipient_mail]')[0], this.sInvalidEmail); }
};
