
function fixm( inp ) {
	return inp.replace( "#" , "@" ).replace( "," , "." );
}
function listm( inp, outp ) {
	$("<div><a href='" + "m4ilto:".replace( "4" , "a" ) + fixm( inp ) + "'>" + outp + "</a></div>");
}



/*
// Fancy effects
$(document).ready(function(){

	
	// add dummy boxes to nav
	$('.page_item').each(
		function (i) {
			$(this).append('<span>'+$(this).children('a').html()+'</span>');
		}
	)

	// start fancy fade menu
	fancyFades();

	// update fades on new section click
	$('.page_item a').click(function(){
		fancyFades($(this));
	});	
	
	

});

function fancyFades(scope) {
	
	// add and remove special classes
	$('.page_item').addClass('fader')
	$('.current_page_item').removeClass('fader')
	
	// hide all fader links to be shown on rollover
	$('.fader a').css("opacity","0");
	
	// show links on span rollover
	$('.fader a').hover(function(){
		$(this).fadeTo("slow", 1);
	});
	$('.fader a').mouseout(function(){
		$(this).fadeTo("slow", 0);
	});	
	
	$('.current_page_item a').unbind('hover');
	$('.current_page_item a').unbind('mouseout');
	
}*/




/*********************************
* Smart ajax thingy
*/
$(document).ready(function(){
						   
	// register navigation function for ALL links! 
	$('a').click(function(){
						  
		// stop poller
		goingForward = true;
		
		navigateTo($(this).attr("href"));
			
		return false;

	});

	// if first visit to danish
	if(document.location.href.indexOf('#') == -1) {
		location.replace('#');
	};
	
	// restore permalink
	if (document.location.href.split("#").length > 1 && document.location.href.split("#")[1] != "") {
		navigateTo(document.location.href);
	}
	
	// set up hash change poller
	prevHash = document.location.href;
	pollInterval = setInterval(poller, 300);


	// add asterisk to first items
	firstItems();
	
	
	// fade out notice msgs
	$('.fade').fadeTo(5000, 1).fadeOut('slow');
	
	
	// store original title
	orgTitle = $('title').html();
	
	
	// scroll to top on bottomnav
	scrollToTop();


	
});


function firstItems () {
	
	// uls
	$('.page_item:has(ul) ul').each(
		function (i) {
			$(this).prepend('<li class="first_page_item"><a href="'+$(this).parent().children('a').attr("href")+'">*</a></li>');
		}
	)
	
	$('.page_item:not(:has(ul))').each(
		function (i) {
			$(this).append('<ul><li class="first_page_item"><a href="'+$(this).children('a').attr("href")+'">*</a></li></ul>');
		}
	)
		// remove extra firstitems
		$('ul ul ul li.first_page_item').remove();


}

function scrollToTop () {
	// scroll to top on bottomnav
	$('.bottomnav a').click(function() {
		scroll(0,0);
	});
}

function navigateTo(destination) {

	document.location.href = destination;
	//location.replace($(this).attr("href"));
	
	var theUrl = document.location.toString().split("#")[1] + "?i=1";
	
	
	// start loading sequence
	/*$('#body').hide('slow', loadContent);
	
	function loadContent () {
		$('#body').load(theUrl, '', $('#body').show('slow'));
	}*/

	


	$('#loading').show();
	//$('#body').load(theUrl, '', function() { setTitle($('.title').html()); $('#loading').hide(); scrollToTop(); } );
	fadeSpeed = "fast";
	$('#inner').fadeOut(fadeSpeed).load(theUrl, '', function() { $('#inner').fadeIn(fadeSpeed); setTitle($('.title').html()); $('#loading').hide(); scrollToTop(); } );
	

	


	// update active menu item
	$(".page_item").removeClass('current_page_item');
	$(".page_item").removeClass('current_page_ancestor');
	
	// find the clicked URL
	theMenuUrl = "/#" + theUrl.split("?i=1")[0];
	
	// add active page item class to parent item
	if(document.location.href.split('/en/').length > 1) {	// english
		
		$(".page_item a:not(.first_page_item a)").filter(function(index) {
			return $(this).attr("href").split('/en')[1] == theMenuUrl;
		})
		.parent().addClass('current_page_item')

		// fixme! adds page ancestor class to divs, also!
		$(".current_page_item").parent().parent().addClass('current_page_ancestor');

	} else {												// others
		
		$(".page_item a:not(.first_page_item a)").filter(function(index) {
			return $(this).attr("href") == theMenuUrl;
		})
		.parent().addClass('current_page_item')
		
		// fixme! adds page ancestor class to divs, also!
		$(".current_page_item").parent().parent().addClass('current_page_ancestor');
		
	}
	


}

// fixme
function setTitle(theTitle) {
	if (theTitle) {
		separator = " | ";
	} else {
		separator = "";
		theTitle = "";
	}
	$('title').html(orgTitle + separator + theTitle);

}




// check if we're going back
function poller() {
	
	if (document.location.href != prevHash && !goingForward) {
		
		navigateTo(document.location.href);
		prevHash = document.location.href;
		sure = false;
		
	} else {
		
		prevHash = document.location.href;
		goingForward = false;
		
	}


}

