/* global.js */


/* initial actions */
window.addEvent('domready', function() {
	
	// large video
	$$('a.video').addEvent('click', function(e) {
		if (e) e.stop();
		openVideo(this.get('rel'));
	});
	
	// email links
	$$('a.email').addEvent('click', function(e) {
		e.stop();
		noSpam(this.innerHTML);
	});
	
	// placeholder inputs
	$$('input.placeholder').each(function(el) {
		el.set('value', el.get('rel'));
	});
	$$('input.placeholder').addEvent('focus', function() {
		placeholderFocus(this);
	});
	$$('input.placeholder').addEvent('blur', function() {
		placeholderBlur(this);
	});
	
	// giving links
	$$('a.giving-amount').addEvent('click', function(e) {
		e.stop();
		setGivingAmount(this.rel);
	});
	
	// copyable input
	$$('input.copy').addEvent('click', function() {
		this.focus();
		this.select();
	});
	
});
window.addEvent('load', function() {
	$('vision-video').fireEvent('click');
});


/* no spam */
function noSpam(string) {
	window.location = 'mailto:'+string.split(' [at] ').join('@');
}


/* set default values */
function placeholderFocus(el) {
	if (el.get('value') == el.get('rel')) {
		el.set('value', '');
	}
}
function placeholderBlur(el) {
	if (el.get('value') == '') {
		el.set('value', el.get('rel'));
	}
}

/* set giving amount */
function setGivingAmount(amt) {
	$('giving-amount').set('value', amt);
}


/* video */
function openVideo(id) {
	var blanket = $('blanket');
	var video = $('video-'+id);
	blanket.setStyle('display', 'block');
	blanket.addEvent('click', function(e) {
		closeVideo(this);
	}.bind(id));
	video.setStyle('display', 'block');
	$$('body').setStyle('overflow', 'hidden');
}
function closeVideo(id) {
	var blanket = $('blanket');
	var video = $('video-'+id);
	blanket.removeEvents();
	blanket.setStyle('display', 'none');
	video.setStyle('display', 'none');
	$$('body').setStyle('overflow', 'auto');
}











