function flipTxt() {
	return $('infoToggle').innerHTML == 'Vis mere info' ? 'Vis mindre info' : 'Vis mere info';
}

function initPage() {
	// Profile -> "Mere info"
	if ($('infoWrapper') != undefined) {
		$('infoWrapper').hide();
		toggler = $('infoToggle');
		if (toggler) {
			toggler.show();
			toggler.onclick = function() {
				Effect.toggle(
					'infoWrapper',
					'blind',
					{onComplete: this.innerHTML = flipTxt() }
					);
				return false;
			}
		}
	}
	
	// Reveal terms on profile signup
	if($$('a.revealTerms')) {
		$$("a.revealTerms").each(function(w) {
			w.onclick = function () {
				new Effect.toggle('terms', 'blind');
				return false;
			};
		});
	}
	
	// Page template videomagic helper
	if($('pageView') && $$('.mainBackground')[0]) {
		$$('.mainBackground')[0].id = 'article';
	}
	
	// Badge toplists display toggle on/off
	// Function is fully working, but currently not in use
	// CAS 24/6 2009
/*	if($('topListContainer')) {
		lists = $$('#topListContainer ol');

		lists.invoke('toggle');

		$$('#topListContainer .badgeHeading').each(function(heading){
			heading.onclick = function() {
				this.next('ol').toggle();
			}
		});
	}*/
	
	// General-purpose toggling of badge_icon display
	if($$('.badge_icon')) {
		$$('.badge_icon').each(function(badge) {
			var icon = badge.down('img');
			
			if(!(badge.ancestors()[0].hasClassName('badgeHeading') || badge.hasClassName('profileIcon'))) {
				badge.onmouseover = function() {
					icon.siblings().each(function(elm) {
						elm.style.display = (badge.hasClassName('winner') ? 'block' : 'inline');
					});
				}
				badge.onmouseout = function() {
					icon.siblings().each(function(elm) {
						if (elm.nodeName != 'SUB') { elm.hide(); }
					});
				}
			}
		});
	}
	
	$$('a.hide').each(function(element) {
		element.onclick = function() {
			$(this.getAttribute('rel')).hide();
			
			return false;
		}
	});
	
	// Add fanship animation
	$$('.addProfileToFeed').each(function(element) {
		element.onclick = function () {
			var li = this.up('li');
			var li_coords = li.cumulativeOffset();
			var destination_coords = $('fanshipList').cumulativeOffset();
			var movePixels = [(destination_coords[0] - li_coords[0]), (destination_coords[1] - li_coords[1])]
			new Effect.Move(li, { x: movePixels[0], y: movePixels[1], mode: 'relative' });
			var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;f.submit();
			return false;
		}
	});
	
	// Profile publisher utility features
	$$('.help').each(function(element) {
		element.onclick = function() {
			$(this.getAttribute('rel')).show();
			this.removeClassName('iconLightbulbOn');
			this.addClassName('iconLightbulbOff');
			return false;
		}
	});
	
	$$('.contentSubmitForm').each(function(element) {
		element.onsubmit = function() {
			this.down('.loadMessage').appear({duration: 0.5});
			return true;
		}
	});
	
	$$('a.moduleLink').each(function(element) {
		element.onclick = function() {
			$$('.moduleTab').each(function(tab) { tab.hide();});
			$(this.getAttribute('rel')).show();
			return false;
		}
	});
}
document.observe('dom:loaded', initPage);