function toggleLock() {
	if ($('lockimage').src.slice($('lockimage').src.length-12) == "unlocked.png") {
		$('lockimage').src = $('lockimage').src.slice(0, $('lockimage').src.length-12)+"locked.png";
	} else {
		$('lockimage').src = $('lockimage').src.slice(0, $('lockimage').src.length-10)+"unlocked.png";
	}
}

function lockDiscussion() {
	$('moderatoract').value = 'lock';
	$('moderation').submit();
}

function toggleSticky() {
	if ($('stickyimage').src.slice($('stickyimage').src.length-12) == "unsticky.png") {
		$('stickyimage').src = $('stickyimage').src.slice(0, $('stickyimage').src.length-12)+"sticky.png";
	} else {
		$('stickyimage').src = $('stickyimage').src.slice(0, $('stickyimage').src.length-10)+"unsticky.png";
	}
}

function stickyDiscussion() {
	$('moderatoract').value = 'sticky';
	$('moderation').submit();
}

function moderatorEnhance() {
	Element.show('modlinks');
	Element.hide('moderation');
	Event.observe($('lock'), 'mouseover', toggleLock, false);
	Event.observe($('lock'), 'mouseout', toggleLock, false);
	Event.observe($('lock'), 'click', lockDiscussion, false);
	
	Event.observe($('sticky'), 'mouseover', toggleSticky, false);
	Event.observe($('sticky'), 'mouseout', toggleSticky, false);
	Event.observe($('sticky'), 'click', stickyDiscussion, false);
}

function commentEnhance() {
	var e = document.getElementsByClassName('quotecomment');
	for (i=0;i<e.length;i++) {
		e[i].href='#addcomment';
		e[i].onclick=quoteComment;
	}
}

function quoteComment(event) {
	var element = Event.element(event);
	var childs = element.parentNode.parentNode.childNodes;
	for (i=0;i<childs.length;i++) {
		if (childs[i].className == "commentinfo") {
			for (j=0;j<childs[i].childNodes.length;j++) {
				if (childs[i].childNodes[j].tagName && childs[i].childNodes[j].tagName.toLowerCase() == "span") {
					var cite = childs[i].childNodes[j].childNodes[0].innerHTML;
				}
			}
		}
	}
	
	var comment = element.parentNode.parentNode.parentNode.parentNode.childNodes[3].innerHTML;
	
	tinyMCE.get('mce_editor_0').setContent(tinyMCE.get('mce_editor_0').getContent()+'<blockquote><p><strong><cite>'+cite+' said:</cite></strong></p>'+comment+'</blockquote><p> </p>');
}

Event.observe(window, 'load', moderatorEnhance, false);
Event.observe(window, 'load', commentEnhance, false);
