
// DOM Ready events
window.addEvent('domready', function() {



	// Creates fade in/out FX for .hover class
	$$('.zoomr').each(function(el) {

		var div = new Element('div', {'id': 'zoomr_holder', 'class' : 'zoomr_hide'}),
		msg = new Element('msg', {'id': 'zoomr_msg', 'padding' : '10px'}),
		overlay = new Element('div', {'id': 'zoomr_overlay', 'class' : 'zoomr_hide'}),
		img = new Element('img', {'id': 'zoomr_img','src': $(el).get('rel') });
	
		overlay.inject(document.id(document.body), 'top');
		div.inject(document.id(document.body), 'top');
		img.inject(div, 'top');
		msg.inject(div, 'top');

		msg.set('html', "Press 'esc' or click anywhere to hide.");

		$(el).addEvent('click', function() {
			console.log($(el).get('src'));
			div.setStyle('display', 'block');
			overlay.setStyle('display', 'block');
			div.fade('in');
			overlay.fade(0.8);
		});
		
		document.body.addEvent('keyup', function(event) {
			if (event.key==='esc') {
				overlay.fade('out');
				div.fade('out');
			}
		});

		div.addEvent('click', function() {
				overlay.fade('out');
				div.fade('out');
		});

		overlay.addEvent('click', function() {
				overlay.fade('out');
				div.fade('out');
		});

	});

	
	// Creates fade in/out FX for .hover class
	$$('.hover').each(function(el) {
		if ($(el.get('id')).get('rel')==null) {
		var out = 0.5;
		} else {
		var out = $(el.get('id')).get('rel');
		}

		$(el).addEvent('mouseover', function() {
			$(el.get('id')).addClass('clickable');
			$(el.get('id')).fade(out);
		});
		
		$(el).addEvent('mouseout', function() {
			$(el.get('id')).tween('width', '100%');
			$(el.get('id')).fade(1);
		});
	});

	// Clear input on focus for .reset class
	$$('.reset').each(function(el) {


		// Erase on focus
		$(el).addEvent('focus', function() {
			var value = $(el).get('value');
			var erase = $(el).get('rel');
			if (value===erase) {
				$(el).value='';
			}
		});

		// Reset on blur
		$(el).addEvent('blur', function() {
			var value = $(el).get('value');
			if (value==='' || value===' ') {$(el).value=$(el).get('rel');}
		});

	});

	// Creates fade FX for links with .fade class
	$$('a.fade').each(function(el) {
		el.addEvent('mouseover', function() {
			if ($(el.get('id')).get('rel')===null) {
				$(el).addClass('fade_green');
			} else {
				$(el).addClass('fade_'+$(el.get('id')).get('rel'));
			}
			el.fade(0.6);
		});
		el.addEvent('mouseout', function() {
			el.fade(1);
		});
	});




	// Preload images with .preload class
	$$('.preload').each(function(el) {
		var src=$(el).src,
		ext = src.substring(src.lastIndexOf('.'),src.length),
		img = new Element('img', { 'id': el+'_tmp', 'align' : 'center', 'class' : 'hide', 'src' : src.replace(ext,'_on' + ext) });
		img.inject($('wrapper'), 'bottom');
		img.destroy();
	});
	
	// Creates image rollovers for .hover class
	$$('.roll').each(function(el) {

		var src=$(el).src,
		ext = src.substring(src.lastIndexOf('.'),src.length),
		img = new Element('img', { 'id': el+'_tmp', 'align' : 'center', 'class' : 'hide', 'src' : src.replace(ext,'_on' + ext) });
		img.inject($('wrapper'), 'bottom');
		img.destroy();

		$(el).addEvent('mouseover', function() {
			var src=$(el).src,
			ext = src.substring(src.lastIndexOf('.'),src.length),
			roll = src.replace(ext,'_on' + ext);
			$(el).src=src.replace(ext,'_on' + ext);
		});
		
		$(el).addEvent('mouseout', function() {
			$(el).src=src;
		});
	});


tinyMCE.init({
mode : "textareas",
theme : "advanced",
editor_selector : "tiny_mce",
skin : "thebigreason",

plugins :"tabfocus,safari,inlinepopups,contextmenu,fullscreen,spellchecker,advimage,paste,preview,print,searchreplace,table",

plugin_insertdate_dateFormat : "%B %d, %Y",
plugin_insertdate_timeFormat : "%I:%M",
tabfocus_elements : "save_btn",

theme_advanced_buttons1 : "fullscreen,|,forecolor,backcolor,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,image,link,unlink,|,bullist,numlist,indent,hr,charmap,|,cleanup,removeformat,|,spellchecker,code,",
theme_advanced_buttons2 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "center",
theme_advanced_resizing : false
});


// Basic MCE
tinyMCE.init({
mode : "textareas",
theme : "advanced",
editor_selector : "tiny_mce_basic",
skin : "thebigreason",

plugins :"tabfocus,safari,inlinepopups,contextmenu,fullscreen,spellchecker,advimage,paste,preview,print,searchreplace,table",

plugin_insertdate_dateFormat : "%B %d, %Y",
plugin_insertdate_timeFormat : "%I:%M",
tabfocus_elements : "save_btn",

theme_advanced_buttons1 : "fullscreen,forecolor,backcolor,bold,italic,underline,strikethrough,link,unlink,bullist,numlist,indent,hr,charmap,spellchecker",
theme_advanced_buttons2 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "center",
theme_advanced_resizing : false
});


}); // End DOM ready
