// Handle Flash Messages
var Flasher = {
	error: function(msg){
		$('flasherror').update(msg);
		new Effect.Appear('flasherror', {duration:0.3});
		setTimeout("Flasher.fade('error')", 7000);
	},
	notice: function(msg){
		$('flashnotice').update(msg);
		new Effect.Appear('flashnotice', {duration:0.3});
		setTimeout("Flasher.fade('notice')", 7000);
	},
	fade: function(type) {
	  new Effect.Fade('flash'+type, {duration: 0.3});
	}
};

// The "Rails Way" isnt always the "Right Way"
var confirm_destroy = function(event, element, options) {
	if (confirm("Are you sure?")) {
		var f = document.createElement('form');
		f.style.display = 'none';
		element.parentNode.appendChild(f);
		f.method = 'POST';
		f.action = options.action;
		var m = document.createElement('input');
		m.setAttribute('type', 'hidden');
		m.setAttribute('name', '_method');
		m.setAttribute('value', 'delete');
		f.appendChild(m);
		if(options.token_name && options.token_value){
			var s = document.createElement('input'); 
			s.setAttribute('type', 'hidden'); 
			s.setAttribute('name', options.token_name); 
			s.setAttribute('value', options.token_value); 
			f.appendChild(s);
		}
		f.submit();
	}
	Event.stop(event);
	return false;
};

// Bug the user to leave comments
// (Subtle but possibly annoying)
var ImNotTouchingYou = function(){new Effect.Pulsate('heyu', {duration: 2.0, pulses: 2, from: 0.2});};
document.observe('dom:loaded', function(){new PeriodicalExecuter(ImNotTouchingYou,5);});

// Toggles element's content
Element.addMethods({
	toggleContent: function(element, a, b){
		(element.innerHTML == a) ? element.update(b) : element.update(a);
	}
});

// Toggle Comment Body
var toggleComment = function(event, el){
	if(event) Event.stop(event);
	el.toggleContent('View', 'Hide');
	new Effect.toggle("comment-"+el.rel, 'blind', {duration: .2});
};